Overview Java
Overview Java
S.REVATHI AP/CSE
Entering the Program
A source file is officially called a compilation unit. It is a text file that
contains one or more class definitions.
The Java compiler requires that a source file use the .java filename
extension.
In Java, all code must reside inside a class.
Name of that class should match the name of the file that holds the
program.
Java is case-sensitive.
Make sure that the capitalization of the filename matches the class
name
Compiling the Program
To compile the Example program,
C:\>javac Example.java
The javac compiler creates a file called Example.class that contains
the bytecode version of the program.
To run the Example program
C:\>java Example
1st simple program
CODING DEMOS
Two Control Statements
1.if Statement:
The Java if statement works much like the IF statement in any other
language.
Syntactically identical to the if statements in C, C++, and C#.
if(condition) statement;
Here, condition is a Boolean expression. If condition is true, then the
statement is executed.If condition is false, then the statement is bypassed.
Example:
if(num < 100) System.out.println("num is less than 100");
2.for Loop
for(initialization; condition; iteration) statement;
Example:
if(x < y) {
// begin a block
x = y;
y = 0;
} // end of block
Lexical Issues
Java programs are a collection of:
whitespace
identifiers
literals
comments
operators
separators
keywords.
Whitespace
Java is a free-form language. This means we do not need to follow
any special indentation rules.
For instance, the Example program could have been written all on
one line or in any other strange way you felt like typing it,