This document provides an overview of basic Java programming concepts including:
- Java programs require a main method inside a class and use print statements for output.
- Java has primitive data types like int and double as well as objects. Variables are declared with a type.
- Control structures like if/else and for loops work similarly to other languages. Methods can call themselves recursively.
- Basic input is done through dialog boxes and output through print statements. Formatting is available.
- Arrays are objects that store multiple values of a single type and know their own length. Strings are immutable character arrays.
In Java 8, the java.util.function has numerous built-in interfaces. Other packages in the Java library (notably java.util.stream package) make use of the interfaces defined in this package. Java 8 developers should be familiar with using key interfaces provided in this package. This presentation provides an overview of four key functional interfaces (Consumer, Supplier, Function, and Predicate) provided in this package.
Start programming in a more functional style in Java. This is the second in a two part series on lambdas and streams in Java 8 presented at the JoziJug.
Esoft Metro Campus - Diploma in Information Technology - (Module VIII) Programming with Java
(Template - Virtusa Corporate)
Contents:
Introduction to Java
Features of Java
What you can create by Java?
Start Java Programming
Creating First Java Program
Java Virtual Machine
Basic Rules to Remember
Keywords in Java
Comments in Java Programs
Printing Statements
Primitive Data Types in Java
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
While Loop
Do While Loop
For Loop
Reading User Input
Arrays
Two Dimensional Arrays
Objects and Classes
Java Classes
Java Objects
Methods with Return Value
Methods without Return Value
Method Overloading
Variable Types
Inheritance
Method Overriding
Access Modifiers
Packages
GUI Applications in Java
Java Applets
ESOFT Metro Campus - Diploma in Software Engineering - (Module VI) Windows Based Application Development in Java
(Template - Virtusa Corporate)
Contents:
Introduction to Java
Features of Java
What you can create by Java?
Start Java Programming
Creating First Java Program
Java Virtual Machine
Basic Rules to Remember
Keywords in Java
Comments in Java Programs
Printing Statements
Primitive Data Types in Java
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
While Loop
Do While Loop
For Loop
Reading User Input
Arrays
Two Dimensional Arrays
Strings
Objects and Classes
Java Classes
Java Objects
Methods with Return Value
Methods without Return Value
Constructors
Method Overloading
Variable Types
Inheritance
Method Overriding
Abstract Classes
Interfaces
Polymorphism
Packages
Access Modifiers
Encapsulation
Exceptions
JDBC
GUI Applications with Swing
NetBeans IDE
Java is Object Oriented Programming. Java 8 is the latest version of the Java which is used by many companies for the development in many areas. Mobile, Web, Standalone applications.
In Java 8, the java.util.function has numerous built-in interfaces. Other packages in the Java library (notably java.util.stream package) make use of the interfaces defined in this package. Java 8 developers should be familiar with using key interfaces provided in this package. This presentation provides an overview of four key functional interfaces (Consumer, Supplier, Function, and Predicate) provided in this package.
Start programming in a more functional style in Java. This is the second in a two part series on lambdas and streams in Java 8 presented at the JoziJug.
Esoft Metro Campus - Diploma in Information Technology - (Module VIII) Programming with Java
(Template - Virtusa Corporate)
Contents:
Introduction to Java
Features of Java
What you can create by Java?
Start Java Programming
Creating First Java Program
Java Virtual Machine
Basic Rules to Remember
Keywords in Java
Comments in Java Programs
Printing Statements
Primitive Data Types in Java
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
While Loop
Do While Loop
For Loop
Reading User Input
Arrays
Two Dimensional Arrays
Objects and Classes
Java Classes
Java Objects
Methods with Return Value
Methods without Return Value
Method Overloading
Variable Types
Inheritance
Method Overriding
Access Modifiers
Packages
GUI Applications in Java
Java Applets
ESOFT Metro Campus - Diploma in Software Engineering - (Module VI) Windows Based Application Development in Java
(Template - Virtusa Corporate)
Contents:
Introduction to Java
Features of Java
What you can create by Java?
Start Java Programming
Creating First Java Program
Java Virtual Machine
Basic Rules to Remember
Keywords in Java
Comments in Java Programs
Printing Statements
Primitive Data Types in Java
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
While Loop
Do While Loop
For Loop
Reading User Input
Arrays
Two Dimensional Arrays
Strings
Objects and Classes
Java Classes
Java Objects
Methods with Return Value
Methods without Return Value
Constructors
Method Overloading
Variable Types
Inheritance
Method Overriding
Abstract Classes
Interfaces
Polymorphism
Packages
Access Modifiers
Encapsulation
Exceptions
JDBC
GUI Applications with Swing
NetBeans IDE
Java is Object Oriented Programming. Java 8 is the latest version of the Java which is used by many companies for the development in many areas. Mobile, Web, Standalone applications.
The emergence of support of functions and lambda expressions as first-class citizens in Java 8 gives us a tremendous opportunity to adapt the concepts of functional programming to the Java language.
Qcon2011 functions rockpresentation_scalaMichael Stal
This is the part I of the tutorial I planned to give at QCon 2011 on Functional Programming with Scala. It also includes Scala 2.8 as well as upcoming features
Historically concept of Actors has been derived from Erlang and is being used as a Threading model in Scala and AKka.
We can think Actors like two persons who do not talk to each other but communicate via a mailbox
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
Esoft Metro Campus - Certificate in java basics
(Template - Virtusa Corporate)
Contents:
Structure of a program
Variables & Data types
Constants
Operators
Basic Input/output
Control Structures
Functions
Arrays
Character Sequences
Pointers and Dynamic Memory
Unions
Other Data Types
Input/output with files
Searching
Sorting
Introduction to data structures
ESOFT Metro Campus - Diploma in Software Engineering - (Module V) Windows Based Application Development in C#
(Template - Virtusa Corporate)
Contents:
Introduction to .NET Framework
.NET Framework Platform Architecture
Microsoft Visual Studio
C# Language
C#, VS and .NET Framework Versions
Your First C# Application
Printing Statements
Comments in C#
Common Type System
Value Types and Reference Type
Variables Declaration in C#
Type Conversion
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
Switch Statement
While Loop
Do While Loop
For Loop
Arrays
Accessing Arrays using foreach Loop
Two Dimensional Arrays
Classes and Objects in C#
Inheritance in C#
Partial Classes
Namespaces
Windows Forms Applications
Using Buttons, Labels and Text Boxes
Displaying Message Boxes
Error Handling with Try… Catch… finally…
Using Radio Buttons
Using Check Boxes
Using List Boxes
Creating Menus
Creating ToolStrips
MDI Forms
Database Application in C#
Creating a Simple Database Application
SQL Insert / Update / Retrieving / Delete
SQL Command Execute Methods
Data Sets
Esoft Metro Campus - Diploma in Web Engineering - (Module VII) Advanced PHP Concepts
(Template - Virtusa Corporate)
Contents:
Arrays
Indexed Arrays
Associative Arrays
Multidimensional arrays
Array Functions
PHP Objects and Classes
Creating an Object
Properties of Objects
Object Methods
Constructors
Inheritance
Method overriding
PHP Strings
printf() Function
String Functions
PHP Date/Time Functions
time() Function
getdate() Function
date() Function
mktime() function
checkdate() function
PHP Form Handling
Collecting form data with PHP
GET vs POST
Data validation against malicious code
Required fields validation
Validating an E-mail address
PHP mail() Function
Using header() function to redirect user
File Upload
Processing the uploaded file
Check if File Already Exists
Limit File Size
Limit File Type
Check if image file is an actual image
Uploading File
Cookies
Sessions
Esoft Metro Campus - Diploma in Information Technology - (Module IX) Programming with C#.NET
(Template - Virtusa Corporate)
Contents:
Introduction to .NET Framework
.NET Framework Platform Architecture
Microsoft Visual Studio
C# Language
C#, VS and .NET Framework Versions
Your First C# Application
Printing Statements
Comments in C#
Common Type System
Value Types and Reference Type
Variables Declaration in C#
Type Conversion
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
Switch Statement
While Loop
Do While Loop
For Loop
Arrays
Accessing Arrays using foreach Loop
Two Dimensional Arrays
Classes and Objects in C#
Inheritance in C#
Partial Classes
Namespaces
Windows Forms Applications
Using Buttons, Labels and Text Boxes
Displaying Message Boxes
Error Handling with Try… Catch… finally…
Using Radio Buttons
Using Check Boxes
Using List Boxes
Creating Menus
Creating ToolStrips
MDI Forms
Database Application in C#
Creating a Simple Database Application
SQL Insert / Update / Retrieving / Delete
SQL Command Execute Methods
Data Sets
Esoft Metro Campus - Diploma in Web Engineering - (Module VI) Fundamentals of PHP
(Template - Virtusa Corporate)
Contents:
Introduction to PHP
What PHP Can Do?
PHP Environment Setup
What a PHP File is?
PHP Syntax
Comments in PHP
echo and print Statements
PHP Variables
PHP Data Types
Changing Type by settype()
Changing Type by Casting
PHP Constants
Arithmetic Operators
String Operators
Assignment Operators
Comparison Operators
Logical Operators
Operators Precedence
If Statement
If… Else Statement
If… Else if… Else Statement
Switch Statement
The ? Operator
While Loop
Do While Loop
For Loop
break Statement
continue Statement
Functions
User Defined Functions
Functions - Returning values
Default Argument Value
Arguments as Reference
Existence of Functions
Variable Local and Global Scope
The global Keyword
GLOBALS Array
Superglobals
Static Variables
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
In this chapter we will get acquainted with the operators in Java and the actions they can perform on the different data types. We will explain the priorities of the operators and we will analyze the different types of operators, according to the count of the arguments they can take and the actions they can perform. In the second part we will examine the conversion of data types.
The emergence of support of functions and lambda expressions as first-class citizens in Java 8 gives us a tremendous opportunity to adapt the concepts of functional programming to the Java language.
Qcon2011 functions rockpresentation_scalaMichael Stal
This is the part I of the tutorial I planned to give at QCon 2011 on Functional Programming with Scala. It also includes Scala 2.8 as well as upcoming features
Historically concept of Actors has been derived from Erlang and is being used as a Threading model in Scala and AKka.
We can think Actors like two persons who do not talk to each other but communicate via a mailbox
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
Esoft Metro Campus - Certificate in java basics
(Template - Virtusa Corporate)
Contents:
Structure of a program
Variables & Data types
Constants
Operators
Basic Input/output
Control Structures
Functions
Arrays
Character Sequences
Pointers and Dynamic Memory
Unions
Other Data Types
Input/output with files
Searching
Sorting
Introduction to data structures
ESOFT Metro Campus - Diploma in Software Engineering - (Module V) Windows Based Application Development in C#
(Template - Virtusa Corporate)
Contents:
Introduction to .NET Framework
.NET Framework Platform Architecture
Microsoft Visual Studio
C# Language
C#, VS and .NET Framework Versions
Your First C# Application
Printing Statements
Comments in C#
Common Type System
Value Types and Reference Type
Variables Declaration in C#
Type Conversion
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
Switch Statement
While Loop
Do While Loop
For Loop
Arrays
Accessing Arrays using foreach Loop
Two Dimensional Arrays
Classes and Objects in C#
Inheritance in C#
Partial Classes
Namespaces
Windows Forms Applications
Using Buttons, Labels and Text Boxes
Displaying Message Boxes
Error Handling with Try… Catch… finally…
Using Radio Buttons
Using Check Boxes
Using List Boxes
Creating Menus
Creating ToolStrips
MDI Forms
Database Application in C#
Creating a Simple Database Application
SQL Insert / Update / Retrieving / Delete
SQL Command Execute Methods
Data Sets
Esoft Metro Campus - Diploma in Web Engineering - (Module VII) Advanced PHP Concepts
(Template - Virtusa Corporate)
Contents:
Arrays
Indexed Arrays
Associative Arrays
Multidimensional arrays
Array Functions
PHP Objects and Classes
Creating an Object
Properties of Objects
Object Methods
Constructors
Inheritance
Method overriding
PHP Strings
printf() Function
String Functions
PHP Date/Time Functions
time() Function
getdate() Function
date() Function
mktime() function
checkdate() function
PHP Form Handling
Collecting form data with PHP
GET vs POST
Data validation against malicious code
Required fields validation
Validating an E-mail address
PHP mail() Function
Using header() function to redirect user
File Upload
Processing the uploaded file
Check if File Already Exists
Limit File Size
Limit File Type
Check if image file is an actual image
Uploading File
Cookies
Sessions
Esoft Metro Campus - Diploma in Information Technology - (Module IX) Programming with C#.NET
(Template - Virtusa Corporate)
Contents:
Introduction to .NET Framework
.NET Framework Platform Architecture
Microsoft Visual Studio
C# Language
C#, VS and .NET Framework Versions
Your First C# Application
Printing Statements
Comments in C#
Common Type System
Value Types and Reference Type
Variables Declaration in C#
Type Conversion
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Nested If Statement
Switch Statement
While Loop
Do While Loop
For Loop
Arrays
Accessing Arrays using foreach Loop
Two Dimensional Arrays
Classes and Objects in C#
Inheritance in C#
Partial Classes
Namespaces
Windows Forms Applications
Using Buttons, Labels and Text Boxes
Displaying Message Boxes
Error Handling with Try… Catch… finally…
Using Radio Buttons
Using Check Boxes
Using List Boxes
Creating Menus
Creating ToolStrips
MDI Forms
Database Application in C#
Creating a Simple Database Application
SQL Insert / Update / Retrieving / Delete
SQL Command Execute Methods
Data Sets
Esoft Metro Campus - Diploma in Web Engineering - (Module VI) Fundamentals of PHP
(Template - Virtusa Corporate)
Contents:
Introduction to PHP
What PHP Can Do?
PHP Environment Setup
What a PHP File is?
PHP Syntax
Comments in PHP
echo and print Statements
PHP Variables
PHP Data Types
Changing Type by settype()
Changing Type by Casting
PHP Constants
Arithmetic Operators
String Operators
Assignment Operators
Comparison Operators
Logical Operators
Operators Precedence
If Statement
If… Else Statement
If… Else if… Else Statement
Switch Statement
The ? Operator
While Loop
Do While Loop
For Loop
break Statement
continue Statement
Functions
User Defined Functions
Functions - Returning values
Default Argument Value
Arguments as Reference
Existence of Functions
Variable Local and Global Scope
The global Keyword
GLOBALS Array
Superglobals
Static Variables
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
In this chapter we will get acquainted with the operators in Java and the actions they can perform on the different data types. We will explain the priorities of the operators and we will analyze the different types of operators, according to the count of the arguments they can take and the actions they can perform. In the second part we will examine the conversion of data types.
Core Java Online training is Offering at Glory IT Technologies Pvt. Ltd. which is an object oriented programming language is classified into three basic level of programming viz. core java programming, specialized java programming & advanced Java programming. Among these first basic level is called basic or core Java programming language & is the first step of mastering Java language.
Final year M.E IEEE PROJECTS TITLES 2014-2015 Final year IEEE PROJECTS TITLES 2014-2015 Final year M.TECH IEEE PROJECTS TITLES 2014-2015 Final year B.E IEEE
Based on chapter 2 of the textbook "Building Java Programs", 3rd edition. Covers primitive data types, variables, operators, ASCII values for chars, operator precedence, String concatenation, casting, for loops, nested for loops, and class constants.
See a video presentation of this slideshow on my YouTube channel JavaGoddess, at https://www.youtube.com/watch?v=N7SBkMY65gc&t=4s
Esoft Metro Campus - Diploma in Web Engineering - (Module IX) Using Extensions and Image Manipulation
(Template - Virtusa Corporate)
Contents:
Image Manipulation with PHP
GD Library
ImageCreate()
ImageColorAllocate()
Drawing shapes and lines
imageellipse()
imagearc()
imagepolygon()
imagerectangle()
imageline()
Creating a new image
Using a Color Fill
imagefilledellipse()
imagefilledarc()
imagefilledpolygon()
imagefilledrectangle()
Basic Pie Chart
3D Pie Chart
Modifying Existing Images
imagecreatefrompng()
imagecolortransparent()
imagecopymerge()
Creating a new image…
Stacking images…
Imagestring()
Draw a string
Final year M.E, IEEE PROJECTS, TITLES, 2014-2015 Final year IEEE PROJECTS, TITLES 2014-2015, Final year M.TECH IEEE PROJECTS TITLES, 2014-2015 Final, year B.E, ieee project,
Esoft Metro Campus - Diploma in Web Engineering - (Module II) Multimedia Technologies
(Template - Virtusa Corporate)
Contents:
What are Graphics ?
Digital Image Concepts
Pixel
Resolution of Images
Resolution of Devices
Color Depth
Color Palette
Dithering
Bitmap and Vector Graphics
Bitmap Graphics
Vector Graphics
Comparison
Graphics File Formats
Bit Map
Tagged Image File Format
Graphical Interchange Format
Join Picture Expert Group
Portable Network Graphics
Multi-image Network Graphics
Multimedia on Web
Animations
Rollovers
Animated GIF
Flash Files
Audio
Audio on Web Sites
Audio File Formats
MIDI
WAVE
MP3
AU
AIFF
Video
Video File Formats
AVI
ASF
MPEG
QuickTime
RealVideo
Copyrights of Web Content
On March 2014, Java 8 was released. These informal slides describe the new elements of the programming languages, focusing on those taken from the functional paradigm.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
2. Objective and Outline
• Objective
– Show basic programming concepts
• Outline
– What do java programs look like?
– Basic ingredients
• Java primitive types
• Variables and constants
• Operators and control flow
– Simple commonly used built-ins.
• Simple input/output
• Arrays and Strings
3. What do java program look like?
public class MyProgram {
public static void main(String
args[])
{
System.out.println(“Hello world!”);
}
} //File: MyProgram.javapublic: Access modifier
class: everything is inside a class
MyProgram: class name.
matches file name.
Case sensitive
main: method of the wrapping
class
Compilation and run:
javac MyProgram.java
=> MyProgram.class
java MyProgram
4. Objective and Outline
• Outline
– What do java programs look like?
– Basic ingredients
• Java primitive types
• Variables and constants
• Operators and control flow
– Simple commonly used built-ins.
• Simple input/output
• Arrays and Strings
5. Basic Ingredients/Primitive Types
• Integers
– byte (1 byte, -128 to 127)
– short (2 bytes)
– int (4 bytes)
– long (8 bytes)
• Floating-point types
– float (4 bytes, 6-7 significant decimal digits)
– double (8 bytes, 15 significant decimal digits)
• char (2 byte, Unicode) (ASCII 1 byte)
• boolean (true or false)
• Those are all the primitive types in Java. Everything else is an object.
For really large numbers use
BigInteger and BigDecimal
classes
6. Basic Ingredients/Primitive Types
• Legal conversions between numeric types
– Arrows indicate direction of legal and automatic conversion
• double x = 123;
• long x = 123456789; float y = x;
– Solid arrow: no loss of precision
– Dotted arrow: might lose precision
• z=1.234567E8
bytes short
double
int long
float
char
7. Basic Ingredients/Primitive Types
• Conversion in the opposite direction required explicit cast.
– double x = 9.997;
– int num = (int) x;
– int num = x; // does not compile
Can easily lead to the loss of precision (round-up errors)
• Cannot convert between boolean and numerical values.
bytes short
double
int long
float
char
8. Objective and Outline
• Outline
– What do java programs look like?
– Basic ingredients
• Java primitive types
• Variables and constants
• Operators and control flow
– Simple commonly used built-ins.
• Simple input/output
• Arrays and Strings
9. Basic Ingredients/Variables and Constants
• Variables can be declared anywhere
for (int i = 0; i < 20; i++) {
System.out.println(“Hi”);
char ch = ‘A’;
}
double pi = 3.14159;
• Java compilers require initialization of local variables before use
public void someMethod()
{ …
int x; // does not compile
}
• Instance variables of class automatically initialized.
10. Basic Ingredients/Variables and Constants
final marks a variable “read-only”
Variable is assigned once and cannot be changed
public void someMethod()
{ final double pi = 3.14159;
.. .. ..
pi = 3.14; // illegal
}
Use static final to define constants which are available to multiple
methods inside a single class
public class Time {
static final int MinHour = 0;
static final int MaxHour = 23;
private int hour, minute;
// these properties are set to 0
// unless overwritten by constructor
… }
11. Objective and Outline
• Outline
– What do java programs look like?
– Basic ingredients
• Java primitive types
• Variables and constants
• Operators and control flow
– Simple commonly used built-ins.
• Simple input/output
• Arrays and Strings
12. Basic Ingredients/Operators
• Basically the same as C++:
+, -, *, /, %, ++, --,
<, <=, >, >=, ==, !=,
!, &&, ||
=, +=, -=, *=, /=, %=,
• User cannot “overload” operators; although + is overloaded to do string
concatenation
– In C++:
• Int x=0; x += 1;
• String& String::operator+=( const String &s)..
• Note that methods can be overloaded
13. Basic Ingredients /Operators
No Pointers!
No explicit pointer types (although objects are implemented as
references)
No & or * operators
In C++:
int *i = (int *) malloc( 3 * sizeof(int));
(i+1)* = 2;
int& y = &i;
No pointer arithmetic
No function pointers
14. Basic Ingredients/Control flow
Basically the same as C++:
if (boolean-expr)
statement; (has optional else)
if ( x = 0 ) //leads to compiling error
for (expr; boolean-expr; expr)
statement;
while (boolean-expr)
statement; (do-while variant also)
switch (integer-expr)
case constant: statement; break;
15. Basic Ingredients/Control flow
Labeled break;
Int n;
read_data:
while (…)
{ … for (…)
{
String input = JOptionPane.showInputDialog
(“Enter a number >=0”);
N = Integer.parseInt(input);
if ( n < 0 )
break read_data;
}
}
// moves to here when n<0.
• No explicit goto (no union, no struct);
Colon
16. Basic Ingredients/Control flow
Recursion
Basically the same as C++:
public class Factorial
{
public static int factorial( int n ) {
if ( n <=1 ) return 1;
return factorial( n-1 ) * n;
}
public static void main(String args[])
{
System.out.println( factorial ( 4 ) );
}
}//Factorial.java
17. Objective and Outline
• Outline
– What do java programs look like?
– Basic ingredients
• Java primitive types
• Variables and constants
• Operators and control flow
– Simple commonly used built-ins.
• Simple input/output
• Arrays and Strings
18. Simple Input/Output
• Contents
– Writing to standard output
– Reading keyboard input via dialog box
– Formatting output
• We discuss I/O in more detail later.
19. Simple Input/Output
• It is easy to print output to the “standard output
device (the console window) by using the
predefined Stream objects out
System.out.print(“Your name is “ + name + “
and you are “ + num + “ years old.”);
20. Simple Input/Output
• It is a bit more complex to read input from the “standard input device” using
Stream.
• However it is easy to supply a dialog box for keyboard input:
JOptionPane.showInputDialog(promptString)
The return value is the string that the user typed
• Example: InputTest.java
21. Simple Input/Output
• Need to include this statement:
import javax.swing.*;
//JOptionPane class is defined in that package
• For example: you can query name of the user by:
String name= JOptionPane.showInputDialog(“Your
name:”);
• To read in a number, use the Integer.parseInt or
Double.parseDouble method to convert the string to its numeric
value. For example,
String input= JOptionPane.showInputDialog(“Your
age:”);
int age = Integer.parseInt(input);
• End the program with the method call: System.exit(0);
22. Simple Input/Output
• Use string formatters provided in java.text.NumberFormat to format
output:
NumberFormat.getNumberInstance() // for numbers
NumberFormat.getCurrencyInstance()// for currency values
NumberFormat.getPercentInstance()// for percentage values
• For Example:
double x = 10000.0 / 3.0;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(4);
nf.setMinimumIntegerDigits(6);
System.out.println(nf.format(x)); //003,333.3333
23. Objective and Outline
• Outline
– What do java programs look like?
– Basic ingredients
• Java primitive types
• Variables and constants
• Operators and control flow
– Simple commonly used built-ins.
• Simple input/output
• Arrays and Strings
25. Arrays
• Arrays are objects of class java.lang.reflect.Array
• Can’t specify size when declaring array
int arr[3]; // not legal in Java!
int arr[]; // okay
int[] arr; // okay (same as previous line)
• Arrays (as all objects) are dynamically allocated
int[] arr = new int[3];
• Before allocation, array variable is null
• All elements are zeroed when array allocated
• Destroyed automatically by garbage collector. No delete operator
• Shorthand to declare, allocate, and initialize
int[] arr = { 5, 10, 15, 20};
26. Arrays
• Java array (object) always knows its own length
int[] arr = {5, 20, 15, 10};
System.out.println(“Length is ” + arr.length);
• Elements indexed from 0 to length-1, like C++
• Raises exception for “ArrayIndexOutOfBounds”
• Length is fixed when allocated; create new array and
copy over to change length
27. Arrays
• Used in similar way as ordinary arrays
int sum(int[] arr)
{
int i, sum = 0;
for (i=0; i < arr.length; i++)
sum += arr[i];
return sum;
}
28. Arrays are references
• Arrays are objects, hence, are implemented as references
(reference is a pointer in disguise)
int[] arr = {5, 20, 15, 10};
int[] b = arr;
b[0] = 3; // arr[0] also becomes 3!
• Array copying (java.lang.System)
System.arraycopy(from, fromIndex, to, toindex, count);
int[] c;
System.arraycopy(arr, 0, c, 0, 4);
• Array sorting (java.util.Arrays)
Arrays.sort(arr) //use a tuned QuickSort
29. Array Examples
public class ArrayRef {
public static void main( String[] args ) {
int [] a = {0, 1, 2, 3, 4};
int [] b = {10, 11, 12, 13, 14};
a = b;
b = new int[] { 20, 21, 22, 23, 24 };
for (int i=0; i<a.length && i<b.length; i++)
{ System.out.println( a[i]+ ” ”+ b[i] ); }
}
}
// ArrayRef.java
//what is the output ?
Notice this quote
30. public class Swapping
{ public static void main(String argv[])
{ int[] a = {1,2,3};
for (int i=0; i<3; i++)
System.out.print(a[i]+" ");
System.out.print(“n”);
swap(a,0,2);
for (int i=0; i<3; i++)
System.out.print(a[i]+" ");
System.out.print(“n”);
}
public static void swap(int[] a, int i, int j)
{ int temp = a[j];
a[j]=a[i];
a[i]=temp;
}
} //Swapping.java
31. Multidimensional Arrays
int[][] matrix = new int[5][10];
int[] firstRow = matrix[0]; //ref to
1st row
int[] secondRow = matrix[1]; //ref to
2nd row
int firstElem = matrix[0][0];
firstElem = firstRow[0];
32. Strings
• Contents
– Strings are objects, immutable, differ from arrays
– Basic methods on Strings
– Convert String representation of numbers into
numbers
– StringBuffer, mutable version of Strings
33. String
• Java.lang.String
• Java.lang.StringBuffer
• String is an object
• Creating a String
– form string literal between double quotes
String s = “Hello, World!”;
– by using the new keyword
String s = new String(“Java”);
35. Strings
• String is a class (java.lang.String)offering methods for almost
anything
String s = “a string literal”;
• + is concatenation, when you concatenate a string with a value that
is not a string, the latter is converted to a string
s = “The year is ” + 2002 + “!”;
• Everything can be converted to a string representation including
primitive types and objects (topic 3, class object)
36. Strings
• A String is not an array. It is immutable. You cannot change a String
– but you can change the contents of a String variable and make it refer to a
different String.
String s = “Hello”;
s[2]=‘a’; // Illegal
s = “Bye”; //Legal
• Equality test:
s.equals(t) // determines whether s and t are same
s == t// determines whether s and t stored at same location
37. String Example
public class StringExample
{ public static void main(String argv[])
{
String h = “hello”;
String w = “world”;
System.out.println(h + “ “ +w);
w = h.substring(1,3);
w += "binky";
for (int i = 0; i < w.length(); i++)
System.out.println(w.charAt(i));
int pos = w.indexOf("in");
System.out.println("Starting position of "in
" in string " " + w + " " is " + pos);
38. String Example
if ( h=="hello" )
System.out.println(
"String h == "hello" ");
if ( "hello".equals(h) )
System.out.println(""hello"
== string h ");
} }
} //StringExample.java
39. Example - String
• To print a string in reverse order
class ReverseString {
public static void reverseIt(String source) {
int i, len = source.length();
for (i = (len - 1); i >= 0; i--) {
System.out.print(source.charAt(i));
}
}
}
40. Convert String to number
• String class itself does not provide such a
conversion
• Type wrapper classes (Integer, Double,
Float and Long) provide a method valueOf
to do the job
String piStr = “3.14159”;
Float pi = Float.valueOf(piStr);
41. StringBuffer
• The String class is used for constant strings
• While StringBuffer is for strings that can
change
• StringBuffer contains a method
tostring() which returns the string value
being held
• Since String is immutable, it is “cheaper”!
42. StringBuffer
class ReverseString {
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--) {
dest.append(source.charAt(i));
}
return dest.toString();
}
}