Introduction to java

                        Flaours of Java

1: core java (J2SE)  for s/w .

2:  Advance java (J2EE) for web/application.

3: Android java (J2ME) for apps.


Q.1: what is java.? and full explain .

Ans: java is a class based, high-level object oriented programming language.

           Developed by"JAMES GOSLING" and his friends in the year 1995.

NOTE: * The first version of java (JDK 1.0) was released on the year

                     jan -23rd 1996 by"SUN MICROSYSTEM".

        *  Latest version of java(JDK 16) on the day 16th-march-2021 by"ORACLE".

Syntax :

                            class class_name{

                                                        public static void main(String args []){

                                                    //code

                                                    }          

                                                  }

                               


Java Tutorial

        Our core Java programming tutorial is designed for students and working professionals. Java is an object-oriented, class-based, concurrent, secured and general-purpose computer-programming language. It is a widely used robust technology.

What is 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 Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered 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.

Java Example

Let's have a quick look at Java programming example. A detailed description of Hello Java example is available in next page.

Simple.java

  1. class Simple{  
  2.     public static void main(String args[]){  
  3.      System.out.println("Hello defaultjava56");  
  4.     }  
  5. }  

output: 

Compile by: javac Simple.java

Run by: java Simple

hello defaultjava56

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 Applications

There are mainly 4 types of applications that can be created using Java programming:

1) Standalone Application

Standalone applications are also known as desktop applications or window-based applications. These are traditional software that we need to install on every machine. Examples of standalone application are Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone applications.

2) Web Application

An application that runs on the server side and creates a dynamic page is called a web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used for creating web applications in Java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications, etc. is called an enterprise application. It has advantages like high-level security, load balancing, and clustering. In Java, EJB is used for creating enterprise applications.

4) Mobile Application

An application which is created for mobile devices is called a mobile application. Currently, Android and Java ME are used for creating mobile applications.

Java Platforms / Editions

There are 4 platforms or editions of Java:

1) Java SE (Java Standard Edition)

It is a Java programming platform. It includes Java programming APIs such as java.lang, java.io, java.net, java.util, java.sql, java.math etc. It includes core topics like OOPs, String, Regex, Exception, Inner classes, Multithreading, I/O Stream, Networking, AWT, Swing, Reflection, Collection, etc.

2) Java EE (Java Enterprise Edition)

It is an enterprise platform that is mainly used to develop web and enterprise applications. It is built on top of the Java SE platform. It includes topics like Servlet, JSP, Web Services, EJB, JPA, etc.

3) Java ME (Java Micro Edition)

It is a micro platform that is dedicated to mobile applications.

4) JavaFX

It is used to develop rich internet applications. It uses a lightweight user interface API

         

Difference between JDK, JRE, and JVM

We must understand the differences between JDK, JRE, and JVM before proceeding further to Java. See the brief overview of JVM here.

If you want to get the detailed knowledge of Java Virtual Machine, move to the next page. Firstly, let's see the differences between the 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. 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
More Details.

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.

JRE

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.

         
 

.

JVM (Java Virtual Machine) Architecture

JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

What is JVM

It is:

  1. A specification where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Oracle and other companies.
  2. An implementation Its implementation is known as JRE (Java Runtime Environment).
  3. Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created.

What it does

The JVM performs following operation:

Current Time 0:00
Duration 18:10
Loaded0.37%
 

  • Loads code
  • Verifies code
  • Executes code
  • Provides runtime environment

JVM provides definitions for the:

  • Memory area
  • Class file format
  • Register set
  • Garbage-collected heap
  • Fatal error reporting etc.

JVM Architecture

Let's understand the internal architecture of JVM. It contains classloader, memory area, execution engine etc.

JVM Architecture

1) Classloader

Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.

  1. Bootstrap ClassLoader: This is the first classloader which is the super class of Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes etc.
  2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loades the jar files located inside $JAVA_HOME/jre/lib/ext directory.
  3. System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the classfiles from classpath. By default, classpath is set to current directory. You can change the classpath using "-cp" or "-classpath" switch. It is also known as Application classloader.
  1. //Let's see an example to print the classloader name  
  2. public class ClassLoaderExample  
  3. {  
  4.     public static void main(String[] args)  
  5.     {  
  6.         // Let's print the classloader name of current class.   
  7.         //Application/System classloader will load this class  
  8.         Class c=ClassLoaderExample.class;  
  9.         System.out.println(c.getClassLoader());  
  10.         //If we print the classloader name of String, it will print null because it is an  
  11.         //in-built class which is found in rt.jar, so it is loaded by Bootstrap classloader  
  12.         System.out.println(String.class.getClassLoader());  
  13.     }  


output:
   sun.misc.Launcher$AppClassLoader@4e0e2f2a 

        null 

These are the internal classloaders provided by Java. If you want to create your own classloader, you need to extend the ClassLoader class.

2) Class(Method) Area

Class(Method) Area stores per-class structures such as the runtime constant pool, field and method data, the code for methods.

3) Heap

It is the runtime data area in which objects are allocated.

4) Stack

Java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return.

 Each thread has a private JVM stack, created at the same time as thread.

