Introduction of Java
While you are on a journey to learn java now, let’s first get introduced to Java. Java is one of the most popular and widely used programming languages in the world. The thing is that when you learn java, you open pathways to getting into many different sectors where java is used, like –
- Game development
- Android application development
- desktop GUI application development
- Cloud-based applications
and a lot more…
There are many reasons why would you want to learn Java, and each reason would be of great benefit. With this, let’s dive into the details gradually. But first, we need to get familiar with very basic details like some history, some important terminologies, and some other basic information before we really dive into the programming concepts.
Java is a high-level, object-oriented, platform-independent programming language. It was developed by James gosling along with his team at Sun Microsystems in 1995. Now, java is owned by oracle. Originally java was called Oak, but later it got renamed Java. We are going to understand many concepts related to Java from scratch.
Ok… Now, let’s come back and try to understand some important things before we dive into the coding part, this might seem a bit theoretical, but the thing is that it will be of great benefit to us while we understand how is the thing working.
There are some other programming languages before java like the C language or C++, then what makes java stand apart and become one of the most popular programming languages in the world? Later on, we are going to have a brief discussion on the features of the java programming language, which can certainly demonstrate why is java so popular and widely used programming language.
Well, java is a very flexible language, which means that once you know much about java, you can work in cloud computing, android app development, developing games, distributed applications, and a lot more.
Also, as mentioned earlier, java is a platform-independent language. Let’s understand what that means. When it comes to some compiled languages like C or C++, which are platform-dependent, if you compile some C/C++ program (called the source code. Source code is the code that we write) on a windows computer, it will execute only on a windows computer.
The same thing is for mac. You can relate this with the thing that we have some .exe file after we compile the C program or the C++ program in a windows machine, which cannot run into a mac straightaway (It’s a different thing if you are using wine for doing this. Don’t worry if you don’t know about wine).
But with java, first, the source code that we write is converted into something called byte-code. The source code we write has an extension of .java, and the byte-code has an extension of .class
Now, this byte-code (.class file) makes Java a platform-independent language, because you can run a byte-code on any machine with the help of something called JVM or Java Virtual Machine.
This means that if I write some java code (again a source code) in a windows machine and convert it into a byte code in my windows computer itself, I can go and run that byte code on any other OS, like Mac, or on any other platform.
This is referred to as platform-independent. The bytecode is going to be executed by every machine with the help of JVM. So, this way, Java becomes a Write Once, Run Anywhere language,
So, now we have understood how Java is a platform-independent language, and this is again explaining how a java source code is converted to a machine code. The java code is first compiled into a byte-code, which is later interpreted into a machine code. So, we can also say that java is a compiled as well as an interpreted language. If this feels a bit confusing, please refer to the below diagram which is a straightforward explanation of conversion from java source code to machine code. The basic idea is that the source code will be converted (compiled) to byte code, and then the byte code will be converted(interpreted) to machine code.
To understand the above simple diagram, let’s recall what we have discussed previously. The main idea is that we are writing a java source code (.java file). Now, that source code is being converted to a byte-code(.class file). Now, we can run this byte-code with the help of JVM, and this makes it platform-independent, which means that if you have the byte-code from windows, you can run it in mac as well.
But remember, that the JDK that we are going to see later, which is just a toolkit that we require for writing java source codes, is not platform-independent. You have to download it separately for Windows, Mac, etc.
Now, when we know how are things working, we got to see some terms here, like JVM or java virtual machine. Let’s systematically understand what this actually is. For that, we need to understand something called a Java Development Kit, which is basically just the essential things that are needed to write a java program.
When we get the Java development kit, it comes with the Java Runtime Environment, and the Java Virtual machine. We will understand all these terms gradually so you don’t have to worry.