0% found this document useful (0 votes)
12 views37 pages

Day 1 Tech

This document provides an introduction to Java, covering its history, features, and the differences between JDK, JRE, and JVM. It explains the compilation and runtime processes, data types, variables, operators, and expressions in Java, along with examples. Additionally, it discusses the types of Java applications and editions, emphasizing Java's platform independence and its widespread use in various devices.

Uploaded by

bhaimodel20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views37 pages

Day 1 Tech

This document provides an introduction to Java, covering its history, features, and the differences between JDK, JRE, and JVM. It explains the compilation and runtime processes, data types, variables, operators, and expressions in Java, along with examples. Additionally, it discusses the types of Java applications and editions, emphasizing Java's platform independence and its widespread use in various devices.

Uploaded by

bhaimodel20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Topic/Course

Sub-Topic (Example: name of college)

Introduction to JAVA
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


Topic/Course
Oracle) in the year 1995. James Gosling is known as the father of Java.
Before Java,Sub-Topic
its name wasname
(Example: Oak. Since Oak was already a registered
of college)

company, so James Gosling and his team changed the name from Oak to
Java.

Platform: Any hardware or software environment in which a program runs,


is known as a platform. Since Java has a runtime environment (JRE) and
API, it is called a platform.
Features of
Java
Compiling our first Program
• Install the JDK if you don't have installed it.

• Set path of the jdk/bin directory.

• Create the java program (preferred notepad)

• Compile and run the java program (Assuming program is saved as


Hello.java

• For compiling : javac Hello.java

• For executing : java Hello


1
2
public class Main
3 {
4
5 public static void main(String[] args)
6 {
7
8 System.out.println(“Lets learn JAVA”);
9
10
11 }
12
13 }
14
15
Output
Lets learn JAVA
class keyword is used to declare a class in java.

public keyword is an access modifier which represents visibility. It means it is


visible to all.

static is a keyword. If we declare any method as static, it is known as the static


method. The core advantage of the static method is that there is no need to create
an object to invoke the static method. The main method is executed by the JVM, so
it doesn't require to create an object to invoke the main method. So it saves
memory.

void is the return type of the method. It means it doesn't return any value.

main represents the starting point of the program.

String[] args is used for command line argument. We will learn it later.

System.out.println() is used to print statement. Here, System is a class, out is


the object of PrintStream class, println() is the method of PrintStream class. We will
learn about the internal working of System.out.println statement later.
What happens at compile time?

At compile time, the Java file is compiled by Java


Compiler (It does not interact with OS) and converts
the Java code into bytecode.
What happens at
runtime?
Classloader: It is the subsystem of JVM
that is used to load class files.

Bytecode Verifier: Checks the code


fragments for illegal code that can violate
access rights to objects.

Interpreter: Read bytecode stream then


execute the instructions.
How to set path in Java

The path is required to be set for using tools such as


javac, java, etc.
If you are saving the Java source file inside the JDK/bin
directory, the path is not required to be set because all
the tools will be available in the current directory.

However, if you have your Java file outside the JDK/bin


folder, it is necessary to set the path of JDK.

There are two ways to set the path in Java:


1.Temporary
2.Permanent
Difference between JDK, JRE, and
JVM

We must understand the differences between JDK,


JRE, and JVM before proceeding further to Java.
JVM
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine
because it doesn't physically exist. It is a specification that provides a runtime
environment in which Java bytecode can be executed. It can also run those
programs which are written in other languages and compiled to Java bytecode.

JVMs are available for many hardware and software platforms. JVM, JRE, and
JDK are platform dependent because the configuration of each OS is different
from each other. However, Java is platform independent. There are three notions
of the JVM: specification, implementation, and instance.

The JVM performs the following main tasks:


•Loads code
•Verifies code
•Executes code
•Provides runtime environment
JRE
JRE is an acronym for Java Runtime Environment. It is also written as Java
RTE. The Java Runtime Environment is a set of software tools which are used
for developing Java applications. It is used to provide the runtime environment.
It is the implementation of JVM. It physically exists. It contains a set of libraries
+ other files that JVM uses at runtime.
The implementation of JVM is also actively released by other companies
besides Sun Micro Systems.
JDK
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development
environment which is used to develop Java applications and applets. It physically exists. It contains JRE +
development tools.
JDK is an implementation of any one of the below given Java Platforms released by Oracle
Corporation:
•Standard Edition Java Platform
•Enterprise Edition Java Platform
•Micro Edition Java Platform
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such as an
interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), etc. to
complete the development of a Java Application.
Application

According to Sun, 3 billion devices run Java. There are many devices
where Java is currently used. Some of them are as follows:

1.Desktop Applications such as acrobat reader, media player, antivirus,


etc.
2.Web Applications such as irctc.co.in, javatpoint.com, etc.
3.Enterprise Applications such as banking applications.
4.Mobile
5.Embedded System
6.Smart Card
7.Robotics
8.Games, etc.
Types of Java Application
• Standalone Application

• Web Application

• Enterprise Application

• Mobile Application
Types of Java Editions
• Java SE – Standard Edition

• Java EE – Enterprise Edition

• Java ME – Micro Edition

• JavaFX
Why is JAVA Platform
Independent?
Why is JAVA both
interpreted and
compiled language?
Why is JAVA slow?

 Dynamic Linking
 Run-time Interpreter
Data Types in Java
Data types specify the different sizes and values
that can be stored in the variable.

There are two types of data types in Java:

1.Primitive data types: The primitive data types


include boolean, char, byte, short, int, long, float
and double.

2.Non-primitive data types: The non-primitive


