This article is a beginner’s introduction to the Java programming language. Here, we are going to study what java actually is. Obviously, we know it is a programming language but how is it different from other languages? We are going to learn how java works, its applications in the real world, the history of java and how it will help us if we study java. So let’s get started.
What is Java?
Java is an object-oriented, cross-platform, multipurpose programming language. Too many big terms? Don’t worry, we are going to cover it all in the following section of the article. It is a simple programming language and writing, compiling and debugging is easy in java. It also helps to create modular and reusable code.
History of Java
Java was developed by James Gosling along with Mike Sheridan, and Patrick Naughton from Sun Microsystems in 1991. It has now been acquired by the Oracle Corporation. The first publicly available version of Java was released in 1995 with the purpose of becoming a machine-independent web technology. Since then, it has acquired a prominent place in the world of computer programming.
Features of Java
There are many key features of Java that make it unique in the world of programming languages and different from them in many aspects. They are:
- Platform independent – Java is a platform-independent language, which means that it can be run on any operating system, including Windows, Linux, macOS, etc, which is why it is known to follow the principle “Write Once, Run Anywhere”. Since it can be run on any platform, it is known as cross-platform. Once the Java source code has been compiled to bytecode, those files can be used on any Java-supported platform and executed without modification, unlike other languages, which requires compiling the machine code each time it is used on a different platform.
- Object-oriented – Java is an object-oriented programming language that makes it modular and organized. Object-oriented programming is a way of organizing programs as a collection of objects, each of which is an instance of a class. We will learn about object-oriented concepts in greater detail in later articles. Java focuses on objects rather than procedures. Except for the primitive data types, all elements in Java are objects and can be easily extended for better handling. Java is not a purely object-oriented programming language since it also allows primitive data types like integer, float, double, etc, about which we will learn in later articles.
- Simple – Java is a very simple and efficient language that makes it easy to learn and use. It does not have complex features like Operator overloading, multiple inheritance, pointers, etc which make it much simpler than other languages.
- Secure – Java also enables the development of a virus-free and tamper-free system. Since we do not have pointers in java and cannot access out-of-bound arrays, several security flaws like stack corruption and buffer overflow are impossible to exploit in java. The Bytecode Verifier inspects fragments of code for illegal code that can bypass access which adds to the security.
- Portable – Java uses a Java Virtual Machine (JVM) as abstraction and does not access the operating system directly. This makes java highly portable. A Java program can run unmodified on any platform.
- Robust – Java is a very reliable language which means that it emphasizes early checking and elimination of errors (especially compile-time errors and runtime errors) which makes it better in performance than other programming languages. The features like no pointers, automatic memory management, exception handling make Java robust.
- High-performance – Java uses a Just-In-Time (JIT) approach for compiling and executing Java code where execution and compilation are done at the same time making Java very fast and powerful.
- Dynamic – Java has been designed to adapt to evolving environments which make it dynamic in nature. It is able to carry an extensive amount of runtime information that can be used to verify and resolve problems at runtime.
- Multi-functional – Java can produce many applications from simple command-line programs to complex applets and more. Thus Java is known to be multifunctional.
- Multi-threading – Java supports multi-threading which means that it is possible to write programs that can perform many tasks simultaneously. This is an important feature which enables maximum utilization of the CPU and enables developers to construct interactive applications that run smoothly.
- Automatic Memory Management – Java automatically manages the allocation and deallocation of memory for creating new objects. In simple words, when we create new objects, we do not need to explicitly allot new memory to it and Java has a garbage collector that automatically deletes the memory occupied by the object when the program ends.
- Interpreted and compiled language – Java is both an interpreted and compiled language since the java source code is compiled to the bytecode and the bytecode is interpreted by the JVM. We will learn about it further in the below section.
- Distributed – Java is designed in a way that java programs can be distributed to more than one system which is connected to each other over the internet.
- Open-source and free – Java is open-source which means that its source code is freely available on the internet for public access and anyone can see and modify it.
- Community support – Java has huge community support with millions of developers and supporters across the globe.
How does it work?
Before we start with the language itself, let’s get familiar with how a java code gets compiled and executed in a system. There are a few terminologies which are important to understand the complete working of a java program in order to get an in-depth knowledge of the language.
Java-Virtual-Machine (JVM) is the reason why Java is called platform independent. It is a software implementation of a computer that executes programs like a real machine. After the compilation, the bytecode is executed by the JVM which is different for different operating systems. The JVM interprets the bytecode and produces an output which will be the same across all operating systems. For example, a bytecode created in a Linux system can be executed in a windows system and vice versa and the output in both cases will be the same. The JVM has the tasks of loading, verifying executing code, and providing a run-time environment. This provides for the cross-platform feature of the Java language. JVM is also platform-dependent.
The Java-Runtime-Environment (JRE) helps in executing a compiled file. The JRE is a collection of tools that together allow the development of applications. JRE includes JVM, browser plug-ins, and applets support. With the JRE in our system, we would be able to run a java program but not compile it. For compilation, we need the JDK. If someone only needs to run a program without wanting to compile it, then a JRE is sufficient. JRE is platform-dependent and provides a run-time environment.
The Java-Development-Kit (JDK) provides an environment to develop, build and execute a java program. Unlike other programming languages, java is platform independent which allows a compiled file to be executed on all operating systems. The JDK is a software that contains various tools like JavaDoc, Java Debugger, Java Interpreter, etc, which we would be needing for the compilation of a java program. The compilation is the process of converting human-understandable source code (which is a .java file) to machine understandable code. The compilation of a java program is done by the javac compiler which is the primary compiler included in the JDK. It takes a java program as input and produces the bytecode as output. The bytecode is stored by the compiler as a .class file.
Applications of Java
Java is also popularly known as the “King of programming languages”. It is being used in multiple fields of the world including our day-to-day activities of playing games or using our android smartphones. The language has become the backbone of millions of applications across multiple platforms including Windows, Mac, Unix, Android-based mobiles, embedded systems and enterprise solutions. The applications of Java can be seen in various domains. A few of them are mentioned below:
- Mobile Applications (especially android apps)
- Web Applications
- Web Servers and Application Servers
- Game Development
- Embedded systems
- Desktop GUI Applications
- Cloud-based Applications
- Enterprise Applications
- Scientific Applications
- Distributed Applications
- Big-Data Technologies
- Artificial Intelligence
Java is one of the most popular languages in the market right now. It is platform-independent, simple and multifunctional language and is open-source and distributed. We have learned about the history of java and how java works, right from when it is written to how the output is generated, and the various software included in the process. In short, the JDK contains the javac compiler which converts the source code to bytecode. The bytecode is then interpreted and executed by the JVM to generate the output.
We have also learned about the various applications of java in multiple domains. Java is proving it to be one of the fastest emerging and extensively applied programming languages. The current number of Java developers have been estimated to be over 9 million worldwide. There has been a rise in the demand for programmers who have in-depth knowledge and understanding of Java setting forth even more job opportunities in the fast pacing technology industry.
I hope you all have become somewhat familiar with the Java language. In the next article, we will be installing the software we require and writing our first java program.
Kuldeep is the founder and lead author of ArtOfTesting. He is skilled in test automation, performance testing, big data, and CI-CD. He brings his decade of experience to his current role where he is dedicated to educating the QA professionals. You can connect with him on LinkedIn.