Professional Documents
Culture Documents
Java Program
Java Coding Guidelines
Java Comments
Java Identifiers
Java Keywords
Java Literals
Java Data Types
Java Variables
Java Constant
*Property of STI
J0007
1 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java Program
*Property of STI
System.out.println(Hello,
World!);
J0007
2 __________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java program files must
Have same name as public class
End with extension .java
Java Program
{
public static void main (String[] args) {
<program statement>
}
Java Coding
Guidelines
}
Indent for readability
*Property of STI
J0007
3 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
4 __________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java
Statements
Java Blocks
Example:
System.out.print(Hello, World!);
*Property of STI
J0007
5 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Example:
*Property of STI
J0007
6 __________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Comment lines are ignored by the
compiler.
Java
Comments
// This is a comment
/* This is a comment */
Example:
Comments
System.out.println(Hello, World!);
}
}
*Property of STI
J0007
7 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
8 __________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Rules:
Identifiers can use alphabetic characters of either case (az and
AZ), numbers (09), underscores ( _ ), and dollar signs ( $ ).
Java
Identifiers
Java
Identifier
Rules
and
Guidelines
*Property of STI
J0007
9 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java
Identifier:
Example
*Property of STI
*Property of STI
J0007
10 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java
Keywords
J0007
11 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
12 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java Literals
\n
\t
\r
\
\
\\
*Property of STI
Octal (base 8)
Decimal (base 10)
Hexadecimal (base 16)
Integers
Floating Point Numbers
Booleans (true or false)
Strings (enclosed in )
Characters (enclosed in )
new line
tab
carriage return
double quote
single quote
backslash
J0007
13 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
0xDadaCafe
1996
0372 0x00FF00FF
*Property of STI
J0007
14 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Floating-Point
Literal
Boolean
Literal
*Property of STI
J0007
15 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
16 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
String Literal
Character
Literal
"Hello, world
"One\tTwo"
"TE\u0041
*Property of STI
J0007
17 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
18 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Simple
Data Types
Primitive Data
Types
Composite
created by the programmer using simple
types, arrays, classes, and interfaces
*Property of STI
J0007
19 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
J0007
*Property of STI
J0007
20 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Boolean
Data Type Example:
\t
\u????
- a tab
- a specific Unicode character, ????
is replaced with exactly four
hexadecimal digits (for example,
\u03A5 is the Greek letter phi, )
*Property of STI
J0007
21 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
22 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
has types: float (32 bits single precision)
and double (64-bit double precision)
Integer Data
Type
*Property of STI
Floating Point
Data Type
J0007
23 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
24 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java Variables
*Property of STI
J0007
*Property of STI
25 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Identifier
Declaring
and
Initializing
Variables
*Property of STI
Declaring
and
Initializing
Variables
Semicolon
Optional: assigned value
J0007
27 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
J0007
26 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
28 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Java Variable:
Example
char option;
option = C;
double grade = 0.0;
System.out.print()
System.out.println()
Example:
Displaying
Variable
Data
}
System.out.println(value);
*Property of STI
J0007
29 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
30 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
System.out.print()
Does not append newline at the end of the data output
Example:
System.out.print(Hello);
System.out.print(World);
Primitive Variables
Output:
HelloWorld
Displaying
Variable Data
System.out.println()
Appends a newline at the end of the data output
Example:
Types of
Variables
Reference Variables
variables that stores the address in the memory location
points to another memory location where the actual data is
System.out.println(Hello);
System.out.println(World);
Output:
Hello
World
*Property of STI
J0007
31 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
*Property of STI
J0007
32 _________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
Constants
*Property of STI
J0007
33 ________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________
___________________________