Core Java

Java Evolution
Java History
Java Features
Benefits of Java over C and C++
How Java works
The Java Programming Language
The Java Platform
Java Development Kit
HARDWARE AND SOFTWARE REQUIREMENTS
Disadvantages of Java
Overview of Java Language
Developing the Java Application
Comments in Java Code
Defining a Class
The main Method
Using Classes and Objects
Java Program Structure
Java Tokens
Constant, Variable and Datatype
Variables
Declaring Variables
Rules on Variable Names
Variable Types
Primitive Data Types
Constants
Operator and Expression
Expressions and Operators
Operator Precedence
Integer Operators
Relational Integer Operators
Floating point Operators
Relational Floating-Point Operators
String Operator
Assignment Operators
Arithmetic assignment operations
Conversions
Casts
Boolean expressions and operations
Logical operators
Bitwise operations
The complement operator
Decision making, Branching and Looping
Flow control with if and else
The if statement
The else statement
Switch statements
for, while, and do-while statements
The for statement
The while statement
The do-while statement
Using break and continue
The break statement
The continue statement
Class Object and Method
Introduction to Classes
The Benefit of Classes
Defining Classes
Class using constructor
Object
Declaring an Object
Instantiating an Object
Initializing an Object
Referencing an Object's Variables
Calling an Object's Methods
Creating a Class
The Class Declaration
The Class Body
Constructors for Classes
Implementing Methods
The Method Body
A Method's Name
Example of the Math class
The Applet Package
Array and String
Arrays
Java arrays
Object arrays
Strings
String Concatenation
Inheritance
Introduction
Creating Subclasses
Member Variables In Subclass Inherit?
Hiding Member Variables
Methods In Subclass Inherit?
Overriding Methods
Methods a Subclass Cannot Override
Methods a Subclass Must Override
The Benefits of Inheritance
Interfaces
Interfaces and Classes
Implementing and Using Interfaces
Implementing Multiple Interfaces
Creating and Extending Interfaces
Methods Inside Interfaces
Extending Interfaces
Package
Introduction
Declaring Packages
Importing Packages
Creating Our Own Packages
The Java Language Package
The Java I/O Package
The Java Utility Package
The Java Networking Package
The Applet Package
The Abstract Window Toolkit Packages
Multithreading
Introduction
Thread
Thread Attributes
Thread State
Thread Group
Methods that Operate on the Group
Access Restriction Methods
The notifyAll() and wait() Methods
Frequently used Method
Exception Handling
Introduction
What Is an Exception?
If Exceptions than?
The exception handling technique
Some Terminology
Throw an Exception
Throw, try, and catch Blocks
Multiple catch Blocks
The finally Clause
The Throwable Class
Types of Exceptions
Different List of Exception
Built-In Exceptions
Applet
Introduction
How Applets and Applications Are Different
Limitation of Applet
The Applet class
Major Applet Activities
The life cycle of a Web page applet
Including an Applet on a Web Page
Essential HTML to launch an applet and pass it parameters
Launching an applet in an HTML document
A sample applet that receives a parameter
Posting a Web page that launches a custom applet
Managing Input/Output Files in Java
Introduction
Streams
Input Streams
The Abstract Class InputStream
The File class
The FileDialog class
Low-level and high-level stream classes
The FileOutputStream class
The FileInputStream class
The DataOutputStream class
The DataInputStream class
The ObjectOutputStream class
The ObjectInputStream class

Decision making, Branching and Looping


The for statement

1) It is useful when the number of passes (iterations) can be predetermined
 
The general syntax
for (initialization; condition; update)
{
statements;
}
 
where:
initialization - represents the declaration of one or more local variables of the same data type. When loop processing is complete, all such variables are destroyed.
 
condition - represents a binary expression that, if true, allows the loop to continue. The condition is tested prior to each iteration. If no longer true, processing continues at the first statement after the closing brace of the for loop.
 
update - represents one or more expressions to be executed at the end of each iteration.
 
The braces may be omitted if the loop consists of a single statement. This would constitute a "single statement for loop".
 
Example 1:
Counting to 10 with a local variable
for (int i = 1; i <= 10; i++)
System.out.println(i);
 

This is a single statement for loop.

 
Local variable i is initialized to 1 before the first iteration and is used for loop control (its value determines when the loop will end). As long as i is less than or equal to 10, looping will continue. At the end of each iteration, i is incremented. Within each iteration, the current value of i is displayed.
 
When the condition is no longer true, processing will continue at the next statement in the program and variable i will be destroyed.
 
Example 2:
Counting to 10 without a local variable
 
Counting to 10 without a local variable
int i = 1;
for (; i <= 10; i++)
System.out.println(i);
System.out.println("Now i is " + i);
 
Here loop control variable i is initialized outside the loop, it will not be destroyed when the loop completes. Its final value (which will be 11) is displayed by the statement after the loop.
 
Notice that when no initialization expression is coded, a place holding semicolon is still required.
 
Example 3:
Coding multiple initialization and update expressions
 
for (int i = 1, j = 10; i <= 10; i++, j--)
System.out.println(i + " x " + j + " = " + (i * j));
 
This loop initializes two local variables, i and j, of the same data type before the first iteration.
 
At the end of each iteration, i is incremented and j is decremented. Within each iteration, the product of i and j is displayed.
 
Notice that commas are used to separate multiple initialization and update expressions.
It can be nested.
 
For example,
the following program generates a simple 9 x 9 multiplication table:
 

import java.io.*;
public class Aman
{
public static void main(String[] args)
{

// This outer loop generates one row of the multiplication
// table during each iteration.

for (int row = 1; row <= 9; row++) {

// This inner loop generates one column of the current row
// of the multiplication table during each iteration.

for (int column = 1; column <= 9; column++)
{

// If a one digit number is about to be displayed, preceed it
// with four spaces. Otherwise, preceed it with three spaces.

if ((row * column) < 10)
{
System.out.print(" ");
}
else
{
System.out.print(" ");
}

// Display the number.

System.out.print((row * column));
}

// End the current line.

System.out.print(" ");
}
}
}

Output: