Learn Pain Less

HomeOur TeamContact
Java
Basic Syntax and Compilation of java programs
Pawneshwer Gupta
Pawneshwer Gupta
February 02, 2015
1 min

Table Of Contents

01
Basic Syntax of java programs :
02
Java Identifiers:
03
Java Modifiers:
04
Java Variables:
05
Compiling and Executing Code :
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 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.

Tags

startsyntax

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

Working with Files, Folders java
Working with Files, Folders java
March 25, 2015
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media