- Case Sensitive: Java is Case Sensitive, which means “abc” and “Abc” both are different identifiers.
- Class Name: First letter of Java Class’s name should be in UpperCase. and if there are two or more words in java Class then first letter of all words should be capital. (for example JavaClassExample).
- Method Name: Name of every method should start with small letter. if there are two or more words then first letter of inner words will be in Capital letter. (for example javaMethodExample()).
- Java File Name: The name of Java file name should match with Java Class name. if both are different then program will not run.
- main Method: Java program execute after main method (public static void main). If your class doesn’t have main method then your program will not run.
- All Identifier should start with (A-Z, a-z $ and _ ), no other symbol allowed.
- We can use only 1 symbol, after that we need to use combination of character. (example _hello, $test)
- we cannot use keyword as Identifier. (for example we cannot use ‘class’ as identifier).
- Identifiers are case sensitive
- Access Modifiers (default, public, private, protected)
- Non-access modifier (final, static)
We would see following type of variables in Java:
- Local Variables
- Class Variables (Static Variables)
- Instance Variables (Non-static variables)
- to write your code open Notepad.
- Now inside notepad type
- Now goto file menu and choose ”save as“.
- choose any directory where you want to save your java programs. and enter file name same as class name. in given example file name will be JavaExampleClass.java. and under save as type choose ”all files“.
- click on save button and your java file is now created.
- To compile this java file.
- Open ”Command Prompt” (in linux or mac open Terminal)
- change directory of Command Prompt/Terminal to path of your java file. (you can use cd command to change directory).
- When you are inside that java file directory type ”javac JavaExampleClass.java) and this command will compile your program and create new file with bytecode with same name. for example (JavaExampleClass.class).
- When above part is done you can run your program by typing “java JavaExampleClass”. and you will get output (Hello World).
Example:
public class First {
public static void main(String[] args) {
System.out.println("Welcome to LearnPainLess.com");
}
}
Subscribe to our newsletter!
We'll send you the best of our blog just once a month. We promise.