How to Compile a Java Program

Method 1 of 2:

Using Java Software Development Kit

  1. How to Compile a Java Program Picture 1
    Open 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:
    1. 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.
    2. 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.
    3. Linux: Press Ctrl+Alt+T.
  2. How to Compile a Java Program Picture 2
    Use the cd command to access the directory with your Java code. The source code is the file that ends with the .java file extension.
  3. How to Compile a Java Program Picture 3
    Type 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.
    1. To see the name of the new file in the current directory, run the dir (Windows) or ls -a (Mac/Linux) command.
    2. If you see an error when trying to
  4. How to Compile a Java Program Picture 4
    Type java programname and press Enter or Return. Replace programname with the name of your program. This runs the program at the command line.
Method 2 of 2:

Using an Online Java Compiler

  1. How to Compile a Java Program Picture 5
    Navigate 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.
    1. There are a variety of online compilers out there if Codiva doesn't work for your needs. Some other popular options are Jdoodle, and OnlineGDB.
  2. How to Compile a Java Program Picture 6
    Sign in or create an account. If you're new to Codiva, click Create Account at the top-right corner to sign up.
  3. How to Compile a Java Program Picture 7
    Enter a project name and click Create. This creates a new project, which is like a container for your source files.[2]
  4. How to Compile a Java Program Picture 8
    Create 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.
    1. For example, if you're creating a Java program called HelloWorld, name the source file HelloWorld.java.
  5. How to Compile a Java Program Picture 9
    Write 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.
  6. How to Compile a Java Program Picture 10
    Click Run to run the program. Since the code compiles automatically, clicking Run will just launch your app in its current state.
5 ★ | 1 Vote

May be interested

  • How to Get Started with the Raspberry PiPhoto of How to Get Started with the Raspberry Pi
    the raspberry pi is a single board computer (sbc) roughly the size of a credit card. it was developed by the raspberry pi foundation to teach the basics of computer science in schools and developing countries. since its release, it has...
  • How to Become a UI DesignerPhoto of How to Become a UI Designer
    user interface design (ui design) is a crucial subset of user experience design that focuses on how users interface with a particular product. ui designers work on constructing apps, websites, and other products that are visually pleasing...
  • How to Use Excel VBA Variable Data TypesPhoto of How to Use Excel VBA Variable Data Types
    you will learn to create the different types of excel vba (visual basic for applications) variable data types. vba makes life easy for programmers because it can handle all the details involved in dealing with data automatically. for...
  • How to Have a Successful Open Source ProjectPhoto of How to Have a Successful Open Source Project
    this wikihow teaches you how to start and maintain a successful open source project. aside from working hard and focusing on the end goal, the key to creating a successful open source project often lies in defining your goals early on in...
  • How to Compress Data Using Huffman EncodingPhoto of How to Compress Data Using Huffman Encoding
    huffman's algorithm is used to compress or encode data. normally, each character in a text file is stored as eight bits (digits, either 0 or 1) that map to that character using an encoding called ascii. a huffman-encoded file breaks down...
  • How to Make a Scrolling Marquee in HTMLPhoto of How to Make a Scrolling Marquee in HTML
    a scrolling marquee is moving text added to a website, but html is no longer commonly used for this feature and is not recommended. the html tag for scrolling marquees has been deleted from the standard html library. to accomplish a...