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

Java Program to find the sum of the Largest Forward Diagonal

in this tutorial, we will write a java program to find the sum of the Largest Forward Diagonal in an Arraylist (matrix). Java Program to …

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a number using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

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 …