Developing Java Programs on Windows with Sublime Text Cardiff School of Computer Science & Informatics Documentation & Facilities Toggle navigation Home Documentation Software Services Contact Developing Java Programs on Windows with Sublime Text This Note describes how to build simple Java applications using the Sublime Text editor as an Integrated Development Environment. In Sublime Text you can create and edit Java programs, compile them with the javac compiler and run them with with java. Developing Java Programs in Sublime Text Sublime Text 2 is the standard editor on the School's Windows, Macintosh and Linux systems. This Note describes how to build simple Java programs and applets in it on Windows. A Java application can be written using a text editor, compiled with the javac command and run with the java command. You can use any editor to create a Java program but on the Windows workstations in the School's teaching laboratories, the Sublime Text editor is particularly suitable because it can be used as an Integrated Development Environment where all of these steps are available through menu entries in the editor itself. Creating a Java Program Sublime Text 2 is installed on the School's Windows PCs with Java 1.7. If you want to use Sublime Text on your own home computer, you can obtain it for evaluation from from http://www.sublimetext.com/. Install Java before you install Sublime Text. That way, it will find the Java commands and configure itself to use them. In the Lab, click the left mouse button on Start and expand the Cardiff Apps menu to find School Apps and then COMSC. Click on the Sublime Text 2.02 menu item to install and start the application. (Once it has been installed, you may also find Sublime Text in the Start menu.) We will create a simple Java program that outputs "Croeso!" (Welcome). Here is the source of the program:
/**
* The Croeso class implements an application that
* simply displays "Croeso!" to the standard output.
*/
class Croeso {
public static void main(String[] args) {
System.out.println("Croeso!"); // Output the string
}
}
When Sublime Text starts, click on the File menu and choose New File. This will cause a new tab to appear in the Sublime Text window. Type your program code into the tab panel. The program appears in the window as you type it. The program is in the editor but it isn't yet stored in your file space. Use the Save As... option in the File pull-down menu to save the program to a file in your file space. You should save the file to one called something.java in you H: drive (your networked file space) or a sub-directory of it. Once the program has been saved into a file named as ....java, Sublime Text recognises the programming language used in the file and becomes context sensitive. It uses colours to highlight syntactical elements of the program. Compiling the Java Program Compile your program using the Build options in the Tools menu. If we look in Build System we can see that JavaC, the Java compiler, has been chosen to compile Croeso.java. Compile the program by choosing Build from the Tools menu. A results panel opens at the bottom of the window showing you that the compilation has finished. This is also the place when any compilation errors are shown. Here we have introduced an error into the program by changing println to printl. When we select Build, the error messages from the Java compiler are output in the lower panel. Correct any errors and run Build again. Once the compilation has succeeded, you can run the program. In the Tools menu, Build System, select Java. Now choose Build and the program will run. The output from the program is shown in the results panel at the bottom of the window. Overview Developing Java Programs in Sublime Text Creating a Java Program Compiling the Java Program Running the Program Back to top Tags editing ide java laboratories programming windows Tags editing ide java laboratories programming windows Cardiff University is a member of the Russell Group of Universities Cardiff University is a registered charity No. 1136855 Copyright © Cardiff University Accessibility Feedback Cookies Privacy Policy Terms of Use Welsh Language Scheme