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.
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.
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”.
public class JavaBasic //JavaProgram is the class name
public static void main(String args) //main() method
System.out.println("Hello World"); //Prints 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.
String Pattern Programs in C
Java Program to Find pair of Integers in Array whose sum is given Number
Program to Print Diamond Alphabet Patterns in C
Half Diamond Pattern in C using Alphabets
Half Pyramid of Alphabets in C