Professional Documents
Culture Documents
Java Fundamentals First Part
Java Fundamentals First Part
FUNDAMENTALS
T A B L E OF CONT E NT S F OR T H IS
P RE S E NT A T ION
1 PARTS OF A JAVA PROGRAM
5 IDENTIFIERS
8 ARITHMETIC OPERATORS
16 COMMENTS
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
“//” marks the beginning of a comment
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
Insert blank lines in programs to make them easier to read
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
Class header marks the beginning of a class definition.
A class serves as a container for an application.
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
Known as an access specifier. The
public specifier means access to the
Is a java key word. It must be class is unrestricted (“Open to the
written in lowercase letters. public”).
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
Is a java key word. It must be Indicates the beginning of a class
written in lowercase letters. definition
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
The name of the class made up
by the programmer.
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
In short: This line tells the compiler that a publicly
accessible class named “Parts” is being defined.
P rog ra m output
I love programming!
PARTS OF A JAVA PROGRAM
Left brace or opening brace associated with the
beginning of the class definition.
out
Object out
Methods
print println(“
println “);
. .
THE PRINT METHOD
5 public static void main(String[] args)
6 {
7 System.out.print(“I love programming!”);
8 }
An important thing to know about the print method
is that it does not advance the cursor to the
beginning of the next line after displaying the
message:
I love programming!
THE PRINT METHOD
5 public static void main(String[] args)
6 {
7 System.out.print(“I love programming!”);
8 }
An important thing to know about the print method
is that it does not advance the cursor to the
beginning of the next line after displaying the
message:
I love programming!|
THE PRINTLN METHOD
5 public static void main(String[] args)
6 {
7 System.out.println(“I love programming!”);
8 }
I love programming!
THE PRINTLN METHOD
5 public static void main(String[] args)
6 {
7 System.out.println(“I love programming!”);
8 }
I love programming!
|
THE PRINT AND PRINTLN
METHODS
public static void main(String[] args)
{
The value is 10
VARIABLES AND LITERALS
1 We//call
A program that
this line of usesa variable
code variablesdeclaration. A
2 variable must first be declared before it can be used.
3 A variable
public class Variables
declaration tells the compiler the variable’s
4 name{ and type of data it will hold.
5 public static void main(String[] args)
6 {
7 int value;
8
9 value = 10;
10 System.out.print(“The value is “);
11 System.out.println(value);
12
13 }
14 }
The value is 10
VARIABLES AND LITERALS
1 // A program that uses variables
2
3 public class Variables The word int
4 { stands for
5 public static void main(String[] args) integer which
6 { is the data
7 int value; type of the
8 declaration.
9 value = 10;
10 System.out.print(“The value is “);
11 System.out.println(value);
12
13 }
14 }
The value is 10
VARIABLES AND LITERALS
1 // A program that uses variables
2 The word
3 public class Variables value is a
4 { word the
5 public static void main(String[] args) programmer
6 { chooses to
7 int value; hold integer
8 numbers.
9 value = 10;
10 System.out.print(“The value is “);
11 System.out.println(value);
12
13 }
14 }
The value is 10
VARIABLES AND LITERALS
1This is
// A
called
program
an assignment
that uses statement.
variables The equal
2 is an operator that stores the value on its right
sign
3 into
(10) public
theclass
variable
Variables
on its left (value).
4 {
5 public static void main(String[] args)
6 {
7 int value;
8
9 value = 10;
10 System.out.print(“The value is “);
11 System.out.println(value);
12
13 }
14 }
The value is 10
VARIABLES AND LITERALS
1The first
// A line
program
here that
sendsuses
the variables
string literal “The value
2 “ to the print method. The second line sends the
is
3 public
name valueVariables
of theclass variable to the println method.
4 {
5 public static void main(String[] args)
6 {
7 int value;
8
9 value = 10;
10 System.out.print(“The value is “);
11 System.out.println(value);
12
13 }
14 }
The value is 10
VARIABLES AND LITERALS
1When // A program
you that usestovariables
send a variable the print or prinln
2methods, the value of that variable will be displayed.
3Important:
public class
thereVariables
are no quotation marks around the
4variable
{ value!
5 public static void main(String[] args)
6 {
7 int value;
8
9 value = 10;
10 System.out.print(“The value is “);
11 System.out.println(value);
12
13 }
14 }
The value is 10
DISPLAYING MULTIPLE ITEMS
WITH THE + OPERATOR
When the + operator is used with strings ,we call it a string
concatenation operator. To concatenate means to append.
The string concatenation operator appends one string to
another.
System.out.println(“Today is “ + “a good
day!”);
The + operator produces a string that is a combination of
the 2 strings both sides of the operator.
P rinted on the com puter screen when a pplica tion runs:
int y;
This gives us no clue as to what the purpose of the variable is.
int numberOfCows; int numberofcows;