How to run a NetBeans project in command prompt?
You cannot run a file compiled using NetBeans because :
- while creating new file in netbeans we always first make a new project which automatically creates a new package
- the package which is created is automatically added at the top of each of the file made using netbeans eg:
Package javaapplication3;
/**
*
* @author Rajeev Handa
*/
public class JavaApplication3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i=10;
System.out.println(i);
}
} - so to run a program in cmd prompt first of all:
- Copy the [abc].java file into the bin folder of jdk
- Open the file and edit it with notepad
- remove the name of the package i.e. Package javaapplication3
- Then press Ctrl+S
- Open cmd Prompt
- Go to the bin folder or locate it by typing [cd..] command eg:cd java [enter] cd jdk[enter] cd bin[enter]
- Type javac [name_of_file].java
- You will see that a class file gets created in bin folder
- Then type java [name_of_class]
- Thats it...
No comments:
Post a Comment