What happens when the following code is compiled and run select the one correct answer?
QuestionsQuestion 1: When you compile a program written in the Java programming language, the compiler converts the human-readable source file into platform-independent code that a Java Virtual Machine can understand. What is this platform-independent code called? Show Answer 1: Bytecode. Question 2: Which of the following is not a valid comment: a. Answer 2: c is an invalid comment. Question 3: What is the first thing you should check if you see the following error at runtime: Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp.java. Answer 3: Check your classpath. Your class cannot be found. Question 4: What is the correct signature of the Answer 4: The correct signature is Question 5: When declaring the Answer 5: They can be in either order, but the convention is Question 6: What parameters does the Answer 6: The ExercisesExercise 1: Change the
Answer 1: This is the only line of code that must change: System.out.println("Hola Mundo!"); //Display the string. Exercise 2: You can find a slightly modified version of The program has an error. Fix the error so that the program successfully compiles and runs. What was the error? Answer 2: Here's the error you get when you try to compile the program: HelloWorldApp2.java:7: unclosed string literal System.out.println("Hello World!); //Display the string. ^ HelloWorldApp2.java:7: ')' expected System.out.println("Hello World!); //Display the string. ^ 2 errors To fix this mistake, you need to close the quotation marks around the string. Here is the correct line of code: System.out.println("Hello World!"); //Display the string.
Essentials, Part 1, Lesson 1: Compiling Running a Simple ProgramThe computer age is here to stay. Households and businesses all over the world use computers in one way or another because computers help individuals and businesses perform a wide range of tasks with speed, accuracy, and efficiency. Computers can perform all kinds of tasks ranging from running an animated 3D graphics application with background sound to calculating the number of vacation days you have coming to handling the payroll for a Fortune 500 company.
Training Index Essentials of the JPL, Part 1 When you want a computer to perform tasks, you write a program. A program is a sequence of instructions that define tasks for the computer to execute. This lesson explains how to write, compile, and run a simple program written in the Java language (Java program) that tells your computer to print a one-line string of text on the console. But before you can write and compile programs, you need to understand what the Java platform is, and set your computer up to run the programs.
A Word About the Java Platform The Java platform consists of the Java application programming interfaces (APIs) and the Java 1 virtual machine (JVM). Java APIs are libraries of compiled code that you can use in your programs. They let you add ready-made and customizable functionality to save you programming time. The simple program in this lesson uses a Java API to print a line of text to the console. The console printing capability is provided in the API ready for you to use; you supply the text to be printed. Java programs are run (or interpreted) by another program called the Java VM. If you are familiar with Visual Basic or another interpreted language, this concept is probably familiar to you. Rather than running directly on the native operating system, the program is interpreted by the Java VM for the native operating system. This means that any computer system with the Java VM installed can run Java programs regardless of the computer system on which the applications were originally developed. For example, a Java program developed on a Personal Computer (PC) with the Windows NT operating system should run equally well without modification on a Sun Ultra workstation with the Solaris operating system, and vice versa. Setting Up Your Computer Before you can write and run the simple Java program in this lesson, you need to install the Java platform on your computer system. The Java platform is available free of charge from the Java web site. You can choose between the Java® 2 Platform software for Windows 95/98/NT or for Solaris. The download page contains the information you need to install and configure the Java platform for writing and running Java programs. Note: Make sure you have the Java platform installed and configured for your system before you try to write and run the simple program presented next. Writing a Program The easiest way to write a simple program is with
a text editor. So, using the text editor of your choice, create a text file with the following text, and be sure to name the text file
Here is the ExampleProgram.java source code file if you do not want to type the program text in yourself. Compiling the Program A program has to be converted to a form the Java VM can understand so any computer with a Java VM can interpret and run the program. Compiling a Java program means taking the programmer-readable text in your program file (also called source code) and converting it to bytecodes, which are platform-independent instructions for the Java VM. The Java compiler is invoked at the command line on Unix and DOS shell operating systems as follows:
Note:
Part of the configuration process for setting up the Java platform is setting the class path. The class path can be set using either the Interpreting and Running the Program Once your program successfully compiles into Java bytecodes, you can interpret and run applications on any Java VM, or interpret and run applets in any Web browser with a Java VM built in such as Netscape or Internet Explorer. Interpreting and running a Java program means invoking the Java VM byte code interpreter, which converts the Java byte codes to platform-dependent machine codes so your computer can understand and run the program. The Java interpreter is invoked at the command line on Unix and DOS shell operating systems as follows:
At the command line, you should see:
Here is how the entire sequence looks in a terminal window: Common Compiler and Interpreter Problems If you have trouble compiling or running the simple example in this lesson, refer to the Common Compiler and Interpreter Problems lesson in The Java Tutorial for troubleshooting help. Code Comments Code comments are placed in source files to describe what is happening in the code to someone who might be reading the file, to comment-out lines of code to isolate the source of a problem for debugging purposes, or to generate API documentation. To these ends, the Java language supports three kinds of comments: double slashes, C-style, and doc comments. Double Slashes Double slashes (
C-Style Comments Instead of double slashes, you can use C-style comments (
Doc Comments To generate documentation for your program, use the doc comments (
The Java platform installation includes API Documentation, which describes the APIs available for you to use in your
programs. The files are stored in a See Common Compiler and Interpreter Problems lesson in The Java Tutorial for troubleshooting help. The
javadoc Home Page has more information on the 1 As used on this web site, the terms "Java virtual machine" or "JVM" mean a virtual machine for the Java platform.
Why Oracle
Learn
What’s New
What will happen when you try to compile and run the following application?What would be the result of attempting to compile and run the following program? The program will compile and run successfully.
What happens when Java code is compiled?Java source code is compiled into bytecode when we use the javac compiler. The bytecode gets saved on the disk with the file extension . class . When the program is to be run, the bytecode is converted, using the just-in-time (JIT) compiler.
When you compile a program written in the Java programming language?Question 1: When you compile a program written in the Java programming language, the compiler converts the human-readable source file into platform-independent code that a Java Virtual Machine can understand.
What does compile mean Java?Compiling a Java program means taking the programmer-readable text in your program file (also called source code) and converting it to bytecodes, which are platform-independent instructions for the Java VM.
|