Chapter 3 - Using Classes and Objects Flashcards
What are the chapter objectives?
1- Discuss the creation of objects and the use of object reference variables.
2- Explore the services provided by the String class.
3- Explore the services provided by the Random and Math classes.
4- Discuss ways to format output.
5- Introduce enumerated types.
6- Discuss wrapper classes and the concept of autoboxing.
7- Introduce the JavaFX API.
8- Explore classes used to represent shapes.
What is a fundamental part of object-oriented software and sets the stage for writing classes of our own?
Knowing how to use classes (+predefined) and objects (we created from them) for the services they provide. Using classes and objects to manipulate character strings, produce random numbers, perform complex calculations, and format output.
What’s the difference between a primitive variable and an object variable?
An object variable does not hold an object itself but it holds the address of an object. The String variable holds a reference to a String object.
Why is it important to always initialize a variable (assign a value) before using it?
Because if you don’t then JAVA will assign a default variable.
What do you call it when two names (object variables) refer to the same object? Can multiple reference variables refer to the same object?
With object variables they reference the same object and are called aliases. Integer variables take on the object and not reference it so a num2 = num1 keeps two separate objects while name2 = name1 removes the reference and references to the object originally referenced by name 1. If we change the referenced object for name1, it will also change the output for name2. Yes.
What happens when an object loses all references to it by variables (perhaps by reassignment)?
That object can no longer contribute to the program and the program can no longer invoke its methods or use its variables. At this out the object is called GARBAGE b/c it serves no useful purpose.
What does automatic garbage collection mean?
After an object loses all references to it and becomes garbage, Java performs automatic garbage collection and removes those objects and returns their memory to the stream for future use.
What does it mean when we say a string object (once created) is immutable?
Once a String object is created it’s value cannot be lengthened or shortened, nor can any of its characters change. However there are several Methods in the string Class return a NEW string Object that are the result of modifying the original string’s value.
What is a Java API?
It’s a Java Application Programming Interfaces (API)s. It’s a standard class library, a set of classes (each contains methods) programmers like to use. Although programmers think classes are part of the language but are not technically part of the language.
ITS IMPORTANT TO KNOW HOW TO GET MORE INFORMATION about Java API classes (this is where you use the online documentation).
How are java files shared?
How do you create these .jar files?
We are the high priests of technology.
You have to create a java archive file, that zips multiple java CLASS files. Most programs will have multiple java files in a .jar file.
The files you share are compiler files javac.exe and interpreter files java.exe
Class is the executable file (the interpreter reads). The compiler takes the .java file and converts it to .class file using the compiler. .jar is a collection of .class files. The .jar file goes through the interpreter java.exe to program execution.
Why should you be focusing on the principles of JAVA?
What are procedural vs. object vs. declarative vs. functional languages?
Because you might use a different object oriented language.
procedural language is python (or C), object is Java, declarative are AIs, functional languages are math related.
What is a JVM (JRE)? What is the point of creating this virtual machine?
It is a Java Virtual Environment (JRE - Java Runtime Environment). You have a consistent sharable file but a little slower. The tradeoff is portability.
What do you call the groups of classes from the Java standard class library?
Packages (each class is a part of a particular package).
What package is the string class, system class, and Scanner class part of?
String and system class are part of the java.lang package. Scanner is part of the java.util package.
Why do we use an import declaration?
It’s to save you from having to define the package each time you use the scanner. Instead you can import it once in the beginning.
For example we could say java.util.Scanner each time we want to use the Scanner class. ON THE OTHER HAND if we just say import java.util.Scanner ; we can then use Scanner after that.
import java.util.Scanner ;