How to Setup Sublime Text 3/4 for Competitive Programming for Java

Saransh Kumar
4 min readDec 3, 2020

Welcome guys! If you are a programmer then you must have heard about Sublime Text “sophisticated text editor for coding”. It’s so popular because it is highly configurable, extremely lightweight, and has a sleek and beautiful design.

This setup will save your time and make you able to focus only on the problem rather than focusing on other things. It is preferred to have some kind of template to save time during online contests.

Hoping that you have already installed Sublime Text 3.

Now, lets get Started!

Setup Input and Output window

We all have to paste that same input to console again and again if code fails and this wastes a lot of time. In online contest, time matter a lot. To avoid wasting time, we are going to take input from a file and writing the output to another file. So when ever we have to give input to the program, we will just paste that into the input file.

To setup this:

  • Go to View -> Layout -> Column-3 (or Press Alt+shift+3).
Layout

Then View -> Groups -> Max Column 2

group

Now we have setup the input and output window.

Setup build system for Java

Now we have to setup the build system in order to compile and run our java program. When compilation of java program is done, .class files are create. So we are going to separate those files in “temp” folder which holds all the temporary files in windows and for linux its “/tmp”.

  • First create two files named “input.txt” “output.txt” under the “C:/Users/<your-username>”.
  • Now inside sublime text, Go to Tools -> Build System -> New Build System.
build system
  • Now a file is open. Then paste this code:
For windows
For linux based OS
  • Then save this file with the name “java.sublime-build”.
  • Now create environment variables for input and output file path.
  • In the start menu, search for environment variables -> Environment Variables.
  • Now create the environment variables “INPUT” and “OUTPUT”.

That all you have successfully setup the Build System for Java.

Code Snippet — Adding Boiler plate code

In Sublime Text or any editor or IDE, we can add our own code snippet. So when ever we trigger that, editor will place the code.

To add code snippet in Sublime-Text:

  • Go to Tools -> Developer -> New Snippet
code snippet
  • Now a file is open. Then paste this code:
  • This code includes a Fast Scanner class which is fast than the native Scanner class — I have added this because in some cases, our code can give TLE (Time Limit Exceed).
  • You can replace the name which is inside the <tabTrigger> tag. So whenever you type that name, it will show suggest and when you press TAB or ENTER key, this code will be added.
code-snippet-trigger

That all you have successfully setup the code snippet for java boilerplate code.

Compile and Run a Java Program

We have setup the build system for java and by using that we will compile and our java program.

  • First create a file called “<file_name>.java”.
  • Inside that file type that code-snippet trigger which you have created and press TAB or ENTER key.
  • Then click on Upper Right window and open the “input.txt” file which is present inside the “default user” folder.
  • Click on Bottom Right window and open the “output.txt” file which is also present inside the “default user” folder.
  • Now you can write your logic inside the solve() method and run the program by pressing “CTRL + B”.

Example:

Now you are ready to go!

Extras — Plugins

Plugins make the editors or IDEs more powerful than before. They also save out time and make editors more attractive.

Here are the plugins which I recommend:

  • Package Control
  • Side Bar
  • Terminus
  • Kite
  • SublimeAStyleFormatter

That’s it guys! Hope you find this article useful. Thanks for reading.

Happy Coding :)

--

--