A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.

5) Program Counter Register

PC (program counter) register contains the address of the Java virtual machine instruction currently being executed.

6) Native Method Stack

It contains all the native methods used in the application.

7) Execution Engine

It contains:

  1. A virtual processor
  2. Interpreter: Read bytecode stream then execute the instructions.
  3. Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here, the term "compiler" refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

8) Java Native Interface

Java Native Interface (JNI) is a framework which provides an interface to communicate with another application written in another language like C, C++, Assembly etc. Java uses JNI framework to send output to the Console or interact with OS libraries.

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.

Variable is a name of memory location. There are three types of variables in java: local, instance and static.

There are two types of data types in Java: primitive and non-primitive.


Variable

A variable is the name of a reserved area allocated in memory. In other words, it is a name of the memory location. It is a combination of "vary + able" which means its value can be changed.

variables in java

  1. int data=50;//Here data is variable  

Types of Variables

There are three types of variables in Java:

  • local variable
  • instance variable
  • static variable

types of variables in java

1) Local Variable

A variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class aren't even aware that the variable exists.

A local variable cannot be defined with "static" keyword.

2) Instance Variable

A variable declared inside the class but outside the body of the method, is called an instance variable. It is not declared as static.

It is called an instance variable because its value is instance-specific and is not shared among instances.

3) Static variable

A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variables happens only once when the class is loaded in the memory.

Example to understand the types of variables in java

  1. public class A  
  2. {  
  3.     static int m=100;//static variable  
  4.     void method()  
  5.     {    
  6.         int n=90;//local variable    
  7.     }  
  8.     public static void main(String args[])  
  9.     {  
  10.         int data=50;//instance variable    
  11.     }  
  12. }//end of class   

Java Variable Example: Add Two Numbers

  1. public class Simple{    
  2. public static void main(String[] args){    
  3. int a=10;    
  4. int b=10;    
  5. int c=a+b;    
  6. System.out.println(c);    
  7. }  
  8. }    

Output:

20

Java Variable Example: Widening

  1. public class Simple{  
  2. public static void main(String[] args){  
  3. int a=10;  
  4. float f=a;  
  5. System.out.println(a);  
  6. System.out.println(f);  
  7. }
  8. }  
  9. output: 10
  10.               10.0 

Run by: java ClassLoaderExample

[email protected]

 

null

JVM (Java Virtual Machine) Architecture

JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

What is JVM

It is:

  1. A specification where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Oracle and other companies.
  2. An implementation Its implementation is known as JRE (Java Runtime Environment).
  3. Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created.

What it does

The JVM performs following operation:


repeat: initial; background-position: initial; background-size: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-width: initial; border-style: none; border-color: initial; transition: none 0s ease 0s; appearance: none; width: 40px; height: 15px; position: relative; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; padding: 0px; flex: 0 0 auto; background-image: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 xmlns:xlink=%27http://www.w3.org/1999/xlink%27 width=%2718.861%27 height=%2718.61%27 viewBox=%270 0 18.861 18.61%27%3E%3Cdefs%3E%3CclipPath id=%27clip-path%27%3E%3Crect id=%27Rectangle_39%27 data-name=%27Rectangle 39%27 width=%2718.861%27 height=%2718.61%27 transform=%27translate%280 0%29%27 fill=%27none%27/%3E%3C/clipPath%3E%3C/defs%3E%3Cg id=%27Group_74%27 data-name=%27Group 74%27 transform=%27translate%280 0%29%27%3E%3Crect id=%27Rectangle_38%27 data-name=%27Rectangle 38%27 width=%271.501%27 height=%2723.56%27 transform=%27translate%281.825 1.089%29 rotate%28-42.266%29%27 fill=%27%23fff%27/%3E%3Cg id=%27Group_72%27 data-name=%27Group 72%27%3E%3Cg id=%27Group_71%27 data-name=%27Group 71%27 clip-path=%27url%28%23clip-path%29%27%3E%3Cpath id=%27Path_95%27 data-name=%27Path 95%27 d=%27M4.1,5.61H0V13H4.1l4.309,3.448L11.09,18.61V9.052L6.335,3.819Z%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_96%27 data-name=%27Path 96%27 d=%27M11.091,1.3V0L8.3,2.239l0,0-.8.639,3.582,3.941Z%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_97%27 data-name=%27Path 97%27 d=%27M13.009,1.707a7.856,7.856,0,0,1,1.106.605A8.391,8.391,0,0,1,16.9,13.207l.715.786A9.323,9.323,0,0,0,12.681.5l-.008,0V1.585c.111.048.228.083.336.135Z%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_98%27 data-name=%27Path 98%27 d=%27M13.854,16.468a7.29,7.29,0,0,1-.844.439v-.029c-.11.052-.225.093-.336.143v1.1l.008,0a9.38,9.38,0,0,0,1.695-.8,9.446,9.446,0,0,0,2.35-2.068l-.677-.745a8.441,8.441,0,0,1-2.2,1.961%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_99%27 data-name=%27Path 99%27 d=%27M16.018,11.454c-.064.185-.144.363-.223.541.08-.178.159-.356.223-.541%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_100%27 data-name=%27Path 100%27 d=%27M13.332,3.752c.047.03.1.055.142.086l-.029-.022c-.036-.024-.076-.041-.113-.064%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_101%27 data-name=%27Path 101%27 d=%27M12.733,3.412l.015.007-.015-.008Z%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_102%27 data-name=%27Path 102%27 d=%27M16.367,9c0,.1.016.206.016.311,0,.09-.01.178-.014.268,0-.09.017-.178.017-.269S16.372,9.1,16.367,9%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_103%27 data-name=%27Path 103%27 d=%27M12.674,3.387v.142l.059-.117-.059-.025%27 fill=%27%23fff%27/%3E%3Cpath id=%27Path_104%27 data-name=%27Path 104%27 d=%27M15.386,9.306a5.608,5.608,0,0,1-.33,1.876l.739.813c.079-.178.159-.355.223-.541.032-.092.064-.184.092-.278.039-.133.072-.267.1-.4.026-.116.048-.233.068-.351s.044-.253.058-.382c.017-.153.024-.309.03-.465,0-.09.013-.178.013-.269s-.01-.207-.015-.31c-.007-.137-.011-.275-.026-.41s-.035-.239-.054-.358-.043-.253-.071-.377-.056-.231-.089-.345-.075-.248-.118-.369-.074-.218-.118-.324c-.053-.131-.115-.257-.176-.384s-.133-.266-.207-.395c-.087-.152-.176-.3-.274-.445-.065-.1-.137-.185-.207-.276s-.156-.2-.238-.3-.156-.175-.236-.26-.19-.19-.289-.282c-.079-.072-.155-.146-.238-.215a6.63,6.63,0,0,0-.552-.42c-.046-.031-.1-.057-.142-.086-.189-.119-.383-.231-.585-.332l-.014-.008-.059.118v1c.072.042.148.077.216.123a5.588,5.588,0,0,1,2.5,4.658%27 fill=%27%23fff%27/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") !important; margin-left: -0.4em !important;">Unmute
Current Time 0:00
Duration 18:10
Loaded0.37%
 

