Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Thursday, February 18, 2010

Overloading Main Method in Java

public class Simple
{
public static void main()
{
System.out.println("My Main");
} 
public static void main(String args[])
{ 
Simple.main();
}
}  
When you run this program your runtime calls main method
with string arguments first and then calls the main method
without arguments. The output of this program will be "My Main".

JAVA BASIC SYNTAX

class Classname
{
  public static void main(String args[])
  {
   //Actual program
   Statements;
  }
}

1. public - Access Specifier, properties and methods can access anywhere, 
any package.
2. main() - The Java environment starts the execution of a program from 
main() method.
3. void - The main() method is not return anything. So the return type of 
the main() method must be void.
4. static - The jave environment able to call the main() method without creating 
an instance of the class. So its declared as static.
5.(String args[]) - In java, whatever we give, it will takes as String. So we are 
giving the command line argument as String.

There is one question that arises: Why do 
we use String args[] when we don't pass an  
argument.The answer for this is runtime 
always calls the method with String argument.

Thursday, January 7, 2010

Installing Java on your PC


1 Downloading the Java Development Kit from the Sun Java web site for a PC

A free version of Java may be obtained from the Sun Web Site
http://java.sun.com/javase/downloads/index.jsp
Make sure that you down load the Development Kit and not just the Run Time Environment (JRE). The download file name should have an dk. in it, e.g. an appropriate version of the Java development Kit, as a I write this (7 May 2007), would be the SE Development Kit (JDK), JDK 6u1, with dowload file titles, jdk-6u1-windows-i586-p-iftw.exe (on-line installation) or jdk-6u1-windows-i586-p.exe (off-line installation).

2 Installing the Java Development Kit on your PC

Click on the downloaded executable file, e.g. jdk-6u1-windows-i586-p-iftw.exe (on-line installation) or jdk-6u1-windows-i586-p.exe, and follow the on-screen installation instructions. The Java Development Kit Folder will be installed in your C:\Program Files\Javafolder.

3 Setting the PATH to the Java Development Kit on MS Windows XP

For ease of use, e.g. to be able to compile and run programs in any folder on your C drive with simple javac and java commands, you need to set the PATH. To do this for MS Windows XP, NT and 2000:
  • Click on start;
  • Click on Control Panel;
  • Click on System;
  • Click on Advanced tab;
  • Click on Environmental Variables button;
    An Envionmental Variables Box will appear;
  • Click on the Path line in the lower System variables window so that it is outlined in blue;
  • Click on the edit button below the lower System variables window;
    An Edit System Variable Box will appear;
  • If the Path line, now in the edit window, does not end in a semi-colon(;) add a semi-colon to the end of the line
    Type, at the end of the Path line, the address to the Java Development Kit bin, e.g. if it is in a folder named jdk1.6.0_01 and if this is stored in the Program Files Java folder type C:\Program Files\Java\jdk1.6.0_01\bin at the end of the Path line;
    For different versions of the Develeopment Kit replace jdk1.6.0_01 with the appropriate folder name;
  • Click on the OK, set or apply button in the Edit System Variable box;
  • Click on the OK, set or apply button in the Environmental Variables box;
  • Click on the OK, set or apply button in the System Properties (Advanced) box;
  • To make the new Path effective type C:\autoexec.bat in the Command Prompt Window, i.e.
    C:\>C:\autoexec.bat
    or restart your PC.
If a Path to a Java Development Kit bin already exists amend it to correspond to your new downloaded folder.