Mid Term Study Concepts Flashcards

1
Q

JDK (Java Developer Kit) is:

A

-What we use to program Java
-Comes with the compiler(Javac.exe) and the JRE
-The compiler converts source code into byte code
-Source code is the code programmers type into VS code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

JRE (Java Runtime Environment) contains:

A

-Ships with every operating system out there
-Contains the JVM and Java API

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JVM (Java Virtual Machine or java.exe) is:

A

-Converts byte code into machine code
-Exists on many operating systems, allowing java to be cross platform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Java API is:

A

-A library of java code that we can use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Primitive variables are:

A

Variables that store values and start with lower case(int, boolean, double, float)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Reference variables are:

A

-Reference variables store a reference to an object in the heap

-Anytime a object or array is referenced in a method, it is referenced using a reference variable

-String is a reference variable(Reference variables typically start with capital)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Local variable is:

A

-any variable declared in a method

-stored in the stack frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Class variables also known as ____ variables, declared with the _____ prefix

A

Class variables also known as static variables, declared with the static prefix
example: public static int age = 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

These are static/instance variables from the Class BankAccount:

private static double interest = 4.25;
private double balance = 0;

Why is interest static and balance not, why are they both private?

A

-Static variables should be values that apply to all objects of a class without being changed, while instance variables can expect to be different from object to object.

-The principle of encapsulation to protect the data means the static and instance variables should be private(inaccessible unless using a getter/accessor).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Arrays are:

A

An object, so their data is stored in the heap while a reference exists on its stack frame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Below is an array of objects, explain where in the memory everything is stored:
(Assume student1 and 2 are previously declared)

Student [ ] arr = {student1, student2}

A

Student [] arr is a reference, with data in the heap. In the heap each of Student [] arr’s indexes store references to the student objects which are also in the heap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JOptionPane Syntax:

A

String name = JOptionPane.showInputDialog(“What is your name?”);

System.out.println(“Hello “+name);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How many classes can be made from objects? How about vice versa?

A

Can’t make classes from objects but the opposite is an infinite amount

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the four types of access modifiers?

A

public, private, protected, default

-all these are case sensitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Static is ___ ______

A

Static is not OOP.

-all objects would share the same values for their static variables. Instance variables allows for objects to be distinct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the principles of OOP?

A

Encapsulation: Protect instance variables and only allow them to be accessed or modified through the use of getter or setter methods

Abstraction: managing complexity by hiding unnecessary details from the user. It allows programmers to focus on the essential features of an object, rather than its internal workings.

17
Q

What are Special classes and Regular classes?

A

Special Classes:Classes with a main method. Are passed into JVM to run the program

Regular Classes: Don’t need a main method

18
Q

Where do classes typically exist?

A

Stored as a .java file on the hard drive

19
Q

Difference between a class and a object?

A

A Class is like a blueprint, tells the JVM how to create an object.

An Object is an instance of a class.

20
Q

An object is a self sustained collection of what two things?

A

Instance variables and methods

21
Q

What problem did OOP solve?

A

OOP solved the GUI problem(Allow for better creation of GUIs) and allowed you to reuse code.

22
Q

Create an Object Constructors for the class called Object:

A

Constructors for the class Object would be the class’s method that would have the same name as the class in this example they would be Object() or Object(String name) or Object(int age), etc…

23
Q

What are overloaded methods/constructors?

A

Overloaded method is when a method has the same name as another method but just takes different arguments or returns a different data type

24
Q

Scope of these variables:

Local, Instance, Static(class)

A

local - method level scope
instance - class level scope
static - class level scope

25
Q

How can you access an instance variable and a static variable?

A

Instance variables would require having an object and using a accessor to return the value

Static variables don’t require you to create a class to access them. Simply use the class name(Example: Classname is Object)
int staticvalue = Object.staticvariable

26
Q

When a program starts what happens?

A

-The Class Loader will load the .class file into the method section of memory
-The JVM will begin running code in the main method first

27
Q

What part of the memory deals with bytecode?

A

method area

28
Q

Why do we not have to JOptionPane obj = new JOptionPane or the same for parseInt, to use the showInputDialog or parseInt class methods?

Integer.parseInt()

A

Because they are static methods

29
Q

Why should we use this.variable syntax?

A

If two variable names collide, the JVM will always choose the variable with the smallest scope (usually the local variable).

The this. keyword allows you to force the JVM to use the instance variable instead

They picked the word this because we are referring to instance variables and methods in this object

30
Q

The Stack holds:

A

Contains local variables, when a method is entered a new stack frame is created, and when a method is exited the current stack frame is destroyed.

31
Q

The Heap stores:

A

Objects are stored in the heap, including arrays as they are considered objects

-When an array is first declared in the method, it is created in the heap, where a reference is created of that array in the current stack frame.

32
Q

The Method stores:

A

Where .class files are loaded when the JVM starts the program. Holds all the information about classes.

33
Q

What happens when the program runs into an Exception?

A

The JVM will look for a try/catch to handle the exception. If it cannot find one in the current stack frame it will go to the next highest stack frame looking for a method with a try/catch. If there are no approriate tries/catches, it terminates the program.

34
Q

What is a Stack?

A

A data structure that operates on the principle of LIFO “Last in, First out”.

Has methods: push(), pop(), peek(), size()

35
Q

What is an enum data type?

public enum AnimalType {
ELEPHANT, LION, TIGER
}

Animal a1 = new Animal(AnimalType.LION);

A

Enums (short for enumerations) in Java are a special data type that enables for variables to be a set of predefined constants. Enums are used to define a collection of constant values in a more readable and organized manner

36
Q

What is a final data type?

A

It can be used on instance variables and also the class itself. Makes the instance variables and the class immutable.