Java Building Blocks Flashcards Preview

Java OCA > Java Building Blocks > Flashcards

Flashcards in Java Building Blocks Deck (58)
Loading flashcards...
1
Q

class

A

A description of an object. A class in Java is defined in a source file with the .java extension and compiled into a file with the .class extension.

2
Q

object

A

A runtime instance of a class in memory

3
Q

members of a class

A

methods and fields

4
Q

Method Signature

A

The full declaration of a method

5
Q

/* */ vs. /** */

A

The first is a regular multiline comment, the second is a special Javadoc comment

6
Q

When you have two classes defined in the same java file, how many can be public?

A

1

7
Q

Java Virtual Machine (JVM)

A

Runs Java class files.

8
Q

main() method declaration

A

public static void main(String[] args)

9
Q

How to compile and run a program called Zoo.java

A

javac Zoo.java

java Zoo

10
Q

bytecode

A

Compiled Java code. Bytecode appears in files with the .class extension.

11
Q

access modifier

A

Defines what other code can refer to the code. Choices are private,
protected, public, and default (no modifier.)

12
Q

static

A
Binds a method or field to its class so it can be called by just the class name, as in, for example, Zoo.main(). Java doesn't need to create an object to call the main() method
Makes a variable shared across all instances of this class.
13
Q

What type does java read in arguments as by default?

A

String

14
Q

package

A

A grouping of classes, interfaces, enumerations, and annotated types.

15
Q

What is the package that is automatically imported?

A

java.lang

16
Q

default package

A

An unnamed package used when no package statement is present in the code. This is a special unnamed package that you should use only for throwaway code. In real life, always name your packages to avoid naming conflicts and to allow others to reuse your code.

17
Q

JAR file

A

Like a zip file of mainly Java class files.

18
Q

What return type does a constructor have?

A

None! Not even void

19
Q

Instance Initializers

A

Code blocks (between braces { }) outside of methods

20
Q

Code Block

A

Code between { }

21
Q

When creating a new object, when does the constructor run?

A

After all fields and instance initializer blocks have run

22
Q

Two types of data

A

Primitive types
and
Reference types

23
Q

byte type

A

8-bit integral value (whole number)

24
Q

short type

A

16-bit integral value (whole number)

25
Q

int type

A

32-bit integral value (whole number)

26
Q

long type

A

64-bit integral value (whole number) (should have a capital L at the end e.g. 463728642L)

27
Q

float type

A

32-bit floating point value (could be decimal) (must have the letter f after the number, e.g. 100.5f)

28
Q

double

A

64-bit floating point value (could be decimal)

29
Q

char type

A

16-bit Unicode value

30
Q

literal

A

A numeric, character, boolean, or String value that is typed into the code.

31
Q

How to specify using octal notation

A

prefix the number with 0 e.g. 017

32
Q

How to specify using hexadecimal notation

A

prefix the number with 0x e.g. 0xFF

33
Q

How to specify using binary notation

A

prefix the number with 0b e.g 0b10

34
Q

What can you use to separate a number into sections to make it easier to read?

A

Underscores

1000000 = 1_000_000

(cannot have _ at the beginning, ending, or right before or after a decimal point)

35
Q

Reference Type

A

Basically an object, conceptually kinda like a pointer

36
Q

What can be assigned the value “null”?

A

Reference types

37
Q

Is String a primitive or a reference type?

A

Reference type

38
Q

What can an identifier be made up of?

A

letters, numbers, $, or _

note: cannot start with a number

39
Q

identifier

A

The name of a variable, method, class, interface, or enum.

40
Q

local variable

A

A variable defined within a method

41
Q

instance variable

A

Variable outside of a method (also called fields)

42
Q

class variable

A

An instance variable with the word “static” before it, shared across multiple objects

43
Q

Which variables are given default values and which are not?

A

Instance and class variables are, and local variables are not

44
Q

Default value of boolean

A

false

45
Q

Default value of byte, short, int and long

A

0

46
Q

Default value of float and double

A

0.0

47
Q

Default value of objects

A

null

48
Q

Order of elements in a class

A

1) Package Declaration
2) Import Statements
3) Class Declaration
4) Field Declarations and Method Declarations

49
Q

heap

A

Represents a large pool of unused memory allocated to your Java application. All
objects in Java reside in the heap memory.

50
Q

When is an object considered to be no longer reachable and thus eligible for garbage collection?

A

1) The object no longer has any references pointing to it
or
2) All references to the object have gone out of scope

51
Q

finalize()

A

The method that gets called if the garbage collector tries to collect an object.
Could run 0 or 1 time

52
Q

Why is Java secure?

A

It runs in a virtual machine, the JVM. This creates a sandbox that makes it hard for Java code to do evil things to the computer it is running on.

53
Q

What may a variable name begin with?

A

The name must begin with a letter, $, or _

54
Q

Default value of boolean

A

false

55
Q

Default value of byte, short, int and long

A

0

56
Q

Default value of float and double

A

0.0

57
Q

Default value of objects

A

null

58
Q

Benefits of Java

A

1) Object Oriented: Java is an object-oriented language, which means all code is defined in classes and most of those classes can be instantiated into objects.
2) Encapsulation: Java supports access modifiers to protect data from unintended access and modification.
3) Platform Independent: A key benefit is that Java code gets compiled once rather than needing to be recompiled for different operating systems.
4) Robust: Prevents memory leaks by doing its own garbage collecting.
5) Secure: Java code runs inside the JVM. This creates a sandbox that makes it hard for Java code to do evil things to the computer it is running on.