Compile and Execute Java, C#, and PHP From Your Favorite Text Editors for REPL (Read-Evaluate-Print-Loop) use cases

Compile and Execute Java, C#, and PHP From Your Favorite Text Editors for REPL (Read-Evaluate-Print-Loop) use cases

Note: The instructions below are based on Windows environment, but are adaptable for Mac/Linux environments.

Sublime Text 2

Compile and Execute Java From Sublime Text 2:

Assuming JDK to be installed, otherise you need to download that first. You can download it from this link: JDK8

Step 1

Add the directory that contains your "javac" executable to "PATH" environment variable:

Open "Command Prompt" with administrator rights i.e "Run as administrator".

Execute the following command: SETX /M PATH "%PATH%;C:\Program Files\Java\jdk1.8.0_20\bin"

My javac executable was located in: C:\Program Files\Java\jdk1.8.0_20\

Note: The SETX command will truncate the path to 1024 characters, so it could be destructive.

Alternative Approach:

Press Win+Pause key.

Follow as directed in the screenshot below:

Step 2

Customise Sublime's build configuration for Java:

Click on Preferences->Browse Packages

Navigate to Java Folder->JavaC.sublime-build

Modify the contents of this file as:

Change To:

{

 "cmd": ["javac $file && java $file_base_name"],

 "shell": true,

 "file_regex": "^(...*?):([0-9]*):?([0-9]*)",

 "selector": "source.java"

}

I have modified the value for "cmd" key and changed it to first compile and build the Java program with the "javac" executable, then to run it with "Java" executable.

Step 3

Restart Sublime Text.

Step 4

Create or open a Java file and press Ctrl+B to build and execute the Java program. See the example below:

Read the complete recipe on how to Compile and Execute Java, C#, and PHP From Your Favorite Text Editors - Sublime Text 2 and Notepad++ here:







To view or add a comment, sign in

More articles by Robin Rizvi

  • GOTO Elimination Algorithm

    Following is an excerpt from the full-length article which is hosted on DZone here: Problem Description Devise an…

    1 Comment
  • JλVλ 8 (A Comprehensive Look): Part 1.2 - Insight Into Streams

    Following is an excerpt from the full-length article which hosted on DZone here. When it comes to Java streams, it's no…

  • JλVλ 8 (A Comprehensive Look): Part 1.1 - Lambdas Under the Hood

    Following is an excerpt from the full-length article which hosted on DZone here. We continue our detailed exploration…

  • JλVλ 8 (A Comprehensive Look)

    Following is an excerpt from the full-length article which hosted on DZone here. Let's start from the start and have a…

  • AngularJS - The Next Big Thing?

    Anyone out there wondering where the future of the web application world is heading? AngularJS is my personal favorite…

    2 Comments

Explore content categories