JVM (Java Virtual Machine) Architecture
Java Virtual Machine
Internal Architecture of JVM
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

What is JVM
It is:

A specification where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Oracle and other companies.
An implementation Its implementation is known as JRE (Java Runtime Environment).
Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created.
What it does
The JVM performs following operation:
Play

Next
Unmute
Current Time 
0:00
/
Duration 
18:10
 
Fullscreen

Backward Skip 10s

Play Video

Forward Skip 10s

Loads code
Verifies code
Executes code
Provides runtime environment
JVM provides definitions for the:

Memory area
Class file format
Register set
Garbage-collected heap
Fatal error reporting etc.
JVM Architecture
Let's understand the internal architecture of JVM. It contains classloader, memory area, execution engine etc.

JVM Architecture

1) Classloader
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.

Bootstrap ClassLoader: This is the first classloader which is the super class of Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes etc.
Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loades the jar files located inside $JAVA_HOME/jre/lib/ext directory.
System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the classfiles from classpath. By default, classpath is set to current directory. You can change the classpath using "-cp" or "-classpath" switch. It is also known as Application classloader.
//Let's see an example to print the classloader name  
public class ClassLoaderExample  
{  
    public static void main(String[] args)  
    {  
        // Let's print the classloader name of current class.   
        //Application/System classloader will load this class  
        Class c=ClassLoaderExample.class;  
        System.out.println(c.getClassLoader());  
        //If we print the classloader name of String, it will print null because it is an  
        //in-built class which is found in rt.jar, so it is loaded by Bootstrap classloader  
        System.out.println(String.class.getClassLoader());  
    }  
}     

  • Loads code
  • Verifies code
  • Executes code
  • Provides runtime environment

JVM provides definitions for the:

  • Memory area
  • Class file format
  • Register set
  • Garbage-collected heap
  • Fatal error reporting etc.

JVM Architecture

Let's understand the internal architecture of JVM. It contains classloader, memory area, execution engine etc.

JVM Architecture

1) Classloader

Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.

  1. Bootstrap ClassLoader: This is the first classloader which is the super class of Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes etc.
  2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loades the jar files located inside $JAVA_HOME/jre/lib/ext directory.
  3. System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the classfiles from classpath. By default, classpath is set to current directory. You can change the classpath using "-cp" or "-classpath" switch. It is also known as Application classloader.
  1. //Let's see an example to print the classloader name  
  2. public class ClassLoaderExample  
  3. {  
  4.     public static void main(String[] args)  
  5.     {  
  6.         // Let's print the classloader name of current class.   
  7.         //Application/System classloader will load this class  
  8.         Class c=ClassLoaderExample.class;  
  9.         System.out.println(c.getClassLoader());  
  10.         //If we print the classloader name of String, it will print null because it is an  
  11.         //in-built class which is found in rt.jar, so it is loaded by Bootstrap classloader  
  12.         System.out.println(String.class.getClassLoader());  
  13.     }  
  14. }     
Loaded
















          

Comments