0

I'm learning Java in school and they told us to use eclipse since it provide a whole IDE, but somehow I like working with sublime better, I don't know, maybe because its cleaner and feels really light weight compare to eclipse.

Now, if I created a Rectangle.java class and I have also created a Program.java class which includes the main:

public class Program {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Rectangle myRect = new Rectangle(double w, double h);

            myRect.show;

    }

}

So where do I run this..? in the terminal? and how?

Of course I will not have a debugger unfortunately, but please help me to figure out how can I use sublime while learning Java, I like this editor and want to use it.

Thanks guys!

SQS
  • 35
  • 5
  • 3
    You can't run it through Sublime Text. You can continue to edit using any editor you please, but you should still use Eclipse as you're being taught for its other support. – mah Apr 27 '14 at 23:34

4 Answers4

0

The easiest way is to compile and run it from terminal. Since you call it terminal, i assume you are working on a mac. This has been answered before.

Community
  • 1
  • 1
Luca
  • 558
  • 4
  • 18
0

Sublime is just a text editor. It is a nice one with syntax highlighting and other nifty tools but it is not a compiler. IDEs will take care of the complilation step for you but since you are opting to use SublimeText you will have to compile the Java files into their bytecode manually.

You will need to use javac for this. You can find it inside your JDK. Where it is located and how you call it depends on your OS and how you installed the JDK.

The most basic use would be to compile a single Java file without any dependencies (run from the command line inside the folder containing your source code):

/path/to/javac YourFile.java

That will output a YourFile.class file beside your .java version that can be run by your JRE with (again from the folder containing the *.java and *.class files):

java YourFile

For more complicated uses such as including 3rd party libraries, class paths and cross class dependencies here is an example tutorial (many of which can be found with a simple Google)

indivisible
  • 4,892
  • 4
  • 31
  • 50
  • does it makes sence to use sublime to edite my code and save the files in the eclipse directory and run it in eclipse? or it's too clumzy.. @mbs – SQS Apr 27 '14 at 23:49
  • You can do so if you wish. It involves a little extra leg work for yourself but that would be your call. But you should be aware of two important things before you decide to stay with SublimeText: 1/ There are many tools an IDE can offer you over a text editor, 2/ Since Eclipse is the supported tool you may not get help down the line from your school if you run into issues as you're not using their suggested tool. – indivisible Apr 28 '14 at 00:11
0

I have written about compile and run a Java program with single key Binding in my Blog at this link https://sainirahul.wordpress.com/2015/07/15/pure-sublime-coding-and-running-java-program-using-sublime-text-editor/

Rahul Saini
  • 2,353
  • 1
  • 16
  • 19
0

Sublime Text has a feature called Build System. It basically means that program will be executed inside a console in Sublime window after pressing Ctrl+B. Unfortunately this inner console doesn't support input (as I recall).

Helpful links:

Luke
  • 1,369
  • 1
  • 13
  • 37