How to Compile and Run Java in Sublime Text 3 / Integrating Java with Sublime Text Editor

TIJ Tech Private Limited
3 min readMar 8, 2021

For more details and information, please refer to the YouTube video.

Video URL: https://youtu.be/dyOHuVoB25A

Introduction

In this tutorial, I’ll be teaching you how to integrate Java in sublime, in the sense, How can we use Sublime as a Java Editor. In fact, there are lots of lots of Editor software. Some of them are heavy as well as some of them are lightweight. So most people prefer lightweight software to work on and one of them is Sublime. In fact, we have some other editor as well but most of the people they actually preferred to work on Sublime. But the question is How we can compile and execute the Java Programming File into the Sublime editor.

Prerequisite (What you need ?)

Check whether your system has Java JDK Files or not.

If you don’t have the JDK Files then download them from:

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

Finding the location of the Java path.

Setup Java in Sublime Text 3

  1. Create Sublime Package to Build and Run Java Source code.

Copy the codes seen below and paste them in the sublime.

{
"cmd": ["javac", "$file_name", "&&", "java", "$file_base_name"],
"selector": "source.java",
"file_regex": "^\\s*File \"(...*)\", line ([0-9]*)",
"path": "C:\\Program Files\\Java\\jdk-14.0.2\\bin\\",
"shell": true
}

So this is the actual format for Java to have the build system within the Sublime text. Then, save this inside the sublime text package file (Package Folder) for that go to:

“Preferences" >>> "Browse Packages”

Then copy this path. Then you can save the file.

But the extension is very important here.

After creating this package file or the build system package file, you just go to “Tools”, to check whether it has been created or not.

As you can see under the build system, “MyJava” is been created.

2. Create simple Java code (Eg. Hello World) and Build and run the code.

For testing, let us create a new file and save it anywhere on your local desktop.

public class HelloWorld {
public static void main(String ...args){
System.out.println("Hello World");
}
}

For running the code, use the shortcut key “Ctrl + b”.

So you can see that we have successfully actually printed the “Hello World” and we have successfully integrated Java with the Sublime Text, and now we can work any Java programming file within the sublime text.

--

--