Java Basic Syntax And Rules, Java Identifier With Rules

  In this section, we will learn about java's basic syntax and rules. As earlier tutorials, we are familiar with Java data types and variables, as we know that Java uses Object-Oriented Concepts to make it more robust and java is a collection of objects also known as a package.

Java Basic Syntax Key Points

  1. Java is a case-sensitive programming language.
  2. The first letter of the class name in java should be Upper Case Letter, if more than one word then starting of each word should be in upper case.
  3. In java, the method name should always start with Lower Case Letter, and also can say that it should be in Camel Case.
  4. The program file name should be exactly the same as the class name.
  5. Java has a mandatory method called the main() method, it is an initial point of the program (Driver Function).
  6. At least one class should be defined as public in a package.

Java Basic Syntax And Rules

Java provides a more secure way to build an application, it needs necessary to about java rules by which the developer can build a secure application. There are following some rules given:

Java Case Sensitive

Java is a case-sensitive programming language which means identifier var and Var having a two different meaning as shown in example:

																
public class CaseSensitive{

     public static void main(String []args){
         int var = 100;
         int Var = 200;
        System.out.println("var :"+var+", Var : "+Var);
     }
}													
													
												

Output :

														
var :100, Var : 200													
													
												

Java Class Name

In Java, the first letter of a word of the class name should be Case Sensitive as per java rules. For Example:

																
public class CodeNaive{
	/***
	 ....................
	 ....your statement...
	 ....................
	**/
}													
													
												

Java Method Name

To make it easier to understand, it needs to create the first letter of function should be Lower Case Letter, also called Came Case Letter.

																
public class CodeNaive{
			
	public void codenaiveFunction(){
		 /*** your statement  **/
	}
}													
													
												

Java Main Function

To start your program java's compiler call the main() function which is the initial point of the program. Get details description of main() function.

																
public class CodeNaive{
			
	public static void main(String [] args){
		 /*** your statement  **/
	}
}													
													
												

Java Program File Name

The program file should be the same as the class name that means if the class name is CodeNaive then the file name should be written as CodeNaive.java.

																
public class CodeNaive{
			
	public static void main(String [] args){
		 /*** your statement  **/
	}
}													
													
												

Java Class As Public

At least one class should be public in the package. For Example:

													
package website;
class code{
	
}													
public class CodeNaive{
			
	
}													
													
												

Java Identifier Rules

Identifiers are used to give a name to things in java, such as classes, methods, and variables. The identifier has several rules given below:

  1. Identifiers can be either UpperCase and lowercase letters.
  2. Java keyword cannot be used as an identifier, For Example, int int.
  3. All Identifiers start with letters A-Z, a-z, and dollar-signs characters (must not be used for general purpose).
  4. The identifier is case-sensitive.
  5. An identifier cannot be created with some special character such as <,>,',", etc.
  6. Example of Identifier which can be used: $book,books8506, Books_code, books, books, etc.
  7. Example of Identifier which cannot be used: 9books, -books, Books/program, books-code, etc.

Example of Valid Identifier in java

The following program implements the valid identifier in the Java Program:

																
public class CodeNaive{
	
	public void  myCustoFunction(){
		
		/** Valid Identifier **/
		int $var;
		int varBooks;
		int books;
		int books_code;
		int books81;
	}
	public static void main(String []args){
		 /*** your statement  **/
	}
}													
													
												
Announcement
Advertisement