Loading, please wait...

A to Z Full Forms and Acronyms

Getting started with Java – Hello World

May 09, 2021 Java, Shibam Dhar, 1944 Views
Java is a programming language like another language that helps in writing instructions for computers. They are useful to write precise useful instructions for a computer so that the computer can run the application with proper coordination. This then can be accessed by anyone to carry out the tasks.

Getting started with Java – Hello World

Java is a programming language like another language that helps in writing instructions for computers. They are useful to write precise useful instructions for a computer so that the computer can run the application with proper coordination. This then can be accessed by anyone to carry out the tasks.

Java is one of the most popular languages because of its properties like being a simple, fast, and robust coding language. There are many other interesting reasons and feature of Java which makes it loveable. You can check about it more on Why to choose Java?  The very basics of Java are much quite similar to other programming languages. This includes printing of texts, commenting code or texts, putting up methods and classes, and compiling it.

NOTE: In Java, everything is class-based.

Basics of Java File.

public class HelloYou {

  public static void main(String[] args) {

    

  }

}

In the above code, there are publicstatic, and void as a syntax for the writing of the main method. Each of them serves its respective functions. String[] args is a placeholder for information we want to pass into our program. 

Print Line

To print something to console we follow a particular syntax which is:

System.out.println();

  • System is a class from the core library provided by Java
  • out is an object that controls the output
  • println() is a method associated with that object that receives a single argument

Inside the brackets of println(), we can put strings, characters, numbers, or pass variables.

For example:

System.out.println(“Hello World”);

//This will print Hello World to the console.

Commenting Code

Programming languages have syntax to comment on some code or text. This commented code has no efficient value in the result of the codded application but still, it holds significant value for the code writer and the code reader.

Commented codes or texts act as notes for the readers to get hold of the things which are getting done in the sets of instructions.

There are different ways to put comments.

When a comment is short, we use- //

// Hi I am a single-line comment.

When comments are long, we use the multi-line syntax: /* and */.

/*Hi

This is

A

Multi-line

Comment */

Whitespaces and Semicolons

This Java language does not get affected by white spaces or blank spaces but still, it should be used while writing code because humans use whitespace to read code without difficulty.

 

We should write code that is easy for other people to read. Those people can be co-workers, friends, or even yourself!

For example:

System.out.println(“Hello World”);System.out.println(“Hello India”);System.out.println(“Hello Delhi”);

and

 

System.out.println(“Hello World”);

System.out.println(“Hello India”);

System.out.println(“Hello Delhi”);

 

Both of the above codes will display the same result but still, the second one is followed because it is easy to understand and interpret by humans.

Whereas in the case of semi-colons, they do get interpret in Java. They are used to state the end of the particular line or instruction. In the case of {} braces we can see that there are no semi-colons, that is because it states the scope of the particular class or methods, this no semi-colons are required for this.

For example:

public class HelloYou {

  public static void main(String[] args) {


    

  }

}

Compilation and Catching Errors

We have discussed in the beginning about Java being a complied programming language which means that initially, we write code in a Java file having an extension of .java then it is transformed into .class or byte codes which is then compiled by the Java Virtual Machine.

During this compilation process, the machine searched for mistakes or errors and detects them for the coder.

The Java compiler runs a series of checks while it transforms the code. Code that does not pass these checks will not be compiled.

 

A to Z Full Forms and Acronyms

Related Article