This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.
This article has been viewed 30,006 times.
Learn more...
This wikiHow teaches you how to turn your Java source code into an executable app using a local and online compiler. If you're using a computer, the most common way to compile Java code is using Java Software Development Kit (Java SDK) from the command line. If you're using a phone or tablet (or a computer without a compiler), you can use an online compiler like Codiva.
Steps
Using Java Software Development Kit
-
1Open the command prompt. You can use the Java Software Development Kit (Java SDK) from the command prompt on Windows, macOS, or Linux. If you don't have the Java SDK installed, see How to Install the Java Software Development Kit. Here's how to get to the command prompt on each system:
- Windows: Right-click the Start menu and select Command Prompt. If you don't see this option, type cmd into the Windows Search bar and click Command Prompt in the search results.
- macOS: Click the magnifying glass at the top-right corner of the screen to open Spotlight, type terminal, and then click Terminal in the search results.
- Linux: Press Ctrl+Alt+T.
-
2Use the cd command to access the directory with your Java code. The source code is the file that ends with the .java file extension.Advertisement
-
3Type javac sourcecode.java and press ↵ Enter or ⏎ Return. Replace sourcecode.java with the name of your source file.[1] This compiles your source code into an executable file, which ends with the .class extension.
- To see the name of the new file in the current directory, run the dir (Windows) or ls -a (Mac/Linux) command.
- If you see an error when trying to
-
4Type java programname and press ↵ Enter or ⏎ Return. Replace programname with the name of your program. This runs the program at the command line.
Using an Online Java Compiler
-
1Navigate to https://www.codiva.io in a web browser. Codiva is an online Java compiler that's great for people who can't install a compiler locally—it can even be used on a phone or tablet.
-
2Sign in or create an account. If you're new to Codiva, click Create Account at the top-right corner to sign up.
-
3Enter a project name and click Create. This creates a new project, which is like a container for your source files.[2]
-
4Create a Java source file and click Create. Java source files must end with the .java file extension. The new file will appear in project's tree, which appears in the right panel.
- For example, if you're creating a Java program called HelloWorld, name the source file HelloWorld.java.
-
5Write or paste your code into the editor. The code will compile in the background as you type. Additionally, it will display any code errors as they occur.
-
6Click Run to run the program. Since the code compiles automatically, clicking Run will just launch your app in its current state.
References
About This Article
1. Open the command prompt.
2. Change to the directory containing your code.
3. Type "javac (your source file)" and press Enter.
4. Type "java (compiled file name)" and press Enter.