|
|
|
|
|
How to compile Java Source code from the command PromptUsing javac to compile .java filesAP Computer Science Class | AB AP computer Science Class | Mastering the Class Path|How to run a class from the command prompt | How to pass parameters to class from command prompt | how to create a runnable Jar file
First off, this tutorial is based on using windows Vista. XP should work basically the same.
Part I: Locate Javac
Part II : Compiling with JavacIn this example, I am going to use javac to compile a java source file called Hi.java which is saved on my desktop. ![]() First, open up a command prompt. If you're using vista, you must run 'as administrator' for this example to work. ![]() ![]() How to Run the class file from the command Prompt
Compiling ia a lot of fun and all, but the whole point in compiling a program is being able to run it! Let's now run my Hi.class file. I would like to show you the source code for this class so that you know what this trivial class does:
public class Hi{
public static void main(String[] args){
System.out.println("hi");
}
}
Assuming that you are in the same folder as your class Hi.class. You can easily run this program by simply typing java Hi . NOTE: you do not append the file extension ".class". Typing Java Hi.class will cause an error. ![]()
Now you are ready to learn how to pass arguments to Java from the command prompt
Top |