Questions and Answers
public class HelloWorld is an example of a ______________ in a Java program.
class header
One of the uses of a class is to serve as a container for an application.
True
A Java program does not need a class definition.
False
You may create more than one class in a file, but you may have only one _________ class per Java file.
Signup and view all the answers
When a Java file has a public class, the name of the public class must be the same as the name of the file (without the .java extension).
Signup and view all the answers
Java is not a case sensitive language.
Signup and view all the answers
public static void main(String[] args) is an example of a ______________ in a Java program.
Signup and view all the answers
A _________ can be thought of as a group of one or more programming statements that collectively has a name.
Signup and view all the answers
The __________ method is the starting point of an application.
Signup and view all the answers
*System.out.prinln("Hello world"); In programming terms, the group of characters inside the quotation marks is called a _______________.
Signup and view all the answers
Every Java application program must have a method named ____________.
Signup and view all the answers
The Java ________ is a collection of pre-written classes and methods for performing specific operations.
Signup and view all the answers
The console window that starts a Java application is typically known as the _________________.
Signup and view all the answers
The term API stands for _______________________.
Signup and view all the answers
The standard input device is typically the ______________.
Signup and view all the answers
*System.out.prinln("Hello world"); In programming terms, the group of characters inside the parentheses is called an _______________.
Signup and view all the answers
The print statement works very similarly to the println statement. However, the print statement does not put a newline character at the end of the output.
Signup and view all the answers
Study table 2-2 on page 40 just in case any of these are on the test. Type yes if you get this card.
Signup and view all the answers
A __________ is a named storage location in the computer's memory. A ________ is a value that is written into the code of a program.
Signup and view all the answers
Variables are classified according to their ______, which determines the kind of data that may be stored in them.
Signup and view all the answers
When the + operator is used with strings, it is known as the _____________________________.
Signup and view all the answers
When quotation marks are placed around a variable name it becomes a string literal and will not display correctly.
Signup and view all the answers
Placing double quotation marks around anything that is not intended to be a string literal will create an error of some type.
Signup and view all the answers
Character literals are enclosed in _________; string literals are enclosed in __________.
Signup and view all the answers
A ________ is a value that is written into the code of a program.
Signup and view all the answers
An ________________ is a programmer-defined name that represents some element of a program. Variable names and class names are examples of these.
Signup and view all the answers
______________________ means you get an understanding of what the program is doing just by reading the code.
Signup and view all the answers
An identifier may only contain: letters a-z or A-Z, the digits 0-9, underscores, or dollar signs. And the first character cannot be a digit.
Signup and view all the answers
Primitive data types are built into the Java language and are not derived from classes.
Signup and view all the answers
What are the 8 Java primitive data types?
Signup and view all the answers
You can force an integer literal to be treated as a long by suffixing it with the letter ___.
Signup and view all the answers
You cannot embed commas in numeric literals.
Signup and view all the answers
In Java, there are two data types that can represent floating-point numbers. They are ________ and ________.
Signup and view all the answers
The float data type can store a floating-point number with ___ digits of accuracy.
Signup and view all the answers
The double data type can store a floating-point number with ___ digits of accuracy.
Signup and view all the answers
Read and understand floating-point literals on page 51. This info will probably be on the test. Type yes if you get this card.
Signup and view all the answers
The boolean data type allows you to create variables that may hold one of two possible values: ________ or _________.
Signup and view all the answers
The modulus operator (%) returns the remainder of a division operation involving two integers.
Signup and view all the answers
The following code will result in a value of 2: double number = 5 / 2;
Signup and view all the answers
When values of the byte or short data types are used in arithmetic expressions, they are temporarily converted to int values.
Signup and view all the answers
The _________ key word can be used in a variable declaration to make the variable a named constant.
Signup and view all the answers
A named constant is a variable whose value is read-only and cannot be changed during the execution of the program.
Signup and view all the answers
Java has no primitive data type that holds a series of characters. The String class from the Java standard library is used for this purpose.
Signup and view all the answers
_________-type variables hold the actual data items with which they are associated.
Signup and view all the answers
A ____________-type variable does not hold the actual data item it is associated with, but holds the memory address of the data item it is associated with.
Signup and view all the answers
Anytime you write a string literal in your program, Java will create a String object in memory to hold it.
Signup and view all the answers
A variable's ________ is the part of the program that has access to the variable.
Signup and view all the answers
Variables that are declared inside a method are called ______ variables.
Signup and view all the answers
Which Scanner class method reads an int?
Signup and view all the answers
If you use nextLine after a nextInt or nextDouble the enter key stored in the keyboard buffer will cause the nextLine method to be skipped.
Signup and view all the answers
A ___________ is a small graphical window that displays a message to the user or requests input.
Signup and view all the answers
The System.out.printf method allows you to format output in a variety of ways.
Signup and view all the answers
The String.__________ method allows you to format a string without displaying it. The string can be displayed at a later time.
Signup and view all the answers
Study Notes
Java Classes and Methods
- Class header syntax:
public class ClassName
. - A class serves as a container for an application and must be defined.
- Only one public class is permitted per Java file, matching the file name.
- The main entry point for a Java application is the method:
public static void main(String[] args)
.
Input and Output
- The console window where Java applications display output is the standard output device.
- The
System.out.println
method outputs a message followed by a newline;System.out.print
does not add a newline. - String literals are represented by characters inside double quotes, e.g.,
"Hello world"
; argument refers to the data given to methods.
Data Types and Variables
- Eight primitive data types: byte, short, int, long, float, double, boolean, char.
- Variable types classified by data type, which dictates the kind of data supported.
- A literal is a fixed value used directly in code, while a variable is a named storage location in memory.
Operators
- The
+
operator, when used with strings, enables string concatenation. - The modulus operator (%) finds the remainder of an integer division.
- Integer literals can be suffixed with
L
to treat them as longs.
Constants and Identifiers
- The keyword
final
creates a named constant, which is a variable whose value cannot change. - Identifiers can only contain letters, digits, underscores, or dollar signs, beginning with a letter or underscore.
Boolean Logic and Conditions
- The boolean data type includes two values: true and false.
- Arithmetic operations on byte or short types convert them to int types, ensuring compatibility in expressions.
Scopes and Local Variables
- Scope indicates where a variable can be accessed within the program.
- Local variables are those declared within a method and only accessible within that method's context.
Input Handling with Scanner
- To read integers, the method used is
nextInt()
. - Using
nextLine()
afternextInt()
ornextDouble()
may cause input issues due to leftover newline characters in the buffer.
Dialog Boxes and String Formatting
- A dialog box presents a message or prompts user input in a small graphical window.
- The
System.out.printf
method offers advanced formatting options for output.
Programming Best Practices
- Self-documenting programs enhance understanding through clear, descriptive code.
- Immersive understanding comes from reading and grasping floating-point literals and other code concepts.
Overall Understanding
- Java is case-sensitive and requires proper syntax for effective code compilation.
- Commas cannot be included in numerical literals to prevent errors.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of Java programming with these flashcards focused on Chapter 2. Explore essential concepts such as class headers and the importance of class definitions in Java applications. Perfect for reinforcing your understanding of fundamental Java principles.