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

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …
Read More

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More