You are on page 1of 19

Java Programming Language

Syntex
The following table summarizes all versions of Java SE from its early days to the latest.

Java SE Version Version Number Release Date

JDK 1.0 1.0 January 1996


(Oak)

JDK 1.1 1.1 February 1997

J2SE 1.2 1.2 December 1998


(Playground)

J2SE 1.3 1.3 May 2000


(Kestrel)

J2SE 1.4 1.4 February 2002


(Merlin)

J2SE 5.0 1.5 September 2004


(Tiger)

Java SE 6 1.6 December 2006


(Mustang)

Java SE 7 1.7 July 2011


(Dolphin)

Java SE 8 1.8 March 2014

Java SE 9 9 September, 21st 2017


Java SE 10 10 March, 20th 2018

Java SE 11 11 September, 25th 2018

Java SE 12 12 March, 19th 2019

Java SE 13 13 September, 17th 2019

Java SE 14 14 March, 17th 2020

Java SE 15 15 September, 15th 2020

Java SE 16 16 March, 16th 2021

Java SE 17 17 September, 14th 2021

Java SE 18 18 March, 22nd 2022

Java SE
19 19

September, 20th 2022

Java SE 20 20 March, 21st 2023

Java SE 21 21 September, 19th 2023


From the table above we can see that the naming and the version number have
been changing over times:

 Versions 1.0 and 1.1 are named as JDK (Java Development Kit).
 From versions 1.2 to 1.4, the platform is named as J2SE (Java 2 Standard
Edition).
 From versions 1.5, Sun introduces internal and external versions. Internal
version is continuous from previous ones (1.5 after 1.4), but the external
version has a big jump (5.0 for 1.5). This could make confusion for someone,
so keep in mind that version 1.5 and version 5.0 are just two different version
names for only one thing.
 From Java 6, the version name is Java SE X.

1) class is a keyword. Every keyword in java should be in lowercase.

2) Hello is our class name. First letter of class name should be in uppercase. It
is not a condition but it is just a convention.

3) public, static and void all are keywords.

4) main is a method name. Method name must be in lowercase. main method


is a special method because execution of a java program starts
from main method. This method takes one argument of type String array.
Remember main is not a keyword.

5) String is a final class from java.lang package.

6) System is also a final class from java.lang package. out is a static member
of System class of type PrintStream. println is a method
of PrintStream class.

7) You can explore the source code of both System class and String class. Go
to JDK installation directory and extract the ‘src‘ zip file. Then go to src –> java
–> lang. In lang folder, you will find both System and String Java files.

8) Above program prints “Hello World” on the console.

Java JDK, JRE and JVM


