Sublime Forum

Java and Sublime Text

#1

Hey guys, I’m new here so if I do something wrong, please tell me.

I want to be able to use sublime text with java (i’m taking a class now). How would I compile and run a program that requires inputs in sublime text?

If that is not possible, I read about people using iTerm and Sublime Text, could someone please explain how they are using that setup?

Thank you!

0 Likes

#2

Anyone?

0 Likes

#3

ST does not allow for interactive input. That being said, you can still build using ST if you would like. That is, you can run “javac” through ST using the ST build system. Then, you can go to your terminal and execute the program (run the “java” command). I don’t know if there is any other way to do it. Of course, there isn’t anything stopping you from running the build (javac) portion of the workflow in the terminal either. I believe you can set up a hotkey to bring iTerm to the front. Perhaps you can also use that to streamline your workflow.

0 Likes

#4

Thanks!

I guess I could do all the compiling and building in iTerm. Two questions:

  1. Is there any way to set up some sort of hotkey to automatically type the command to get to the that java file and run it (and automatically get its location too, so I dont have to change/type that each time)?

  2. What do you mean by streamline the workflow?

0 Likes

#5

The terminal will keep a history of your last run commands. You can use the “up” arrow to navigate through them. You may also use some sort of bash alias/function so you have to type less. I don’t know if there are tools to auto type a single command. It’s never been an issue for me. Something to do is effectively dedicate a tab of iTerm to performing your building/testing. That way you only need to navigate there once. You can then use the previously mentioned tips to run your program.

When I say “streamline” you may also read “make easier/faster”. Let’s say your normal workflow is to do the following to test.

  1. Use mouse to bring iTerm into focus.
  2. Type the command to compile your program (javac …)
  3. Execute your program (java …)
  4. Enter input required.

Alternatively, let’s say you do the following.

  1. Hotkey to bring iTerm into focus.
  2. Use a bash alias/function to build and execute your program. You could also use file redirection for the input.

With the, what I will loosely call an improved workflow, you can do the same tasks in fewer steps. By using a hotkey (though you could always cmd+tab to iTerm), it’ll take less time to bring iTerm into focus. By using an alias/function, you can reduce the number of steps to build and execute your program. Rather than going through the history to build and execute separately, there is now a single command. Though this can also be done through chaining using “&&” to build and execute. Finally, redirecting the input just makes things nice. Rather than having to do type in your input, which can be error prone and time consuming, you can be sure the same input is being used each time. This last point moves towards testing process. I don’t know what your class covers, but I would think testing would be covered at some point (if you are not familiar with it). If it isn’t and you aren’t ask your teacher and/or do some independent research.

0 Likes

#6

Thanks very much, helped me a ton

0 Likes