Mid Term Study Concepts Flashcards
JDK (Java Developer Kit) is:
-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
JRE (Java Runtime Environment) contains:
-Ships with every operating system out there
-Contains the JVM and Java API
JVM (Java Virtual Machine or java.exe) is:
-Converts byte code into machine code
-Exists on many operating systems, allowing java to be cross platform
Java API is:
-A library of java code that we can use
Primitive variables are:
Variables that store values and start with lower case(int, boolean, double, float)
Reference variables are:
-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)
Local variable is:
-any variable declared in a method
-stored in the stack frame
Class variables also known as ____ variables, declared with the _____ prefix
Class variables also known as static variables, declared with the static prefix
example: public static int age = 5;
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?
-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).
Arrays are:
An object, so their data is stored in the heap while a reference exists on its stack frame.
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}
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.
JOptionPane Syntax:
String name = JOptionPane.showInputDialog(“What is your name?”);
System.out.println(“Hello “+name);
How many classes can be made from objects? How about vice versa?
Can’t make classes from objects but the opposite is an infinite amount
What are the four types of access modifiers?
public, private, protected, default
-all these are case sensitive
Static is ___ ______
Static is not OOP.
-all objects would share the same values for their static variables. Instance variables allows for objects to be distinct.
What are the principles of OOP?
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.
What are Special classes and Regular classes?
Special Classes:Classes with a main method. Are passed into JVM to run the program
Regular Classes: Don’t need a main method
Where do classes typically exist?
Stored as a .java file on the hard drive
Difference between a class and a object?
A Class is like a blueprint, tells the JVM how to create an object.
An Object is an instance of a class.
An object is a self sustained collection of what two things?
Instance variables and methods
What problem did OOP solve?
OOP solved the GUI problem(Allow for better creation of GUIs) and allowed you to reuse code.
Create an Object Constructors for the class called Object:
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…
What are overloaded methods/constructors?
Overloaded method is when a method has the same name as another method but just takes different arguments or returns a different data type
Scope of these variables:
Local, Instance, Static(class)
local - method level scope
instance - class level scope
static - class level scope