data types include Classes, Interfaces, and Arrays.
Data Default Default
Type Value size
boolean false 1 bit
char '\u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
Java Variables
A variable is a container which holds the value while the Java
program is executed. A variable is assigned with a data type.
3
Variable is a name of memory location.
Example to understand the types of variables
in java
public class Variable {
int m = 100; // instance variable

void method() {
int n = 90; // local variable
System.out.println(n);
}
public static void main(String
args[]) {
Variable v = new Variable();
v.method();
int data = 50; // local variable
System.out.println(v.m);
System.out.println(data);
}
}
Operators in Java
Operator Type Category Precedence

Unary postfix expr++ expr--

prefix ++expr --expr +expr -expr ~ !

Arithmetic multiplicative */%

additive +-

Shift shift << >> >>>

Relational comparison < > <= >= instanceof

equality == !=

Bitwise bitwise AND &

bitwise exclusive OR ^

bitwise inclusive OR |

Logical logical AND &&

logical OR ||

Ternary ternary ?:

Assignment assignment = += -= *= /= %= &= ^= |=


<<= >>= >>>=
Java Unary Operator
The Java unary operators require only one
operand.
Unary operators are used to perform various
operations i.e.:
•incrementing/decrementing a value by
one
public class OperatorExample{
•negating an expression
•inverting the value of a boolean
public static void main(String
args[])
{
int x=10;
System.out.println(x++);//
10 (11)
System.out.println(++x);//12
System.out.println(x--);//12 (11)
public class OperatorExample
{
public static void main(String
args[])
{
int a=10;
int b=10;
System.out.println(a++ + +
+a);
System.out.println(b++ + b+
+);
}
public class OperatorExample
{
public static void main(String args[])
{
int a=10;
int b=-10;
boolean c=true;
boolean d=false;
System.out.println(~a);//-
11 (minus of total positive value which starts from 0)
System.out.println(~b);//
9 (positive of total minus, positive starts from 0)
System.out.println(!c);//false (opposite of boolean value)
System.out.println(!d);//true
}
Java Assignment
Operator public class OperatorExample
{
public static void main(String[
] args)
{
int a=10;
a+=3;//10+3
System.out.println(a);
a-=4;//13-4
System.out.println(a);
a*=2;//9*2
System.out.println(a);
a/=2;//18/2
Java Left Shift Java Right Shift
Operator Operator
public class OperatorExample public OperatorExample
{ {
public static void main(String args[] public static void main(String args[
) ])
{ {
System.out.println(10<<2);// System.out.println(10>>2);//
10*2^2=10*4=40 10/2^2=10/4=2
System.out.println(10<<3);// System.out.println(20>>2);//
10*2^3=10*8=80 20/2^2=20/4=5
System.out.println(20<<2);// System.out.println(20>>3);//
20*2^2=20*4=80 20/2^3=20/8=2
System.out.println(15<<4);// }
15*2^4=15*16=24 }
Logical && and
Bitwise
public&class OperatorExample{
public static void main(String args[])
{
int a=10;
int b=5;
int c=20;
System.out.println(a<b&&a++<c);//
false && true = false
System.out.println(a);//
10 because second condition is not checked
System.out.println(a<b&a++<c);//
false && true = false
System.out.println(a);//
Logical || and Bitwise |

public class OperatorExample{


public static void main(String args[]){
int a=10;
int b=5;
int c=20;
System.out.println(a>b||a<c);//true || true = true
System.out.println(a>b|a<c);//true | true = true
//|| vs |
System.out.println(a>b||a++<c);//true || true = true
System.out.println(a);//
10 because second condition is not checked
System.out.println(a>b|a++<c);//true | true = true
System.out.println(a);//
11 because second condition is checked
}}
Java Ternary Operator

public class OperatorExample{


public static void main(String args
[])
{
int a=10;
int b=5;
int min=(a<b)?a:b;
System.out.println(min);
}}
List of Java
Keywords
abstract else interface strictfp
boolean enum long super
break extends native switch
byte final new synchronized
case finally null
Catch float package this
Char for private throw
class if protected throws
Continue implements public transient
Default import return try
Do instanceof short void
Double int static volatile
while
Types of Expressions in Java
1. Arithmetic Expressions
• Combine numerical values and operators (+, -, *, /, %).
• Example: a + b * c
2. Relational Expressions
• Compare two values using relational operators (<, >, <=, >=, ==, !=).
• Example: x > y
3. Logical Expressions
• Combine Boolean values using logical operators (&&, ||, !).
• Example: (a > b) && (b < c)
4. Assignment Expressions
• Assign values to variables using =, +=, -=, etc.
• Example: x = y + 5
5. Bitwise Expressions
• Manipulate data at the bit level using operators (&, |, ^, ~, <<, >>).
• Example: a & b
6. Conditional Expressions
• Ternary operator (? :) for decision-making.
• Example: int max = (a > b) ? a : b;
Operator Precedence in Java
Operator Precedence Table (From Highest to Lowest)
Precedence Level Operators Associativity
1 () Left to Right
2 ++, -- (Postfix) Left to Right
3 ++, --, +, - (Unary), ~, ! Right to Left
4 *, /, % Left to Right
5 +, - Left to Right
6 <<, >>, >>> Left to Right
7 <, <=, >, >=, instanceof Left to Right
8 ==, != Left to Right
9 & Left to Right
10 ^ Left to Right
11 && Left to Right
12 ? : (Ternary) Right to Left
13 =, +=, -=, etc. Right to Left
Key Rules
•Operators with higher precedence are evaluated first.
•Parentheses () can be used to override precedence.
THANK YOU

You might also like