How Really Java is Platform Independent

Probably the first thing that is written anywhere about java is that it is a platform independent language. Have you ever wondered that what is meant by platform independent? How java is platform independent? Why other programming languages lack this portability? The purpose of this article is to understand you about all these terminologies.

Before going into detail, first you have to understand that what is a platform?

What Is A Platform? 

A platform consists of computer hardware and Operating system. For example, a PC with Windows 8.

Platform dependent means the program can be executed only on a specific platform. Many programs like Skype can be used on multiple operating systems like Windows or OS X. but notice that this software has different versions for different operating systems, which means that Skype is not actually platform independent. Basically the programs written in dependent languages require some code changes to run on other platforms. C++ is an example of platform dependent programming language.

Platform independent means the program that we have developed can run on any platform. The code remains the same irrespective of the platform involved. Java is an example of platform independent programming language. One Program written in Java can run on Windows or OS X without any modification.

How Java Is Platform Independent:

The reason why java is platform independent is that it is a structured differently from other programming languages. In fact, Java is both compiler and interpreter based language. In other programming languages like C/C++, the source code you write must be compiled in machine code to execute because computers can only execute machine code. The compiler, which compiles the code, uses the functions of the current operating system to compile the source code. This compiled program just runs on that operating system as its code was translated interacting the functions of specific operating system. So, the program becomes platform dependent.

On the other hand, the java compiler compiles the source code and produces an independent intermediate code called byte code instead of direct machine code. This code is platform independent because java compiler doesn’t interact with the local platform while generating byte code. In fact, this code is represented in hexa-decimal format which is same for every platform. You can say that byte code generated on Windows is same as the byte code generated on Linux for the same java code.

Now this code must be converted into machine code to be executed by a computer, here JVM comes. JVM stands for JAVA Virtual Machine and it is available as a part of JDK & JRE (described later) for different operating systems. The JVM translates the byte code into machine code which can be executed by a computer. This JVM works like a virtual machine on which platform independent byte code runs and this machine produces a platform dependent machine code. No matter, what physical platform you are using, the part where JVM interprets byte code is guaranteed to work in the same way. Since all the JVMs work exactly the same, the same code works exactly the same way without recompiling. So the same code works on all operating systems without modification.

How Java Is Platform Independent, when it requires JVM:

In true sense, Java is NOT PLATFORM INDEPENDENT programming language as it requires JVM to run upon. But it works like a platform independent language with pre-installed JRE/JDK on the computer.

JVM comes as a part of JDK and JRE. JDK stands for Java Development Kit which is used to write, compile, debug and execute Java code. While JRE stands for Java Runtime Environment which is required to run java programs. So, every computer must be preloaded with JRE to run any java application.

Mostly computer manufacturers sell their computers with pre-installed JRE. Now, these computers are familiar with programs written in Java language. So, they run/execute the program without demanding a single file.  But, if computer manufacturers have not added JRE in their systems then JRE should be installed manually.

But, wait a minute, think that you want to run a program written in C/C++ (platform dependent code) on another platform then what you would do? Surely you will make some changes in the core code of program. This could be a long and complicated process and you also should have knowledge of the construction of target platform. But, the java program can run on any platform without modifying the code. Just, JVM is required to run the code on any platform exists. Your byte code is same for every platform and JVM converts it into machine code according to local platform. This machine code is then executed by computer.

About Author:
Kamal Choudhary is a tech geek who writes about c++ programming tutorials on C++ Beginner. He is a student of computer science in University of Gujrat, pakistan. He loves to write about computer programming. You can find his full bio here. Follow him on twitter @ikamalchoudhary

How To Make a Age Calculator in Java

This is a age calculator made in java, it's a console application by the way :)

source :

 import java.util.GregorianCalendar;
import java.util.Scanner;
import java.util.InputMismatchException;

public class age_calculator {

    public static void main(String[] args) {
        int day = 0;
        int month = 0;
        int year = 0;
        Scanner scan = new Scanner(;
         System.out.print("Day: ");
         day = scan.nextInt();
         System.out.print("Month: ");
         month = scan.nextInt();
         System.out.print("Year: ");
         year = scan.nextInt();
  catch(InputMismatchException e){
   System.out.println("Error: You entered an invalid number");
        System.out.println("\nYou are " + getAge(day,month,year) + " years old");

    public static int getAge(int day, int month, int year){
  final int ERROR = -1;

        //initialize GregorianCalendar with current date
        GregorianCalendar cal = new GregorianCalendar();
        //constant holds current day
        final int CDAY = cal.get(GregorianCalendar.DAY_OF_MONTH);
        //constant hold current month
        final int CMONTH = cal.get(GregorianCalendar.MONTH) + 1;
        //constant to hold current year
        final int CYEAR = cal.get(GregorianCalendar.YEAR);
        //check if current day of the month is greater then birth day
        if (month == CMONTH){
            if(CDAY >= day)
                return CYEAR - year;
   if(CDAY < day)
    return CYEAR - year - 1;
        //check if birth month is less then current month
        else if(month < CMONTH)
            return CYEAR - year;
        //subtract 1 from the age because  the current day in the month is less then birth date
         return CYEAR - year - 1;
  return ERROR;


screenshot :
 How To Make a Age Calculator in Java
 Hope it helped you :)

How To Execute Shell Commands and Print Results in Java

Java Command Shell,bash script -eq, bash script -ne, best way to learn java, execute shell commands, execute shell commands java, get runtime, host runtime, java, java learning, oracle sql plsql, print results, tutorial,
There are many ways to execute shell commands and print results in java I guess, the famous and the most used way is Runtime.getRuntime().exec you can find a good explanation for that from here. Coming to the point i am using the same way but little different! I use BufferedReader,InputStreamReader for simplicity and I can't make it much advanced. On the main event I have created a String where you put your command with the second event it executes the command and prints the result before I start I would like to give some credits to luismcosta.

How To Make A Addition Calculator In Java Using JOption

How To Make A Addition Calculator In Java Using JOption
Okay guys today i will be teaching you how to make a simple addition calculator using Joption in java, I saw someone wrote some codes to calculate addition also it uses Java Scanner. This is that program .
import java.util.Scanner;

class basic_cal
  public static void main(String args[])
   Scanner shim = new Scanner(;
   double first_number,second_number,answer;
   System.out.println("Enter First Number : ");
   first_number = shim.nextDouble();
   System.out.println("Enter Second Number : ");
   second_number = shim.nextDouble();
   answer = first_number + second_number;
   System.out.println("Answer : " + answer);
Okay now i saw that and got an idea to make the same thing with Joption , Joption is like the messagebox we have in c# and ok , this is the program i wrote :