Flat Preloader Icon

First Java Program

We advise reviewing this tutorial in the order specified in the menu on the left. Since Java is an object-oriented language, some ideas can be unfamiliar. Take breaks as necessary, and review the examples as often as necessary.

Overview

1) Environment Setup

2) First Java Program

1) Environment Setup

        Download Java Platform(JDK) from oracle website         

  • Install the IDE on your machines and
    use the downloaded JDK location as the default JDK for the IDE.

Other Available IDEs

  • Eclipse (free and open source)
  • Sun’s Java Studio Enterprise (free)
  • Sun’s Java Studio Creator (free)
  • Oracle JDeveloper (free)
  • Borland JBuilder
  • IBM’s WebSphere Studio Application Developer
  • BEA WebLogic Workshop
  • IntelliJ IDEA

2) First Java Program

				
					
* @author testuser
*/
public class FirstApp {

public static void main(String[] args) { 

    System.out.println("Hello Beans!!");
    
 }

}
				
			

Content of Java Program - Package

				
					

/**
* @author testuser
*/
public class FirstApp {

public static void main(String[] args) {

    System.out.println("Hello Beans!!");
    
 }

}
				
			
  • Specifies the package of the program.                                                                   
  • FirstApp .java gets compiled and FirstApp .class gets generated and is stored under folder myPackage.

Content of Java Program - Comments

				
					package myPackage;
/**
* @author testuser
*/
public class FirstApp {

public static void main(String[] args) { 

    System.out.println("Hello Beans!!");

 }

}
				
			
  • Text preceded by “//”
  • Text surrounded by /* */
  • Gets ignored by compiler
  • Content of Java Program - Reserved Words

    • Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program.
    • E.g. class, public, static etc.

          Content of Java Program-statements

    • Represents an action or sequence of actions . E.g. System.out.println(“Hello Beans!!”);
    • Every statement in Java ends with a semicolon (;).

    Content of Java Program - Blocks

    • A pair of braces i.e. {}, forms a block that groups components of a program.
    				
    					public static void main(String[] args) {
    
        System.out.println("Hello Beans!!");
        
    }
    				
    			

    Content of Java Program - Class

    • Represents the blueprint for all the objects.
    				
    					public class FirstApp { }
    				
    			

    Content of Java Program - Methods

    • A function call for performing some specific operations and takes in some  inputs and returns an output.
    				
    					System.out.println("Hello Beans!!");
    				
    			

    Content of Java Program - Main method

    • Acts as a starting point of the program.
    • Takes in String array as input parameter
    				
    					public static void main(String[] args) {
    
        System.out.println("Hello Beans!!");
        
    }
    				
    			
    We will only use println() in this lesson because it makes code output easier to read.