Java PDF
Java PDF
Java is a programming language and a platform. Java is a high level, robust, object-oriented
and secure programming language.
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year
1995. James Gosling is known as the father of Java. Before Java, its name was Oak.
History of Java:
1. History of Java
2. Java Version History
The history of Java is very interesting. Java was originally designed for interactive
television, but it was too advanced technology for the digital cable television industry at
the time. The history of Java starts with the Green Team.
1. Edit
Programmer writes program (and stores program on disk)
2. Compile
Compiler creates bytecodes from program
3. Load
Class loader stores bytecodes in memory
4. Verify
Verifier ensures bytecodes do not violate security requirements
5. Execute
Interpreter translates bytecodes into machine language
Operators in Java:
Java provides many types of operators which can be used according to the need. They are
classified based on the functionality they provide. Some of the types are-
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators
Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that they are
used in algebra.
+ Addition
– Subtraction (also unary minus)
* Multiplication
/ Division
% Modulus
++ Increment
+= Addition assignment
–= Subtraction assignment
*= Multiplication assignment
/= Division assignment
%= Modulus assignment
– – Decrement
Assignment Operators
Java provides special operators that can be used to combine an arithmetic operation with
an assignment. As you probably know, statements like the following are quite common in
programming:
a = a + 4;
Increment and Decrement
The ++ and the – – are Java’s increment and decrement operators.
// Demonstrate ++.
class IncDec {
public static void main(String args[]) {
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
}
}
Bitwise Operators
Java defines several bitwise operators that can be applied to the integer types, long, int, short,
char, and byte.
Assignment Operator
The assignment operator is the single equal sign, =
var = expression;
Conditional Operator
Java includes a special ternary (three-way) operator that can replace certain types of if-then-
else
statements. This operator is the ?.
expression1 ? expression2 : expression3
Control structure:
If statement:
Method Overloading:
Constructors all have the same name.
Methods are distinguished by their signature:
name
number of arguments
type of arguments
position of arguments
That means, a class can also have multiple usual methods with the same name.
Not to confuse with method overriding (coming up), method overloading:
Event Handling:
It can be generated as a consequence of a person interacting with the elements in a graphical user
interface.
Event Classes:
The classes that represent events are at the core of Java’s event handling mechanism.
EventObject(Object src)
The ActionEvent Class: