Java Tutorial
Java Tutorial
TUTORIAL
What is Java?
• Java is a popular programming language, created in 1995.
• It is owned by oracle, and more than 3 billion devices run Java.
• It is used for :
1. Mobile applications (specially Android apps)
2. Desktop applications such as acrobat reader, media player, antivirus,etc.
3. Web applications such as irctc.co.in, javapoint.com, etc
4. Enterprise Applications such as banking applications.
5. Web servers and application servers
6. Games
7. Database connection
8. Smart Card
9. Embedded System
Why use Java?
• Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
• It is one of the most popular programming language in the world
• It is easy to learn and simple to use
• It is open-source and free
• It is secure, fast and powerful
• It has a huge community support (tens of millions of developers)
Features of Java
1. Simple 2. Object-Oriented
5. Secured 6. Robust
Bytecode Verifier: checks the code fragments for illegal code that can
violate access right to objects.
• The path is required to be set for using tools such as javac, java, etc.
• To set the temporary path of JDK, you need to follow the following steps:
STEP 1: Open the command prompt
STEP 2: Copy the path of the JDK/bin directory
STEP 3: Write in command prompt: set path=copied_path
For Example:
set path=C:\Program Files\Java\jdk1.6.0_23\bin
2) How to set Permanent Path of JDK in Windows
• For setting the permanent path of JDK, you need to follow these steps:
• Go to MyComputer properties -> advanced tab -> environment variables -> new
tab of user variable -> write path in variable name -> write path of bin folder in
variable value -> ok -> ok -> ok
Difference between JDK, JRE, and JVM
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.
• The JVM performs the following main tasks:
1) Loads code
2) Verifies code
3) Executes code
4) Provides runtime environment
JRE ( Java Runtime Environment)
• It 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.
JDK(Java Development Kit)
• is a software development environment which is used to develop Java
applications and applets.
• It physically exists. It contains JRE + development tools.
Java Variables
• A variable is a container which holds the value while the java program is
executed.
• A variable is assigned with a datatype.
• Variable is a name of memory location.
• For example
int data=50;//Here data is variable
• Types of Variables
1) local variable
2) instance variable
3) static variable
Types of variables
1) Local Variable
• A variable declared inside the body of the method is called local variable.
2) Instance Variable
• A variable declared inside the class but outside the body of the method, is called
instance variable.
3) Static variable
• A variable which is declared as static is called static variable.
• It cannot be local.
• Memory allocation for static variable happens only once when the class is loaded
in the memory.
• You can create a single copy of static variable and share among all the instances
of the class.
• Example to understand the types of variable in java
class A{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
Static Variable example
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:
• Primitive data types: The primitive data types include boolean, char, byte,
short, int, long, float and double.
• Non-primitive data types: The non-primitive data types include Classes,
Interfaces, and Arrays.
Java Primitive Data Types
Data Type Default Value Default size