Java Basic Syntax And Rules, Java Identifier With Rules
Java Basic Syntax Key Points
- Java is a case-sensitive programming language.
- 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.
- In java, the method name should always start with Lower Case Letter, and also can say that it should be in Camel Case.
- The program file name should be exactly the same as the class name.
- Java has a mandatory method called the main() method, it is an initial point of the program (Driver Function).
- At least one class should be defined as public in a package.
Table of Contents
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:
- Identifiers can be either UpperCase and lowercase letters.
- Java keyword cannot be used as an identifier, For Example, int int.
- All Identifiers start with letters A-Z, a-z, and dollar-signs characters (must not be used for general purpose).
- The identifier is case-sensitive.
- An identifier cannot be created with some special character such as <,>,’,”, etc.
- Example of Identifier which can be used: $book,books8506, Books_code, books, books, etc.
- Example of Identifier which cannot be used: 9books, -books, Books/program, books-code, etc.
Beginning with JDK 9, the underscore cannot be used by itself as an identifier
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 **/
}
}
Leave a Reply