0

I have some code and i need to build and run it . But the name of file where this code is located can be different from classes name. How can i config SUBLIME TEXT to compile and run in this situation.

class A {   
}

class B extends A{
}

class C extends B{
public static void main(String ...args){
A a =new A();
 }  
}

  • Possible duplicate of [How to run a java program from the command line](http://stackoverflow.com/questions/16137713/how-to-run-a-java-program-from-the-command-line) – Cédric M. Feb 24 '16 at 14:06

1 Answers1

2

You can compile java code using sublime text by following this steps:

  1. Install jdk (java Development Kit) from Oracle
  2. if you are in windows you will need to create an environment variable a. go to system in control panel b. advance system settings c. Environement variables d. New e. variable name : PATH f. variable value: C:\Program Files (x86)\Java\jdk1.8.0_71\bin (or navegate where the jdk was installed and copy and paste the path name. click ok and you are done with step one.

  3. Open command prompt and type javac to test if is working(if you installed and configure the jdk correctly you will get a bunch of letters on screen. If not you will get an error, please start the process again

  4. to compile the program go to the directory where the program is locate by typing cd "Enter the directory name here" and press enter

  5. in command prompt type: javac "name of program plus extention" such that myProgram.java and hit enter

  6. Then type: java "name of program without extention" such myProgram

if you are using terminal: http://introcs.cs.princeton.edu/java/15inout/mac-cmd.html

If you have any more questions please feel free to ask

  • It is not exactly what i want . For examle i have file test.java and code like in post . How can i run this code without changing name of file – Dmitry Zherebko Feb 24 '16 at 15:14