JVM (Java Virtual Machine) is an abstract machine that enables your
computer to run a Java program.
When you run the Java program, Java compiler first compiles your Java code
to bytecode. Then, the JVM translates bytecode into native machine code (set
of instructions that a computer's CPU executes directly).

Source code

class Hello

Int a=10;

public static void main(String args[]) // main thread

System.out.println(“Hello”);

System.out.println(“Hello ” + “World”);

Compiler – analyse the code and find the syntax error in the programs

Scan the complete program and finds the error

Interpreter – execute the program

Which read the lines one by one and display the error

Java is a platform-independent language


It's because when you write Java code, it's ultimately written for JVM but not
your physical machine (computer). Since JVM executes the Java bytecode
which is platform-independent, Java is platform-independent.

Source code -------Compiler -----byte code ------JVM -----Machine code -------CPU –


display output

Working of Java Program

Windows Byte Code -- windows specific JVM


Linux Byte Code—Linux specific JVM
Mac OS Byte Code – Mac-OS specific JVM

Java is platform-independent language


But JVM is Platform dependent.
What is JRE?
JRE (Java Runtime Environment) is a software package that provides Java
class libraries, Java Virtual Machine (JVM), and other components that are
required to run Java applications.
JRE is the superset of JVM.

Java Runtime Environment


What is JDK?

JDK (Java Development Kit) is a software development kit required to develop


applications in Java. When you download JDK, JRE is also downloaded with
it.

In addition to JRE, JDK also contains a number of development tools


(compilers, JavaDoc, Java Debugger, etc).

Java Development Kit

Relationship between JVM, JRE, and JDK.

Relationship between JVM, JRE, and


JDK

package com.corejava.demo;
/*advantage of java
Object oriented programming language
Functional programming language - task why
the java is called functional programming
language
platform independent
simple - python
multithreded-
Interpreted language
High performance - JIT(Just In time)
Java editor
Notepad
Eclipse
Netbeans
VScode

Java Identifiers
All Java components require names. Names
used for classes,
variables, and methods are called
identifiers.
• All identifiers should begin with a
letter (A to Z or a to z), currency
character ($) or an underscore (_).
• After the first character, identifiers
can have any combination of characters.
• A key word cannot be used as an
identifier.
• Most importantly, identifiers are case
sensitive.
Java Variable
variable is a container
A-Z to a-z

int a; variable declartion (a is


identifier, type of a data is a)

int a=10; variable initilization

3 types
• Local variables
• Local variables are declared in methods,
constructors, or blocks
• Local variables are created when the
method, constructor or block
is entered and the variable will be
destroyed once it exits the method,
constructor, or block.
• Local variables are visible only within
the declared method, constructor, or block
• There is no default value for local
variables, so local variables should
be declared and an initial value should be
assigned before the first use

• Instance variables
• Instance variables are declared in a
class,
but outside a method, constructor or any
block.
• Instance variables are created when an
object is
created with the use of the keyword 'new'
and destroyed when the object
is destroyed.
• The instance variables are visible for
all methods,
constructors and block in the class.
• Instance variables have default values.

• Class/Static variables

byte a=10; number


short a=10; number
int a=10; number
long a=10; number

a=s; character
a=10.5 floating number
a=padmaja world string (collection of
character)

Java Provided me predefined data types

byte - • Byte data type is an 8-bit - 1


byte
• Minimum value is -128 to (-2^7)
• Maximum value is 127 (inclusive)(2^7 -1)
• Default value is 0
short- • Short data type is a 16-bit - 2
byte
• Minimum value is -32,768 (-2^15)
• Maximum value is 32,767 (inclusive)
(2^15 -1)
• Default value is 0
int- • Int data type is a 32-bit - 4 byte
• Minimum value is - 2,147,483,648 (-2^31)
• Maximum value is
2,147,483,647(inclusive) (2^31 -1)
• Default value is 0

long- • Long data type is a 64-bit - 8


bytes
• Minimum value is -
9,223,372,036,854,775,808(-2^63)
• Maximum value is
9,223,372,036,854,775,807 (inclusive)(2^63
-1)
• Default value is 0L

float- • Float data type is 32 bit decimal


point- 4 byte
• Float is mainly used to save memory in
large arrays of floating point numbers
• Default value is 0.0f
float f1 = 234.5f

double Float data type is 64 bit


• Default value is 0.0d
double d1 = 123.4
boolean -• boolean data type represents
one bit of information
• There are only two possible values: true
and false
• Default value is false
char- • char data type is a single 16-bit
*/

public class Hello//identifier (which will


be going to identify the name of the class)
{
//int xyz;//identifer;

byte b; // instance variable // need not


to be intilize it will give the defalut
value
public void display()
{
//byte b; // local variable // it
must be initilize
System.out.println(b);
}
default value =0
public static void main(String[] args) {
//byte a; // local variable
//System.out.println(a);
Hello h=new Hello();
h.display();
}

class NameOfTheClass
{
//Body of the class
//what it includes in the body
//data member
// member functions
}

/*
* class ABC { int a; } class Student {
//data member int id; // instance
* variable String name address course int
dob
*
* // member functions accessspecifier
returntype methodname(parameter list)
*
* public void display() {
*
* }
*
* store
*
* view
*
* }
*/

public class VariableDemo {


int marks; // instance variable
public void displayMarks()
{
int marks = 0;
marks=marks+100;
//marks=0+100;
//marks=100;
System.out.println("My Marks
are "+ marks);
}
public static void main(String[]
args) {
VariableDemo vd=new
VariableDemo();// craeting the
object for the class with which i
can call the method
vd.displayMarks();
}
}

/*Java provides a rich set of


operators to manipulate variables.
We can divide all the Java
operators into the following groups
• Arithmetic Operators
• Relational Operators
• Bitwise Operators
• Logical Operators
• Assignment Operators
unary operators
*
*/
public class OperatorDemo {

public static void main(String[]


args) {
int a=10;
int b=3;
int c=5;
int result=a+b;
//Arithmetic Operator
System.out.println("a + b = "
+ result);//+ operator a , b are
called operands
System.out.println("a - b = "
+ (a - b));
System.out.println("a / b = "
+ (a / b));
System.out.println("a * b = "
+ (a * b));
System.out.println("a % b = "
+ (a % b));

// Relatinonal operator
System.out.println("a > b = "
+ (a > b));
System.out.println("a < b = "
+ (a < b));
System.out.println("a >= b = "
+ (a >= b));
System.out.println("a <= b = "
+ (a <= b));
System.out.println("a == b = "
+ (a == b));
System.out.println("a != b = "
+ (a != b));

// bitwise operator
/*
* Java defines several
bitwise operators,
* which can be applied to the
integer types, long, int,
* short, char, and byte.
Bitwise operator works on bits and
performs bit-by-bit operation
*/
int m=60; // 0011 1100
// 128 64 32 16 8 4 2
1
// 0 0 1 1 1 1 0
0 =60
int n=13; // 0 0 0 0 1 1
0 1 =13
// a&b = 0000 1100 = 12
/*
* a|b = 0011 1101 =61
a^b = 0011 0001 =49
~a = 1100 0011 =

*/
result=m & n;
System.out.println(result);
result=m | n;
System.out.println(result);
result=m ^ n;
System.out.println(result);
result=m & n;
System.out.println(result);
result=m >> 2; // 15
System.out.println("m >> 2" +
result);
result=m << 2; // 15
System.out.println("m << 2" +
result);
// Ternary Operator
int min=(a<b)? a : b;
System.out.println(min);

// assignemnt/complex operator
System.out.println("a=a+b " +
(a +=b));
System.out.println("a=a-b " +
(a -=b));
System.out.println("a=a*b " +
(a *=b));
System.out.println("a=a/b " +
(a /=b));

// increment and decrement


operators
int x=5;
int z=10;
System.out.println(x);
System.out.println(x++);
System.out.println(x--);
//preincrement and post
increment
System.out.println(++x);
//pre-increment operator
System.out.println(x++);
//post- increment operator

You might also like