OCAJP Import

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/143

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:53 AM on 9/14/23
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

144 Terms

1
New cards
public void Constructor() is this a constructor?
NO constructors can't have ANY return types.
2
New cards
StringBuilder str \= "bla";
This doesn't compile. It needs to be new StringBuilder();
3
New cards
Arrays.asList()
returns a fixed size list. Anything that changes size causes an exception
4
New cards
System.out.println()
implicitly calls toString.
5
New cards
Java variable names can start with
a letter, an underscore, or a dollar sign.
6
New cards
local variables do not have
default values. MUST BE INITIALIZED
7
New cards
stringBuilder.toString()\==string. What does it evaluate to?
FALSE. The value on the right makes a NEW string. So they point to different objects in memory.
8
New cards
what is default in a subclasses constructor?
empty super method. It is not required.
9
New cards
multiple assignment syntax
multiple variables of the same type can be declared/initialized on the same line:
int x,y; or int x \= 1, y \= 2;
10
New cards
Java.time.LocalDate()
has a static method of(int year, java.time.Month month, int dayOfMonth). This returns DateTimeException if inputs messed up. 1 index instead of 0.

\
This cannot be done in the constructor. The .of method should be used.
11
New cards
When is a return required in a lambda?
When {} are used. Then a return is required.
12
New cards
What happens when two interfaces have the same method?
if the signature is the same, then the compiler throws an error. if it is overriden, then its fine.
13
New cards
What are the differences in comments Java?
/\** is a Javadoc
/* is a normal multiline comment
// is a single line comment
14
New cards
if the main method doesn't have static void main:
it is considered a normal method.
15
New cards
What happens when two packages have the same method?
if one is imported explicitly and one is imported with a wildcard(*) then the explicit one takes precedence. Otherwise a compiler error is thrown.
16
New cards
How can you tell if an object is reference or primitive?
If the first letter is capitalized. Primitives also always have a value whereas reference variables can be null(they don't point to any objects in memory).
17
New cards
what is an instance variable?
Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.
18
New cards
What is a class variable?
These are variables declared with in a class, outside any method, with the static keyword.
19
New cards
will double variables fail to compile if a .0 is missing?
No. This is due to autoboxing where it is automatically casted upwards.
20
New cards
is java a functional programming language?
No. It has aspects of a functional programming language but is more focused on being object oriented.
21
New cards
What are the 3 types of operators in order?
unary \> binary \> ternary
22
New cards
what are the precedence of java operators?
postfix increment and decrement: ++, --
prefix increment and decrement, and unary: ++, --, +, -, ~, !
multiplicative: *, /, %
additive: +, -
shift: <
23
New cards
Auto casting
you can implicitly cast objects upwards(one at a time). This is the first task to run in a line.

\
\*Also happens when shorts or chars are multiplied together. \*Means 5==5.0
24
New cards
What types are allowed in a switch statement?
int, byte, short, char, their wrappers, enums and strings. They HAVE to be literals or final variables.
EX:
1
or
final int season
25
New cards
what does for(;;) do?
Creates an infinite loop.
26
New cards
What is 1 + 2 + "c" equal to?
3c
27
New cards

When a string is given a new value, what happens?

it makes a new object because strings are IMMUTABLE

28
New cards
str.indexOf()
returns -1 or the index(starting at 0) of the current objects position.
29
New cards
str.substring(start, end)
returns the string starting at position (start) and ending at position (end-1) in the given string
Think of it as do not include the second argument in the string literal.
30
New cards
What are the possible behaviors when "\==" is used on strings?
this means they check if the strings REFERENCE the same object as the strings are reference variables. They do not actually contain the value.
31
New cards
What does int a[], b; initialize?
This makes an array of integers and a single integer.
32
New cards
What is an ArrayStoreException?
It is thrown when something is inserted into an Array which shouldn't be as the variable types don't match.
33
New cards
What does binary search return and what is required?
This requires the list to be sorted! If it is not sorted the output is not guaranteed.
If the element doesn't exist, then negative one is returned. If the element exists and the array is sorted, (-1*i)-1 is returned.
34
New cards
Would int[][] java \= new int[][]; compile?
NO. The first dimension has to be specified. If the initialization had the first dimension decided, then this statement would compile.
35
New cards
would new ArrayList(differentArrayList); compile?
Yes.
36
New cards
what do parse and valueOf do for wrapper classes?
parse converts a wrapper to a primitive and valueOf creates a wrapper from a primitive.
37
New cards
Can wrapper class conversion be done automatically?
Yes
38
New cards
How do you import time in java?
import java.time.*;
39
New cards
What is a LocalDate?
The LocalDate is just a date with no time zone information. An example of this is your birthday. It represents a single day regardless of time zone or time.
40
New cards
What does Month.SEPTEMBER convert to?
9
41
New cards
LocalTime.of()?
sets the local time. The minimum is hour and minute. Seconds and nanoseconds are optional
42
New cards
How does .sort work?
It sorts from the first letter onward. Ex: 0, 01, 1, 10
43
New cards
When compiling a class, what does the java command do?
The javac command compiles a .java file into a .class file, which is also technically bytecode.
44
New cards
What is autoboxing?
Autoboxing is when you have a subclass cast upwards. This can be done without an explicit cast.
45
New cards
What modifiers can Interfaces have?
public or abstract
46
New cards
Can we instantiate an interface by assigning it to an object?
Yes. An object can be cast to a superclass or inherited interface type without an explicit cast.

* NOTE: we can also cast interfaces to each other if they are both implemented.
47
New cards
When is an object eligible for garbage collection?
When it is out of scope, it has no value, or it is overwritten by assigning it the same value as another object.

* when a method takes an object, it can manipulate it as it takes its reference. Thus, it doesn’t go out of scope if it returns one and the returned value is saved.
48
New cards
What is a virtual method?
A virtual method is a method that can be overridden by a subclass

Connected to polymorphism. all non-final, non-static and non-private methods in Java are virtual
49
New cards
What is a LocalDateTime?
The LocalDateTime contains both a date and time but no time zone information. A good example of this is the stroke of midnight on New Year's Eve.
50
New cards
DateTimeException
This is an unchecked exception thrown when there are problems creating, querying and manipulating date-time objects
51
New cards
would new LocalDate() compile?
No. The time classes cannot have objects.
52
New cards
can a date formatter format format dateTime?
Yes. There is enough data for the date formatter.
53
New cards
Can a dateTime formatter work on date?
No! the compiler does not have enough data to fill the dateTime object and an exception is thrown.
54
New cards
What does DateTimeFormatter.ofLocalizedTime output?
This outputs just the time! It looks like it might format date but it is doing localized TIME.
55
New cards
What are public, no modifier, protected and private?
Public: accessible to anyone. Even in different packages. Protected: Accessible to any subclasses and classes in the same package. No modifier: this is only accessible to subclasses and itself. Private: Only usable in the class it is made in. Private cannot be assigned to instance variables.

\
NOTE: This can be confusing. Consider this: There are 2 classes in different packages. Their names are A and B. A has a method bla which is protected. B is initialized as: public class B extends A {} bla is not accessible when making a new object A. We would need to make an object of type B as that is the subclass.
56
New cards
Would _term or 1term compile?
_term. While names can contain numbers, they are not allowed to start with them. They can only start with _, $ and letters.
57
New cards
What is a vararg?
A vararg is the last parameter in a method. This can take in a list of objects(any length).
58
New cards
if a superclass has private methods can they be overridden?
No. As these methods are private they cannot be overridden. The subclass does not know they exist.
59
New cards
If a null object is made, can static methods still be called from it?
Yes. Static methods do not need an instantiated object and can be called even in null objects.
60
New cards
Can a static method call non-static methods?
No. Static methods can only call other static methods. Non-static methods, however, can call static methods.
61
New cards
What is a constant?
a static final variable
62
New cards
If a list is final can elements be added?
Yes. The only thing you cannot do is overright the object.
"you can still change, add and remove the contents of the list, but cannot create a new list assigned to the variable."
63
New cards
What does
static {//some code}
do?
This is where the class is first used and the only place final variables can be reassigned.
64
New cards
How do you do a static import?
import static package.directory; If two imports collide, a compilation error is thrown. If one is imported with .* and the other is imported explicitly the explicit import stays.
65
New cards
Java is pass by value. What does that mean?
it means that changing assignments inside a method has no effect outside the method.

Though the method makes a new reference. So anything manipulated under that gets forgotten.
66
New cards
What is method overloading?
If a class have multiple methods by same name but different parameters, it is known as Method Overloading. It increases the readability of the program.
67
New cards
Do access modifiers and exception lists affect method overloading?
No. The only things relevant to method overloading are parameters.
68
New cards
What causes a method overload to cause a compiler error?
different return types, making some static/non-static, if both end with varargs and array.
69
New cards
What are examples of method overloading compiling?
using wrapper classes(autoboxed if needed), String and Object(if its not a string its potentially an object(autoboxing again).
70
New cards
Can a manually created empty constructor be a "default constructor"?
No. It was not compiler generated therefore it is not the default constructor.
71
New cards
What is the order of initialization of a class?
1: Initialize superclass
2: Init static vars/initializers.
3: Instance vars/initializers.
4: constructor
72
New cards
Can lamdas use both static and instance vars?
Yes.
73
New cards
What is package private access?
This means default.
74
New cards
In a class called MakeSandwich can a normal method be made?
e.g.
public void MakeSandwich() {}
Yes this would compile as we had a return type.
75
New cards
if a main method is declared without static or given a return type, what is the output?
This makes it a normal method and not a main method so java cannot run the class.
76
New cards
What is hiding?
This is when a static method is overwritten(both must be static and neither can be final)
77
New cards
When extending a class, can instance variables be used from the parent class?
No. They are not accessible by the child class.
(They can be accessible when making an object of the superclass)
78
New cards
How can you import multiple classes?
Using multiple level inheritance. Superclasses can have superclasses which can be given to low level classes.
79
New cards
What does super do?
It gives us access to parent classes members when we're inside the child class
80
New cards
call super class methods with:
superClass.Method();
81
New cards
What is overriding?
allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes.

\
exceptions should be narrower or missing. They cannot be broader. They should also have the same return type.
82
New cards
Can abstract methods or interface methods be final?
No. This defeats their purpose.
83
New cards
What access modifiers can interfaces have?
Only public/default.
84
New cards
interface's variables are assumed to be\____
public static final. This means they must be initialized.
85
New cards
interface's methods are assumed to be\____
public abstract. (or static/default)
86
New cards
What happens from method clash in interface implementation?
This compiles when the signatures match
If not/not overloaded, compilation error(unless one is default).
The only caveat is more than one can be default if the implementing classes override all but 1.
87
New cards
What is a "default method"?
Only method in an interface with body. Its is assumed public NOT abstract, static or final.

\
Implementing classes can chose to override these but it is not necessary. It needs to be extended to be used.
88
New cards
Can default methods change to abstract in abstract classes?
Yes.
89
New cards
What does static do in interfaces?
This is not inherited. It can be called like any other static method with the interface name.
90
New cards
What is polymorphism?
It allows objects of different classes to be treated as objects of a common superclass, enabling flexibility and reusability in object-oriented programming. Polymorphism is achieved through method overriding and method overloading.
91
New cards
If a class implements an interface, should it implement all methods?
No. The class might be abstract.
92
New cards
Should a concrete subclass inherit all methods from an interface?
False. It could have 2nd level inheritance/some class might have already implemented some methods.
93
New cards
Can an abstract class have private methods?
Yes. Subclasses cannot see it as it is private. They need their own implementation.
94
New cards
Java has a superclass Throwable. What are its subclasses?
Error and Exceptions. When errors are thrown, they should not be handled by the code.
95
New cards
What are runtime exceptions?
These are unchecked. These are unexpected but not fatal errors that can be handled in the code.

These do not need to be handled or declared. They are thrown by a programmer or the Java Virtual Machine
96
New cards
What is a checked exception?
This includes the Exception class and all subclasses not under runtime exception. These are anticipated.
These exceptions can be thrown by the JVM or the programmer.
97
New cards
How are checked exceptions handled?
The handle or declare rule. The code should deal with them(try/catch) or the method should: throws \_____
98
New cards
What happens when an exception is thrown in a try catch?
Any code after is not run and it immediately moves on.
99
New cards
T or F: A try catch can have any valid code inside.
True. It can have anything even another try/catch
100
New cards
Lets say there is a try/catch/finally method. An exception is thrown in the catch block. Does the finally still run?
Yes. The finally block will run unless System.exit(0) is called in the catch or try blocks.

Explore top flashcards

Hinduism
Updated 1056d ago
flashcards Flashcards (20)
Civil Rights EK 3
Updated 14d ago
flashcards Flashcards (60)
Vocab Unit 1
Updated 866d ago
flashcards Flashcards (50)
Muscular System I
Updated 368d ago
flashcards Flashcards (124)
50 States
Updated 203d ago
flashcards Flashcards (50)
1017
Updated 394d ago
flashcards Flashcards (55)
Hinduism
Updated 1056d ago
flashcards Flashcards (20)
Civil Rights EK 3
Updated 14d ago
flashcards Flashcards (60)
Vocab Unit 1
Updated 866d ago
flashcards Flashcards (50)
Muscular System I
Updated 368d ago
flashcards Flashcards (124)
50 States
Updated 203d ago
flashcards Flashcards (50)
1017
Updated 394d ago
flashcards Flashcards (55)