java ch4

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/59

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:56 PM on 2/9/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

60 Terms

1
New cards

Each class you create becomes

a new type that can be used to declare variables and create objects.

2
New cards

You can declare new classes as needed; this is one reason Java is known as

an extensible language.

3
New cards

Class Declaration:

Each ______ that begins with the access modifier public must be stored in a file that has the same name as the class and ends with the .java filename extension.

4
New cards

Every class declaration contains

keyword class followed immediately by the class’s name.

5
New cards

Camel Case Naming:

Class names begin with an uppercase letter, and method and variable names begin with a lowercase letter.

6
New cards

An object has attributes that are implemented as

instance variables and carried with it throughout its lifetime.

7
New cards

Instance variables exist before methods are called on an

object, while the methods are executing and after the methods complete execution.

8
New cards

A class normally contains one or more methods that manipulate the

instance variables that belong to particular objects of the class.

9
New cards

Variables or methods declared with access modifier private are

accessible only to methods of the class in which they’re declared.

10
New cards

Parameters are declared in a comma-separated parameter list, which is located inside the

parentheses that follow the method name in the method declaration. Multiple parameters are separated by commas.

11
New cards

Variables declared in the body of a particular method are local variables and can be used

only in that method. When a method terminates, the values of its local variables are lost.

12
New cards

The method’s return type specifies the

type of data returned to a method’s caller.

13
New cards

Keyword void indicates that a method will perform a task but

will not return any information. When a method that specifies a return type other than ____ is called and completes its task, the method must return a result to its calling method.

14
New cards

Empty parentheses following a method name indicate that the

method does not require any parameters to perform its task.

15
New cards

The return statement passes a

value from a called method back to its caller.

16
New cards

Classes often provide public methods to allow the class’s clients to

set or get private instance variables. The names of these methods need not begin with set or get, but this naming convention is recommended.

17
New cards

Driver Class AccountTest:

A class that creates an object of another class, then calls the object’s methods.

18
New cards

A class instance creation expression begins with keyword

new and creates a new object.

19
New cards

A constructor is similar to a method but is called implicitly

by the new operator to initialize an object’s instance variables at the time the object is created.

20
New cards

To call a method of an object,

follow the object name with a dot separator, the method name and a set of parentheses containing the method’s arguments.

21
New cards

Every instance variable has a default initial value, a value provided by Java when you do not specify the instance variable’s initial value.

The default value for an instance variable of type String is

null.

22
New cards

A method call supplies values, known as

arguments, for each of the method’s parameters. Each argument’s value is assigned to the corresponding parameter in the method header.

23
New cards

The javac command can

compile multiple classes at once.

24
New cards

If the directory containing the app includes only one app’s files, you can compile all of its classes with the command

javac *.java. The asterisk (*) in *.java indicates that all files in the current directory ending with the filename extension “.java” should be compiled.

25
New cards

In the UML, each class is modeled in a

class diagram as a rectangle with three compartments.

26
New cards

UML Top Compartment:

The ___ one contains the class’s name centered horizontally in boldface.

27
New cards

UML Middle Compartment:

The ___ compartment contains the class’s attributes, which correspond to instance variables in Java.

28
New cards

UML Bottom Compartment:

The bottom compartment contains the class’s operations, which correspond to methods and constructors in Java.

29
New cards

The UML represents instance variables as an

attribute name, followed by a colon and the type.

30
New cards

Private attributes are preceded by a

minus sign (–) in the UML.

31
New cards

A plus sign (+) in front of the operation name indicates that the operation is

a public one in the UML.

32
New cards

The UML models operations by listing the

operation name followed by a set of parentheses.

33
New cards

The UML indicates an operation’s return type by

placing a colon and the return type after the parentheses following the operation name. UML class diagrams do not specify return types for operations that do not return values.

34
New cards

The UML models a parameter of an operation by

listing the parameter name, followed by a colon and the parameter type between the parentheses after the operation name.

35
New cards

You must call most methods other than

main explicitly to tell them to perform their tasks.

36
New cards

A key part of enabling the JVM to locate and call method main to begin the app’s execution is the static keyword,

which indicates that main is a ___ method that can be called without first creating an object of the class in which the method is declared.

37
New cards

Most classes you’ll use in Java programs must be

imported explicitly.

38
New cards

There’s a special relationship between classes that are compiled in the same directory.

By default, such classes are considered to be in the same package, known as the default package. Classes in the same package are implicitly imported into the source-code files of other classes in that package.

39
New cards

An import declaration is not required when

one class in a package uses another in the same package, or if you always refer to a class with its fully qualified class name, which includes its package name and class name.

40
New cards

Each class you declare can optionally provide a constructor with

parameters that can be used to initialize an object of a class when the object is created. Java requires a constructor call for every object that’s created.

41
New cards

Constructors can specify parameters but

not return types.

42
New cards

If a class does not define constructors, the compiler provides a

default constructor with no parameters, and the class’s instance variables are initialized to their default values.

43
New cards

There’s No Default Constructor in a Class That Declares a Constructor:

If you declare a constructor for a class, the compiler will not create a default constructor for that class.

44
New cards

To distinguish a constructor from a class’s operations, the UML places

the word “constructor” between guillemets (« and ») before the constructor’s name.

45
New cards

A floating-point number is a number with a decimal point. Java provides two primitive types for storing floating-point numbers in memory:

float and double.

46
New cards

Variables of type float represent

single-precision floating-point numbers and have seven significant digits.

47
New cards

Variables of type double represent

double-precision floating-point numbers. These require twice as much memory as the other variables and provide 15 significant digits—approximately double the precision of float variables.

48
New cards

Scanner method nextDouble returns a

double value.

49
New cards

The format specifier %f is used to

output values of type float or double.

50
New cards

The format specifier %.2f specifies that

two digits of precision should be output to the right of the decimal point in the floating-point number.

51
New cards

even though its possible to do so, do not call a methods

from constructors.

52
New cards

private variables can only be accessed within the same class. However, it is possible to access them if

we provide public get and set methods.

53
New cards

The get method:

returns the variable value.

54
New cards

the set method:

assigns the variable value.

55
New cards

What's the purpose of keyword new? Explain what happens when you use it.

The keyword new is used to create an object/instance of a class in the program. When it is used, it tells Java to allocate memory to store the newly created object.

56
New cards

What is the difference between constructors and methods?

The difference is that a constructor is used to implicitly initialize an object’s instance variables at the time the new operator creates the object, while methods define the behavior or actions an object can perform after it has already been initialized.

57
New cards

What does the keyword private preceding the most instance-variable declarations indicate?

If the keyword private is used on a variable declaration, it will only be accessible within the method in which it was declared.

58
New cards

Most classes need to be imported before they can be used in an app. Why is every app allowed to use classes System and String without first importing them?

You do not need to import the classes System and String because they are part of the default Java package and are imported into the source code of files by default.

59
New cards

Explain how a program could use class Scanner without importing it.

You can use Scanner without explicitly importing the class by typing java.util.Scanner, which is a fully qualified class name.

60
New cards

Explain the disadvantage of creating a class that has no set and get methods for an instance variable.

The disadvantage of not using the get and set methods is because you can control how those instance variables are changed by putting security measures into the methods. you also can't access private instance variables from other class methods.

Explore top flashcards