Java

Compiling and Running the Java Program

Compiling and Running the Java Program

Compiling and running a Java program is the first step in learning, especially in java, since this process is a little different than in other languages. The process involves writing source code, compiling it into bytecode, and then running the compiled program. To begin with, all that is required is an editor for writing source code and a command prompt for interacting with the compiler. 
Once written, source code can be saved as. java files which are then fed into the Java compiler from within the command line interface (CLI). This compiles them into class files containing bytecode which can be run on any machine equipped with a JVM (Java Virtual Machine). 
● Compiling: 
Hence to compile the java program, type the following command in CLI: For example, let’s say the file name is FirstProgram.java, you will have to type the following command: 
 

javac FirstProgram.java 


● Running: 
Finally, these compiled applications can be executed by simply typing ‘java’ followed by their name at the CLI and pressing enter - thus completing both the compilation and execution of your program in one step! 
Example: java FirstProgram 

Shortcut: Some IDEs like Eclipse, IntelliJ IDEA, and Netbeans provide a shortcut to compile and run the code by using the "run" button or "ctrl+f11" or "cmd+f11" respectively. 
Hence, once the java code is written, it has to be saved with .java, and then it has to be compiled and executed. 
 

Top course recommendations for you

    Web Scraping with Python
    1 hrs
    Beginner
    13.8K+ Learners
    4.45  (746)
    Python for Non-Programmers
    1 hrs
    Beginner
    43.5K+ Learners
    4.5  (1841)
    Visual Graphics in C
    2 hrs
    Intermediate
    13.9K+ Learners
    4.52  (405)
    Swift Tutorial
    2 hrs
    Beginner
    3.4K+ Learners
    4.43  (140)
    Systematic Inventive Thinking Innovations
    1 hrs
    Beginner
    2.1K+ Learners
    4.57  (101)
    React JS Tutorial
    2 hrs
    Beginner
    53.1K+ Learners
    4.51  (2845)
    Linux Tutorial
    2 hrs
    Beginner
    42.3K+ Learners
    4.51  (2607)
    Functions in Python
    1 hrs
    Beginner
    14.5K+ Learners
    4.56  (654)
    GitHub Tutorial for Beginners
    2 hrs
    Beginner
    15.2K+ Learners
    4.0  (1)
    Trees in Java
    2 hrs
    Beginner
    7.1K+ Learners
    4.51  (146)