Podcast
Questions and Answers
public class HelloWorld is an example of a ______________ in a Java program.
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.
One of the uses of a class is to serve as a container for an application.
True (A)
A Java program does not need a class definition.
A Java program does not need a class definition.
False (B)
You may create more than one class in a file, but you may have only one _________ class per Java file.
You may create more than one class in a file, but you may have only one _________ class per Java file.
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).
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).
Java is not a case sensitive language.
Java is not a case sensitive language.
public static void main(String[] args) is an example of a ______________ in a Java program.
public static void main(String[] args) is an example of a ______________ in a Java program.
A _________ can be thought of as a group of one or more programming statements that collectively has a name.
A _________ can be thought of as a group of one or more programming statements that collectively has a name.
The __________ method is the starting point of an application.
The __________ method is the starting point of an application.
*System.out.prinln("Hello world"); In programming terms, the group of characters inside the quotation marks is called a _______________.
*System.out.prinln("Hello world"); In programming terms, the group of characters inside the quotation marks is called a _______________.
Every Java application program must have a method named ____________.
Every Java application program must have a method named ____________.
The Java ________ is a collection of pre-written classes and methods for performing specific operations.
The Java ________ is a collection of pre-written classes and methods for performing specific operations.
The console window that starts a Java application is typically known as the _________________.
The console window that starts a Java application is typically known as the _________________.
The term API stands for _______________________.
The term API stands for _______________________.
The standard input device is typically the ______________.
The standard input device is typically the ______________.
*System.out.prinln("Hello world"); In programming terms, the group of characters inside the parentheses is called an _______________.
*System.out.prinln("Hello world"); In programming terms, the group of characters inside the parentheses is called an _______________.
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.
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.
Study table 2-2 on page 40 just in case any of these are on the test. Type yes if you get this card.
Study table 2-2 on page 40 just in case any of these are on the test. Type yes if you get this card.
A __________ is a named storage location in the computer's memory. A ________ is a value that is written into the code of a program.
A __________ is a named storage location in the computer's memory. A ________ is a value that is written into the code of a program.
Variables are classified according to their ______, which determines the kind of data that may be stored in them.
Variables are classified according to their ______, which determines the kind of data that may be stored in them.
When the + operator is used with strings, it is known as the _____________________________.
When the + operator is used with strings, it is known as the _____________________________.
When quotation marks are placed around a variable name it becomes a string literal and will not display correctly.
When quotation marks are placed around a variable name it becomes a string literal and will not display correctly.
Placing double quotation marks around anything that is not intended to be a string literal will create an error of some type.
Placing double quotation marks around anything that is not intended to be a string literal will create an error of some type.
Character literals are enclosed in _________; string literals are enclosed in __________.
Character literals are enclosed in _________; string literals are enclosed in __________.
A ________ is a value that is written into the code of a program.
A ________ is a value that is written into the code of a program.
An ________________ is a programmer-defined name that represents some element of a program. Variable names and class names are examples of these.
An ________________ is a programmer-defined name that represents some element of a program. Variable names and class names are examples of these.
______________________ means you get an understanding of what the program is doing just by reading the code.
______________________ means you get an understanding of what the program is doing just by reading the code.
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.
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.
Primitive data types are built into the Java language and are not derived from classes.
Primitive data types are built into the Java language and are not derived from classes.
What are the 8 Java primitive data types?
What are the 8 Java primitive data types?
You can force an integer literal to be treated as a long by suffixing it with the letter ___.
You can force an integer literal to be treated as a long by suffixing it with the letter ___.
You cannot embed commas in numeric literals.
You cannot embed commas in numeric literals.
In Java, there are two data types that can represent floating-point numbers. They are ________ and ________.
In Java, there are two data types that can represent floating-point numbers. They are ________ and ________.
The float data type can store a floating-point number with ___ digits of accuracy.
The float data type can store a floating-point number with ___ digits of accuracy.
The double data type can store a floating-point number with ___ digits of accuracy.
The double data type can store a floating-point number with ___ digits of accuracy.
Read and understand floating-point literals on page 51. This info will probably be on the test. Type yes if you get this card.
Read and understand floating-point literals on page 51. This info will probably be on the test. Type yes if you get this card.
The boolean data type allows you to create variables that may hold one of two possible values: ________ or _________.
The boolean data type allows you to create variables that may hold one of two possible values: ________ or _________.
The modulus operator (%) returns the remainder of a division operation involving two integers.
The modulus operator (%) returns the remainder of a division operation involving two integers.
The following code will result in a value of 2: double number = 5 / 2;
The following code will result in a value of 2: double number = 5 / 2;
When values of the byte or short data types are used in arithmetic expressions, they are temporarily converted to int values.
When values of the byte or short data types are used in arithmetic expressions, they are temporarily converted to int values.
The _________ key word can be used in a variable declaration to make the variable a named constant.
The _________ key word can be used in a variable declaration to make the variable a named constant.
A named constant is a variable whose value is read-only and cannot be changed during the execution of the program.
A named constant is a variable whose value is read-only and cannot be changed during the execution of the program.
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.
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.
_________-type variables hold the actual data items with which they are associated.
_________-type variables hold the actual data items with which they are associated.
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.
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.
Anytime you write a string literal in your program, Java will create a String object in memory to hold it.
Anytime you write a string literal in your program, Java will create a String object in memory to hold it.
A variable's ________ is the part of the program that has access to the variable.
A variable's ________ is the part of the program that has access to the variable.
Variables that are declared inside a method are called ______ variables.
Variables that are declared inside a method are called ______ variables.
Which Scanner class method reads an int?
Which Scanner class method reads an int?
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.
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.
A ___________ is a small graphical window that displays a message to the user or requests input.
A ___________ is a small graphical window that displays a message to the user or requests input.
The System.out.printf method allows you to format output in a variety of ways.
The System.out.printf method allows you to format output in a variety of ways.
The String.__________ method allows you to format a string without displaying it. The string can be displayed at a later time.
The String.__________ method allows you to format a string without displaying it. The string can be displayed at a later time.
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.