- Download Java Development Kit (JDK).
- Set paths - You better copy below code to a batch file (.bat) to run before compiling and running a Java program.
Code: Select all
set path=C:\Java\jdk1.6.0_20\bin set CLASSPATH=.;C:\Java\jdk1.6.0_20\lib set JAVA_HOME=C:\Java\jdk1.6.0_20
- Compile a Java program - use following command
Sample Java code is give below. Save following contents to Hello.java
Code: Select all
C:\Java\jdk1.6.0_20\bin\javac.exe Hello.java
After this step, you can see a file named as Hello.classCode: Select all
public class Hello { public static void main(String argv[]) { System.out.println("Hello world !"); } }
- Running the class file - use following command
Code: Select all
C:\Java\jdk1.6.0_20\bin\java.exe Hello.class
How to run a Java Class from scratch
How to run a Java Class from scratch
I had to write a Java program to help a member of ours. I didn't touch Java after 2003 and I couldn't remember the essential settings. So I had to surf the net to find out how we can compile and run a Java class file. So I thought it would be better to add a quick guide to do this from scratch.
Re: How to run a Java Class from scratch
Neo friend
I did as this
http://www.java.com/en/download/help/path.xml
http://www.ehow.com/how_5127784_set-java-path.html
Then I don't have to Type Java Compiler Path again and again.
We can use Simple by typing in Command Prompt
If some one wants more info Just search on Google like this " set java path "
I added this to Help for others and Not tried to Show that I Know More than You. Don't misunderstand Me !
I did as this
http://www.java.com/en/download/help/path.xml
http://www.ehow.com/how_5127784_set-java-path.html
Then I don't have to Type Java Compiler Path again and again.
We can use Simple by typing
Code: Select all
javac
If some one wants more info Just search on Google like this " set java path "
I added this to Help for others and Not tried to Show that I Know More than You. Don't misunderstand Me !