Java Program Basic

From Following program you can easily understand basics of defining the java program step by step.

// Comment
package com.sabari;

import java.util.Scanner;

public class simple {

  * @param args
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  String name;
  Scanner in = new Scanner(;
  System.out.println("Enter Your name");
  name = in.nextLine();
  System.out.println("Enter Your Age");
  int  age = in.nextInt();
  System.out.println("Your Name:"+name);
  System.out.println("Your Age:"+age);



Out Put
Enter Your name
Enter Your Age
Your Name: sabari
Your Age:29
// Comment
class simple {

Here class is a keyword mainly use to create a new class."simple" is the name of the class.
// Comment
public static void main(String[] args) {

Public - public is an access specifier, due to this the programmer can easily  control the visibility of class members. When a class member is affirmed as public, then that member can be accessed by code outside the class in which it is declared.

static allows main( ) to be elite to instantiate a particular instance of the class. main( ) is called by the Java interpreter before any objects are created.

 void merely says the compiler  ,main( ) does not return a value
main( ) is called when a Java application initiates.
It is imperative to realize that the Java compiler will compile classes that do not contain a main( ) method.

Java interpreter  has no approach to run these classes .if you mention Main as a replacement for main, the compiler retain compile your program. Java interpreter will testimony an error because it cant find the main( ) method.

String args[ ] array of instances of the class  String.

  args obtains command-line arguments here when the program    is     executed.Arrays are collections of similar objects.
A complex program may have several number of classes,but one main class is need to initiate an application.
While creating applets—Java programs are  usually embedded in Web browsers so we no need to use  main( ) at all, because Web browser uses a various ways of starting the execution of applets.

System is a predefined class affords various access to the system

out  is the output stream which is usually get in connected with that of console.
Output is consummate by the built-in println( ) method.
print( )  mainly exhibit the string .This string is not go behind a newline. next output is generated, it will start on the same line.
test Web Developer

No comments:

Post a comment

Related Posts Plugin for WordPress, Blogger...