JAVA Introduction
JAVA Introduction
James Gosling
What you will be able to do after Learning Java
Programming??
Java Object:
Java object is any real time entity in the world associated with
some states/properties and different behaviours/ Methods where
states are represented using data types(static/instance variables)
and behaviours are represented using methods/functions.
Modification in the states achieve the correct behaviours of any
object.
4 main OOPS of java:
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Java does support Abstraction & Encapsulation
Java does support Polymorphism
import java.lang.*;
class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello This is my First Java Code");
}
}
How to WriteCompile Execute Java Code/Program
• Step2: Open command prompt and navigate to the directory where you have stored the file.
• Step 4: On successful compilation, you will see the command prompt and HelloWorld.class file in
the same folder where HelloWorld.java is stored. This is the byte code of the program.
• Step 5: To execute, type java HelloWorld Do not type the extension while executing.
• Step 6: See the output Hello This is my First Java Code displayed on the console.
How to WriteCompile Execute Java Code/Program
1. Create folder on any drive on the PC
2. In the folder create notepad file and write java code in it and save
the file with Classname.java
3. Compile java program using command: javac HelloWorld.java
4. Execute java program using command: java HelloWorld
Setting Path one time to run java program on any drive
any folder:
Basic Constructs:
• Constants
• variables and data types
• Wrapper classes
• Operators and Expressions
Java Constants
Data Types
int i = 5;
int j = 4.5;
float x = 3.5;
float y = (float) 3.5;
Error check each of the
double z = 100;
statements in the box to
i = z;
the right
y = z;
z = i;
j = (long) y;
j = (byte) y;
Operators and Expressions
Method Description
1 Byte Byte.ParseByte()
2 Short Short.valueOf()
3 Integer Integer.shortInt()
4 Long Long.parseLong()
5 Float Float.parseFloat()
6 Double Double.parseDouble()
Input through BufferedReader class
BufferedReader is another way to take the input
from the user, but it’s a bit more complex than the
Scanner class. java.io.BufferedReader reads text
from the character-input stream.
The scanner class is not synchronous and does not support The BufferedReader class is synchronous and Widely used
threads. with multiple threads.
Scanner breaks its input into tokens using a Delimiter BufferedReader simply reads the sequence of characters in a
pattern. portion that depends on the buffer size.