Friday, February 29, 2008

Calling a Method in Java Program

Calling a method in Java mainly involves of two basic steps:

1. You have to create an object to the class to which the method belongs.

Syntax for the above step : Classname obj = new Classname();

Example: First f = new First();

Here "First" is the classname and 'f' is the object created to that class.

2.Now after creating an object you can call any method using the notation "object.methodname();"

Therefore for the above example the calling goes like this : 'f.method'.

Here 'f' is the object we created.

Monday, February 25, 2008

First Java Program

Lets run our first Java Program which displays "Welcome To Java".

import java.lang.*;

class First
{
//First is the name of the Class

//"What ever we type after "//" are known as 'comments' and they wont be executed while running your Java application."

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

Note: 'void' never returns anything.