Head First Java Chapter 1 — Breaking the Surface

Yasuni Chamodya
4 min readJul 16, 2022

--

Java is an object-oriented, high-level, class-based, reliable, and secure programming language.

James Gosling is credited with developing Java. He did it in 1995 while working at Sun Microsystems, now it is part of Oracle Corporation. Those days, Java was developed for interactive television, but they understood Java was more advanced than the digital cable industry. Java 1.02 is the initial release of Java. it was included 250 classes and was quite slow and with including lots of bugs, but Applets were the big things. Java 1.1 is the second release of Java and was published with 500 classes. It was a little bit quicker, more powerful, and user-friendly than its previous one and quickly gained enormous popularity. Then release Java 2 with 2300 classes and all versions between 1.2 and 1.4 are referred to be Java 2. Additionally, there are three different versions of Java 2: Micro Edition (J2ME), Standard Edition (J2SE), and Enterprise Edition (J2EE). And Java 2 is powerful and a lot faster than earlier versions. Then, it became the language of choice for new enterprise and mobile application programming. Then Java 5 was released which consisted of 3000 classes and was very easy to use for development and it was very powerful than previous releases.

A very brief history of Java

Let’s just take a look at how Java works

Java workflow

In the first step, the Developer creates a source document and saves it as a .java file (Ex: A.java).

Next in the second step, the Developer run their source document through a source code compiler. For that source code to compile developer run the javac <file_name.java> (Ex: javac A.java) command. During that compilation, which checks for errors and won’t let the developer compile until it’s satisfied that everything will run correctly.

Next in the third step, after successfully compiling the .java file, which creates a new document as .class file. That files are coded into bytecode. Any device capable of running Java will be able to interpret/translate this file into something it can run. The compiled bytecode is platform-independent.

Lastly in the fourth step, The Java Virtual Machine (JVM) on our electronic device. that reads and executes the bytecode (We just use the “java <class-name>” command for executing inside the device) And a virtual Java machine is running inside of electrical devices where you run Java code. If we execute the command “java class-name>,” the JVM searches for the main method with the exact same appearance as:

Main method

Code structure in Java

Code structure in Java

A source code file (with the .java extension) holds one class definition. The class represents a piece of your program, although a very tiny application might need just a single class. The class must go within a pair of curly braces.

A class has one or more methods. In the Dog class, the bark method will hold instructions for how the Dog should bark. Your methods must be declared inside a class (in other words, within the curly braces of the class).

Within the curly braces of a method, write your instructions for how that method should be performed. Method code is basically a set of statements, and for now, you can think of a method kind of like a function or procedure.

Anatomy of a Class

You can see the anatomy of a class below. In this example, the class name is “MyFirstApp”, and this class uses public access modifier. However, every class should start with curly braces “{” as well as end with the curly braces “}” as below. Inside the class, we have a method called the main () method. But required to think every class has not the main method. One application should have one main () method. And Methods are also required to start and end with curly braces “{}”. When running the program JVM first starts to run the main () method no matter how many classes are there. Moreover, inside the main () method we can do declaring, assignments, method calls, looping, and branching but this example only demonstrates printing a text message in the command line.

Anatomy of a Class

I hope you learned something valuable from this article and let’s meet with another one.

Wish you happy learning!

--

--