Java – Basic Syntax2 min read

The syntax of the Java programming language is the set of rules for writing the java programs and defining its interpretation. Java program is the collection of classes and objects that communicate with each other via. method. It is the program structure.

There are certain features that are omitted such as operator overloading or unsigned integer types, also there are no global functions or variables, but there are data members which are regarded as global variables.

Before starting programs, it is very important to remember the following points.

1. Case Sensitivity:

Java is case sensitive, which means identifier Hello, heLlO and hello, all have a different meaning in Java.

2. Class Names:

Class names should always begin with Upper Case. If more than one word is used to form the name of the class, then each inner word’s first letter should be in Upper Case.

Example: class MyFirstJavaLesson, class StudentsDetails, etc.

3. Method Names:

All method names should begin with a Lower Case letter. If more than one word is used to form the name of the method, then each inner word’s first letter should be in Upper Case.

Example: public void myFirstMethod(), public void myStudentDetails() etc.

Note: public static void main(String args[]):
All Java program processing begins from the main() method which is a mandatory part of every Java program.

4. Program File Name:

The name of the program file should always match the class name. While saving the file, it should be saved with the class name and append ‘.java’ to the end of the name. Note that if it doesn’t match with the class name then the program will not work.

Example: consider that ‘MyFirstJavaCode’ is the class name. Then the file should be saved with the name ‘MyFirstJavaProgram.java’.

JAVA Basic Example to print “Hello World”:

This the very basic way to write a program. The program below print “Hello World”.

This shows the format for writing java code in code editor. This is the basic one. To learn more on how to write java with function and multiple classes, navigate through our website and learn more.


MORE

Implement Insertion sort Program in C

In this tutorial, we will learn and write a C program to implement insertion sort. Before that you may go through the following topics in …
Read More

C Program for implementation of Selection sort

In this tutorial, we will learn and write a C program to implement selection sort using function. Before that you may go through the following …
Read More

C Program to Delete a Particular element from an Array

In this tutorial, we will write a C program to delete an element in an array by specifying the value. Before that, you should have …
Read More

C Program to sort a String in Ascending order

In this tutorial, we will write a c program to sort a string array in ascending order. Before that, you may go through the following …
Read More

C Program to find Maximum occurring Character in a String

In this tutorial, we will write a program in C to find the maximum occurring character in a string. Before that, you may go through …
Read More

Keith Number Program in C

In this tutorial, we will write a Keith number in C. It is one of the most asked questions in an interview. Before that, you …
Read More