Java Syntax

In computer programming the syntax is a set of rules which define how a program is written and interpreted. The java syntax is similar to C++.

Java Hello World

public class JavaHelloWorld {

/* This program will print Java Hello World on screen */

public static void main(String []args) {

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



Save this program in file.

In command prompt go to the directory where this file is located and type ‘javac’

It will compile your program. after that type ‘java JavaHelloWorld’ to see the output.
Code blocks

In java braces { and } are used for code blocks. Body of a method, if statement, loops etc are written inside these braces.

void myFun() {

int a;

a = 5;


Java Comments

Comments are ignored in program execution. Comments are also used by javadoc tool to generate automatic documentations. In java we can add comments in following ways.

// This is a single line comment

/* multi-line comment.

…. */

* This is a javadoc comment.
* @author Allen Kooper
* @version 1.0.1