Basics Of Java For Beginners

Let me tell you the best of the basics of java…

It is important to know that java and all programming languages are require practice and re-read to get the best out of them.

In that regard…

You might need to read this page more than once for you to get the best out of it.

The Most Important Basics Of Java

Every Java program must start with a call to main. It is like the gate to a house. To enter the house, you first need to pass through the gate.

The name of a java source file is very important. Unlike other programming languages that give little or no importance to such names, just the code in it. It is important to know this as a java programmer.

The java source file must be saved with a .java extension. This denotes that the file is a java file.

Every java source code must contain at least a class. The name of the main class in the code must correspond with the name of the source file. That is one of the reasons why Java respects the name of the source file. You will later understand the reasons as you learn about the importance of a class in the java program.

It is also important to know that java is case-sensitive. So the name of the main class must be the same as the name of the source file and the two must be in the same case all through.

RELATED: Variables In Java

Class In Java In Brief 

Written as class Example {….}

The term class is a keyword in java and the Example in front of this example is the identifier of the class, also called the name of the class.

Anything that falls in between the to {} symbols is called the class definition.

All java programs are written inside a class definition. That is one of the features that make all java programs OOP enabled.

No matter how small a java program is, it will have an element of OOP and class is the first of these elements.

How Java Program Run 

To compile a java program, you will execute the java compiler called javac and specify the name of the java source file you want to run. Assuming the name of the source file is Example.java

 javac Example.java

The compiler will use the above command to create .class out of the source code. The class will contain the Bytecode of the program. So the output of a java compiler is not an executable code but rather a bytecode that only the Java Virtual Machine (JVM)can run.

Now to run the bytecode, you will launch the JVM using java launcher (java) followed by the name of the class.

java Example

So what the java compiler did at the first command was that it creates a .class file for all the classes in the source code. You don’t need to put .class extension to able to run the class file. The java launcher automatically recognizes that.

Comments In Java

This is another import basics of java.

Comments are use to explain a feature in the program, tell how the program works and use to describe the entire program to anyone that reads the source code. It is important to know that the java compiler doesn’t compile the comments and comments are only used to explain more info to the person reading the source file.

There are three types of comments

Multi-line comments

Multi-line comments are used to give a long description that covers multiple lines. It starts with /* and ends with */ anything that falls in between these two symbols will be neglected by the java compiler. It will only serve as a message to anyone who reads the code.

Single Line Comment

This one is used to give a single line description in the source code. It doesn’t extend more than one line. It starts with // and ends at the end of the line.

Documentation Comment

This is used to provide big lines of text.

Leave a Comment