Java Syntax

Case Sensitivity

Java is a case sensitive language, which means that the identifier Hello, hello, HeLLo, hEllO, helLo, HELLO. All are different in Java.

Class Names

For all class names, the first letter should be in Uppercase
If several words are used to form a name of the class, each inner word’s first letter should be in Upper Case.
Examples: class MyJavaProgram, class MyThirdJavaProgram, class StudentRecords etc.

Method Names

All the method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each first letter of inner word should be in Upper Case
Example: public void employeeRecords(), public void myMethodName(), public void employeeNumber() etc.

Program File Name

Name of a program file should exactly match the class name.
When saving the file, you should save it using the class name and add/append ‘.java’ to end of the name.
If file name and the class name do not match, your program will not compile.
Example: Think ‘MyFirstJavaProgram’ is the class name. Then the file should be saved as ‘’

public static void main(String args[])

Java program processing starts from the method main() which is a mandatory part of every Java program.

Following is Java’s simplest program, prints Hello World on the screen.

public class JavaProgram
public static void main(String args[])

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


Output:Hello Java

Comments in Java

There are the three types of comments defined by Java. You have already seen two: single-line and multiline comments. The third type is a documentation comment. This type of comment is used to produce an HTML file that documents your program. The documentation comment begins with /** and ends with */.

All characters available inside any comment are ignored by Java compiler. Her is an example.

public class MyProgram

This is a simple Java program.
It will print ‘Hello Java’ on the output screen
It is an example of multi-line comments or block comments.

public static void main(String args[])

// It is an example of single line comment
/* It is also an example of single line comment. */

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


Output:Hello Java

Whitespaces in Java

A line containing only whitespace, possibly with comment, is known as blank line, and Java compiler ignores it.

Leave a Reply

Your email address will not be published. Required fields are marked *