Chapter 1: Introduction to Java
Chapter 1: Introduction to Java
Welcome to Java programming and thank you so much for choosing my book among the large selection of Java books available.
Whether you are a seasoned programmer or a complete novice, this book is written to help you learn Java programming fast. Topics are carefully selected to give you a broad exposure to the fundamental concepts of Java while not overwhelming you with information overload. While it is not possible to cover every single Java concept in this book, rest assured that by the end of the book, you should have no problem writing your own Java programs. In fact, we will be coding a program together as part of the project at the end of the book. Ready to start?
Let’s first answer a few questions:
1.1 What is Java?
Java is an object-oriented programming language developed by James Gosling at Sun Microsystems, which has since been acquired by Oracle Corporation. It was released in 1995 and is currently one of the most popular programming languages in use. It can be used to develop applications for a large variety of environments, such as applications for desktop, web and even mobile devices. One of the main features of Java is that it is platform independent. This means that a program written in Java can be executed on any operating system (such as Windows, Mac or Linux).
Like all modern programming languages, Java code resembles the English language which computers are unable to understand. Therefore, Java code has to be converted into machine code through a process known as compilation. Every computer platform has its own machine code instruction set. Hence, machine code that is compiled for one platform will not work on another platform. Most programming languages (like C and C++) compile written code into machine code directly. As a result, this machine code can only be run on the specific platform that the code is compiled for.
Java does it a little differently.
Instead of compiling into machine code directly, Java compiles all written code into bytecode first. Bytecode is platform independent. That is, there is no difference between the bytecode for Windows, Mac or Linux.
When a user wants to run a Java program, a program inside the user’s computer (known as the Java Virtual Machine or JVM) converts this bytecode into machine code for the specific platform that the user uses.
The advantage of using this two-step compilation process is that it allows Java code to be run on all platforms as long as the computer running the Java program has JVM installed. JVM is free to download and there are different versions for different computer platforms. We’ll learn how to install JVM in the next chapter.
1.2 Why Learn Java?
There are a lot of reasons why one should learn Java. Let’s look at some of the reasons below.
Firstly, Java is currently one of the most popular programming languages in use. According to Oracle, 3 billion devices run Java. Furthermore, Android apps are also developed using Java. With the growing demand for mobile apps, it is safe to say that Java is an essential language to learn if you are interested in becoming a programmer.
Next, Java has syntax and features that resemble other programming languages like C and C++. If you have any prior programming experience, you will find learning Java a breeze. Even if you are totally new to programming, you can rest assured that Java is designed to be a relatively easy language to learn. Most programmers find it easier to learn Java than say, C or C++.
Java is also designed to be platform independent. As mentioned earlier, Java code is compiled into bytecode first, which can be run on any machine that has the Java Virtual Machine. Hence with Java, you can write the code once and run it anywhere you want.
Next, Java is an object-oriented programming (OOP) language. Objectoriented programming is an approach to programming that breaks a programming problem into objects that interact with each other. We’ll be looking at various object-oriented programming concepts in this book. Once you master Java, you will be familiar with these concepts. This will make it easier for you to master other object-oriented programming languages in future.
Convinced that Java is a great language to learn? Let’s move on.