Questions and Answers
What translates a source code program into executable object code?
Compiler
What is the extension used for Java byte code?
.class
What will be the output of the following calls to the print() method? System.out.println("hello"); System.out.println("world");
hello world
What will be the output of the following calls to the print() method? System.out.print("hello"); System.out.print("world");
Signup and view all the answers
Which of the following statements is true? (Select all that apply)
Signup and view all the answers
Which of the following is not one of the three general types of computer languages?
Signup and view all the answers
The .class extension on a file means that the file:
Signup and view all the answers
The .java extension on a file means that the file:
Signup and view all the answers
Each Java statement should be terminated with _____________.
Signup and view all the answers
The file produced by the Java compiler contains ________ that is executed by the _____________.
Signup and view all the answers
What kind of error is created by the following code snippet? System.outt.println("Hello");
Signup and view all the answers
Which Java statement prints a blank line?
Signup and view all the answers
These two lines of code do not produce the same output. Why? System.out.println(7+3); System.out.println("7+3");
Signup and view all the answers
What step should you take to run the same Java program on a computer that has a different processor?
Signup and view all the answers
What is the output from this code snippet? System.out.print("The sum is "); System.out.println("7+3");
Signup and view all the answers
A Java class with the name Printer has to be saved using the source file name:
Signup and view all the answers
When a compiler finds a syntax error in a program, what happens?
Signup and view all the answers
What is the output from this code snippet? System.out.print("The sum is "); System.out.println(7+3);
Signup and view all the answers
Expected math result: 2.5 Java result: 2
Signup and view all the answers
Expected math result: 0.3 Java result: 0.30000000000000004
Signup and view all the answers
Expected math result: 400000000 Java result:-294967296
Signup and view all the answers
Which of the following is required in order to convert Java source code into Java byte code?
Signup and view all the answers
Which of the following is required in order to run Java byte code?
Signup and view all the answers
The name of a file containing Java source code must end with which extension?
Signup and view all the answers
The Java programming language is roughly how many years old?
Signup and view all the answers
What is the most current major version of Java?
Signup and view all the answers
The Java code you type in a text editor is typically referred to as...
Signup and view all the answers
Which of these best describes the structure of a Java program?
Signup and view all the answers
If a Java program contains multiple methods, how does the Java Virtual Machine know which method should be executed first?
Signup and view all the answers
In Java, a set of words contained within quotation marks is referred to as a...
Signup and view all the answers
The missing quotation marks in the following line of code will result in what kind of error? System.out.println(Hi there!);
Signup and view all the answers
In Java, an exception is an example of a:
Signup and view all the answers
If you compile and run a program, and the program prints "hello" but you wanted it to print "goodbye", then your program contains:
Signup and view all the answers
The part of a computer responsible for carrying out instructions is known as:
Signup and view all the answers
Which of the following are typically integrated into an IDE, including Dr.Java? (Select all that apply)
Signup and view all the answers
When using Dr.Java, which of the following techniques will fix the indentation in your source code?
Signup and view all the answers
What does Dr.Java's 'Interactions Pane' give as a result when you type: 47/10?
Signup and view all the answers
What does Dr.Java's 'Interactions Pane' give as a result when you type: 1+.1?
Signup and view all the answers
What does Dr.Java's 'Interactions Pane' give as a result when you type: "cat".length?
Signup and view all the answers
What does Dr.Java's 'Interactions Pane' give as a result when you type: "13"+"14"?
Signup and view all the answers
Which of the following settings can you change in Dr.Java's preferences? (Select all that apply)
Signup and view all the answers
Study Notes
Compiler and File Extensions
- A compiler translates source code into executable object code.
- The .class extension signifies Java byte code.
- The .java extension indicates a file containing Java source code.
Output and Print Statements
-
System.out.println("hello");
followed bySystem.out.println("world");
outputs:hello world
-
System.out.print("hello")
followed bySystem.out.print("world")
outputs:helloworld
Methods and Language Types
- A method encapsulates program statements to perform tasks and hides implementation details, similar to a car pedal.
- Natural Language is not classified as a general type of computer language (compared to Machine and Assembly Language).
Java Class and Syntax
- If a Java class is named
Printer
, the source file must be saved as Printer.java. - A syntax error, such as in
System.outt.println("Hello");
, prevents the program from compiling.
Java Output Basics
- To print a blank line in Java, use
System.out.println();
. -
System.out.print("The sum is "); System.out.println("7+3");
results in:The sum is 7+3
-
System.out.print("The sum is "); System.out.println(7+3);
outputs:The sum is 10
Numerical Operations and Errors
- Java rounds division, so
10/4
gives a result of 2 instead of the expected 2.5. - Floating-point arithmetic can yield unexpected results, as in the case of
0.1 + 0.1 + 0.1
, giving 0.30000000000000004. - Adding two large integers,
2000000000 + 2000000000
, can lead to an overflow, resulting in -294967296.
Java Compilation and Execution
- A java compiler converts Java source code into byte code.
- A java virtual machine is necessary to run the byte code.
- The Java programming language is about 20 years old, with its current major version being 9.
Structural Elements of a Java Program
- Java programming typically involves a class containing multiple methods.
- The Java Virtual Machine identifies the method to execute first based on the main method.
Data Types and Errors
- A sequence of characters in quotes is called a String.
- Missing quotation marks in
System.out.println(Hi there!);
will cause a compile-time error. - Exceptions in Java represent run-time errors.
- Logic errors occur when the program runs incorrectly, such as printing "hello" instead of "goodbye".
Computer Components and IDE Features
- The CPU is responsible for executing instructions in a computer.
- An Integrated Development Environment (IDE) may include features like editors, code formatters, debuggers, and compilers.
- To fix indentation in Dr.Java, select all text and press Tab.
Interactive Results in Dr.Java
- In Dr.Java's Interactions Pane:
- Typing
47/10
yields 4. -
1 + .1
results in 1.1. -
"cat".length
returns 3. -
"13" + "14"
concatenates to 1314.
- Typing
Dr.Java Preferences
- Dr.Java's preferences allow customization, including right margin position, font size and color, and displaying line numbers.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge with these flashcards from CSE 174, focusing on key concepts related to compilers and Java programming. Each card presents a crucial term or concept to enhance your understanding of the material covered in Week 1. Ideal for revision and self-assessment.