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
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
Declaring Variables
Rules on Variable Names
Variable Types
Primitive Data Types
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
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
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
Java arrays
Object arrays
String Concatenation
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 and Classes
Implementing and Using Interfaces
Implementing Multiple Interfaces
Creating and Extending Interfaces
Methods Inside Interfaces
Extending Interfaces
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
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
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
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
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
Examples of Core Java
A simple program printing 'Hello'.
Writing the first ten multiples of any number using for loop.
To check whether a number is a PERFECT NUMBER or not.
A simple program using accumulator.
Calculate the square of the numbers from 1 to 10

Exception Handling

The exception handling technique

• Involves the use of the try, catch, and finally Java keywords
• Consists of several steps
1. try a block of code that may result in an exception being "thrown"
2. Code one or more blocks designed to automatically catch and handle a specific type of exception if one occurs. At most, only one of these blocks can be called in a single pass through the code. If none of the specified exceptions occurs, none of the blocks will be executed.
3. Optionally code a block that will finally be run in ALL situations, whether an exception occurs or not
• Has the following general syntax:
statements that may result in an exception being thrown;

catch (exception-type1 reference)
statements to handle the exception;

catch (exception-type2 reference)
statements to handle the exception;

other catch blocks...

statements to be ALWAYS executed;
The following is a modified version of the "shell game" program presented earlier. It contains a try block and two catch blocks. One handles a NullPointerException and the other handles an ArrayIndexOutOfBoundsException. No finally block is specified, so logic comes together after the end of the last catch block.
public class AppExcep
public static void main(String[] args)

// Loop control variable.

char again = 'y';

// Main loop. One array is entered and processed in each iteration.

while (again == 'Y' || again =='y')

// Instantiate a three element array and load a single String
// at a random element location.

String[] strings = new String[3];
int randomIndex = (int) ((Math.random()*100) % strings.length);
strings[randomIndex] = "Lucky";

// Ask the user to guess the element location.

Utility.separator(50, '>');
System.out.print("Pick a number from 1 to " + strings.length + ": ");

// "Try" to read their response, use it to index into the array,
// and see if they win.


// If they guess the element location, display a message. Otherwise,
// an exception will occur.

if (strings[Keyboard.readInt() - 1].equals("Lucky"))
System.out.println(" YOU WIN!!!");

// This block is automatically executed if a NullPointerException
// occurs to indicate a null array location.

catch (NullPointerException err)
System.out.println(" Empty shell - YOU LOSE!!!");

// If an ArrayIndexOutOfBoundsException occurs, this block is
// automatically executed. It indicates an invalid number was
// used as an index.

catch (ArrayIndexOutOfBoundsException err)
System.out.println(" Invalid number - YOU LOSE");

// Ask the user if they want to do it again and repeat the loop as
// requested.

Utility.separator(40, '=');
System.out.print("Again? (Y/N): ");
again = Keyboard.readChar();