Java Chapter 2 Flashcards
53 Questions
100 Views

Java Chapter 2 Flashcards

Created by
@HandsomeVariable

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.

<p>public</p> 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).

<p>True</p> Signup and view all the answers

Java is not a case sensitive language.

<p>False</p> Signup and view all the answers

public static void main(String[] args) is an example of a ______________ in a Java program.

<p>method header</p> 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.

<p>method</p> Signup and view all the answers

The __________ method is the starting point of an application.

<p>main</p> 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 _______________.

<p>string literal</p> Signup and view all the answers

Every Java application program must have a method named ____________.

<p>main</p> Signup and view all the answers

The Java ________ is a collection of pre-written classes and methods for performing specific operations.

<p>API</p> Signup and view all the answers

The console window that starts a Java application is typically known as the _________________.

<p>standard output device</p> Signup and view all the answers

The term API stands for _______________________.

<p>application programmer interface</p> Signup and view all the answers

The standard input device is typically the ______________.

<p>keyboard</p> Signup and view all the answers

*System.out.prinln("Hello world"); In programming terms, the group of characters inside the parentheses is called an _______________.

<p>argument</p> 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.

<p>True</p> 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.

<p>yes</p> 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.

<p>variable, literal</p> Signup and view all the answers

Variables are classified according to their ______, which determines the kind of data that may be stored in them.

<p>data type</p> Signup and view all the answers

When the + operator is used with strings, it is known as the _____________________________.

<p>string concatenation operator</p> 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.

<p>True</p> 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.

<p>True</p> Signup and view all the answers

Character literals are enclosed in _________; string literals are enclosed in __________.

<p>single quotes, double quotes</p> Signup and view all the answers

A ________ is a value that is written into the code of a program.

<p>literal</p> 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.

<p>identifier</p> Signup and view all the answers

______________________ means you get an understanding of what the program is doing just by reading the code.

<p>self-documenting programs</p> 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.

<p>True</p> Signup and view all the answers

Primitive data types are built into the Java language and are not derived from classes.

<p>True</p> Signup and view all the answers

What are the 8 Java primitive data types?

<p>byte, short, int, long, float, double, boolean, char</p> Signup and view all the answers

You can force an integer literal to be treated as a long by suffixing it with the letter ___.

<p>L</p> Signup and view all the answers

You cannot embed commas in numeric literals.

<p>True</p> Signup and view all the answers

In Java, there are two data types that can represent floating-point numbers. They are ________ and ________.

<p>float, double</p> Signup and view all the answers

The float data type can store a floating-point number with ___ digits of accuracy.

<p>7</p> Signup and view all the answers

The double data type can store a floating-point number with ___ digits of accuracy.

<p>15</p> 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.

<p>yes</p> Signup and view all the answers

The boolean data type allows you to create variables that may hold one of two possible values: ________ or _________.

<p>true, false</p> Signup and view all the answers

The modulus operator (%) returns the remainder of a division operation involving two integers.

<p>True</p> Signup and view all the answers

The following code will result in a value of 2: double number = 5 / 2;

<p>True</p> 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.

<p>True</p> Signup and view all the answers

The _________ key word can be used in a variable declaration to make the variable a named constant.

<p>final</p> 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.

<p>True</p> 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.

<p>True</p> Signup and view all the answers

_________-type variables hold the actual data items with which they are associated.

<p>primitive</p> 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.

<p>class</p> 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.

<p>True</p> Signup and view all the answers

A variable's ________ is the part of the program that has access to the variable.

<p>scope</p> Signup and view all the answers

Variables that are declared inside a method are called ______ variables.

<p>local</p> Signup and view all the answers

Which Scanner class method reads an int?

<p>nextInt()</p> 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.

<p>True</p> Signup and view all the answers

A ___________ is a small graphical window that displays a message to the user or requests input.

<p>dialog box</p> Signup and view all the answers

The System.out.printf method allows you to format output in a variety of ways.

<p>True</p> 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.

<p>format</p> 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() after nextInt() or nextDouble() 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.

Quiz Team

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.

More Quizzes Like This

Use Quizgecko on...
Browser
Browser