Basic Syntax and Compilation of java programs

Fetching Comments ...
Basic Syntax and Compilation of java programs

Basic Syntax of java programs :

  • 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.

Java Identifiers:

  1. All Identifier should start with (A-Z, a-z $ and _ ), no other symbol allowed.
  2. We can use only 1 symbol, after that we need to use combination of character. (example _hello, $test)
  3. we cannot use keyword as Identifier. (for example we cannot use ‘class’ as identifier).
  4. Identifiers are case sensitive

Java Modifiers:

  1. Access Modifiers (default, public, private, protected)
  2. Non-access modifier (final, static)

Java Variables:

We would see following type of variables in Java:

  1. Local Variables
  2. Class Variables (Static Variables)
  3. Instance Variables (Non-static variables)

Compiling and Executing Code :

  • 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 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 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).


public class First {

	public static void main(String[] args) {
		System.out.println("Welcome to");

Share This:

Featured Posts

post preview
post preview
post preview
post preview
post preview


Related Posts

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.