What is the use of 'javac' command?
Compile a java program
The question asks about the primary function of the javac command in the context of Java programming. Understanding the different stages a Java program goes through from source code to execution is key to answering this.
A typical Java program development and execution process involves several steps. Initially, you write the human-readable source code in files with a .java extension. This source code then needs to be processed before it can be run on a computer.
The javac command is a crucial tool provided as part of the Java Development Kit (JDK). Its main purpose is related to preparing your source code for execution.
Let's look at what each option suggests about the use of the javac command:
java command, not javac. The java command starts the Java Virtual Machine (JVM) and runs the bytecode contained in .class files.jdb (Java Debugger), not javac..class files), the javac command itself does not perform interpretation of the original .java source code. It performs a different process.javac command takes the .java source files and translates them into bytecode, which is saved in files with a .class extension. This bytecode is then platform-independent and can be run on any system with a compatible JVM.When you use the command javac YourProgram.java, the javac compiler reads your YourProgram.java source file. It checks for syntax errors and other issues, and if the code is valid, it generates a YourProgram.class file. This .class file contains the bytecode.
Therefore, the fundamental use of the javac command is to compile Java source code into Java bytecode.
Here's a simple comparison of common Java commands:
| Command | Primary Function | Input | Output |
|---|---|---|---|
javac |
Compile Java source code | .java files |
.class files (bytecode) |
java |
Execute Java bytecode | .class files |
Runs the program |
jdb |
Debug Java programs | Running JVM/program | Debugging session |
Based on this, the option that correctly describes the use of the javac command is compiling a Java program.
The javac command is the Java compiler. It takes your human-readable Java source code and translates it into machine-readable bytecode that the Java Virtual Machine (JVM) can execute. Without the compilation step performed by javac, you cannot run a Java program from its source code.
| Command | Purpose |
|---|---|
javac |
Compiles Java source code files (.java) into bytecode files (.class). |
java |
Executes Java bytecode (.class files) by running the Java Virtual Machine. |
jdb |
Provides command-line debugging capabilities for Java programs. |
The Java platform is known for its "Write Once, Run Anywhere" principle. This is achieved through the compilation to platform-independent bytecode by javac and the execution of this bytecode by the platform-specific JVM using the java command. The JVM acts as an interpreter for the bytecode, translating it into native machine instructions at runtime.
Understanding the distinction between compilation (javac) and execution (java) is fundamental to working with Java.
When an applet begins, which of the following sequence methods is CORRECT?
1) start()
2) paint()
3) init()
What will be the output of the following Java program?
class test
{public static void main (String args [ ])
{
System.out.println(20 + 30 + "Java");
System.out.println("Java" + 20 + 30);
}
}
In Java, the 'PreparedStatement' interface is a sub interface which is used to execute __________ query.
Which of the following is NOT a java primitive type?
Which of the following is/are the rules to declare variables in Java?