How Java is platform independent

In our earlier tutorial we have seen the difference between JDK, JRE, JVM. In this tutorial we will see one more important concepts which every Java Developer should know. We know JDK, JRE, JVM are platform dependent but how Java is platform independent.

The configuration for each OS is different so JDK, JRE, JVM are all platform dependent. But the Java code developed in Windows can be executed in Apple/Linux or vice versa, which is called WORA means Write Once Run Anywhere.

To understand this we must should understand the execution of Java Program.

How Java is Platform Independent

How Java is Platform Independent

  • When we write Java Code, we will save it with an extension of .java.
  • Using Java Compiler, the java source code will be converted to bytecode, means .java file will be converted into .class file.
  • This .class file will be converted into native machine code by JVM and get executed.

But the magic happened in the bytecode (.class file). The converted byte code is platform independent can be executed by any JVM irrespective of Operating System.

Eg: When we develop the code in Linux machine and compiled it, we will get byte code. This byte code can be executed in Windows/Apple OS machine which makes the Java is Platform Independent.

Difference between JRE JDK JVM

In this post we will see about one of most common Java interview question for all level of Java developers, which is Tell me the “Difference between JRE JDK JVM”.

JRE – Java Runtime Environment:

To execute the program, JRE is enough. JRE contains JVM and other libraries. JRE will not have any development tools like compiler or debugger. JRE must be installed to execute any Java program.

Difference between JRE JDK JVM -  JRE Architecture

Difference between JRE JDK JVM – JRE Architecture

 

JDK – Java Development Kit:

JDK is a combination of development tools (like compiler, launcher and debugger) and JRE. With the help of development tools, we can develop a java program and compile it (using compiler). With the help of JRE we can execute it.

Difference between JRE JDK JVM - JDK Architecture

Difference Between JRE, JDK and JVM – JDK Architecture

Compiler in the JDK converts java code (.java) into byte code (.class) and in JRE with the help of JVM byte will be converted into machine code and executes it.

JDK must be installed if we want to write code, compile it and execute it.

JRE is enough if we only want to execute the code and not going to write any code.

JVM – Java Virtual Machine:

Java code (.java) will be converted into byte code (.class) using Java Compiler. Those machine code can’t be executed directly in a machine. It needs to be converted into machine code to execute it. JVM understands the byte code and convert into machine code to execute it.

JVM executes by converting the bytecode to machine code. JVM has built in interpreter and JIT Compiler both helps in converting the bytecode to machine code.

Interpreter converts each bytecode to native code/instruction. Here conversion means it maps the bytecode to corresponding native code.

JIT (Just In Time Compiler) analyze/understand the similar functionality byte code, optimize it and convert into machine code. Here similar functionality code converted by which it improves the time of compilation.

Additional Details of JVM

JVM is platform independent. JVM is a specification that provides runtime environment in which byte code will be executed. Many companies provide implementation of JVM, but Oracle HotSpot is most popular one.

 

Difference between JRE JDK JVM

To summarize, JRE is used to only to execute the program, JDK is used to code and execute the program and JVM is used to convert the convert bytecode to machine code and executes it. JVM is the subsystem of JRE. JRE is the subsystem of JDK.

 

References

JDK Architecture

 

Angular Tutorial – Getting Started – Setting Up and Creating a new Project

To work in angular project first we have to install nodejs, an editor and an angularcli. In this tutorial we will see how to install all the things which we want to develop angular project and also we will see how to create an angular project. Angular tutorial setting up – Create new project – node js and angular cli

Getting Started – Setting Up.

Install node js:

Visit: https://nodejs.org/en/ and download recommended or latest version and do regular process to install a software

Once installed, open Command Prompt (cmd) and check the version of node js

  • node -v
    • which will display the installed version of node v10.15.3 (it might for you)
  • npm -v
    • which tell the package manager version
How to check node js version

How to check node js version

Install Editor/IDE:

I recommend visual studio code since it provide a support for TypeScript, visit https://code.visualstudio.com/  download latest version and install it.

Install Angular CLI:

Visit https://cli.angular.io/ to get the command to install angular ci

  • npm install -g @angular/cli which will install angular cli in the current directory.

But to install globally issue the following command

  • npm install -g @angular/cli -g
  • ng –version
    • Which will tell the angular cli version
How to Check Angular Cli Version

How to Check Angular Cli Version

 

Creating the angular project

To create a new angular project issue the command and open the project in the visual studio editor.

  • ng new first-project
    • Here first-project is the name of the project.

How to run the project.

Issue the following command to run the project in browser.

  • ng serve
    • This will create a local server and deploy our project into it.
  • To run the project, open the browser and hit localhost:4200