Java Kahoot

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the value of the String at the first index of the array? String[] arr = new String[3]; arr[0] = "Hello";

"Hello"

What is the difference between a HashSet and a TreeSet

A HashSet sorts its elements using a hash and a TreeSet sorts its elements using a tree structure. HashSets are faster at adding elements to the collection, TreeSets are slower at doing this, but will be ordered.

What is a class method?

A class method is a method belonging to the class. You do not need to create an object in order to access this method. It contains the static keyword in its method declaration.

What is a Heterogeneous collection?

A collection that can include objects of varied types (all inherit from the same base class).

What is an instance method?

A method that belongs to the object. We need to create an object and call that method from that object in order to run it.

Who can access a private static attribute?

All objects created from the same class.

What is an unchecked exception?

Also known as run time exceptions, they occur at the time of execution of your program. They are not required to be caught or handled unlike checked exceptions.

What is polymorphism?

An entity can take on different forms. Whether it be through run time polymorphism (method overriding) or compile time polymorphism (method overloading).

What kinds of strings will match this regex: ba?b

Any string with two b's with zero or one a's between them. Ex: "bb" or "bab"

What is the difference between a LinkedList, ArrayList, and Vector?

ArrayList -Implemented as resizable array -As more elements added, size increased dynamically -Grows by 50% each time more space needed for elements added LinkedList -Implemented as a double linked list -Performance on add/remove better than Arraylist, but worse on get/set methods -Also inherits from the Queue interface Vector -Like ArrayList, but synchronized. -ArrayList is a better choice if your program is thread-safe -Doubles array size each time more space needed for elements added

How do you create a Thread?

By extending the Thread class or implementing the Runnable interface.

What does the instanceof keyword do?

Checks if an object is an instance of a class.

What is Downcasting and Upcasting?

Downcasting is when you cast from a parent type to a child type. Upcasting is when you cast from a child to a parent.

Which date class can store time zones?

Either Date from java.util or ZonedDateTime from java.time.

What is the Default Exception Handler?

If you don't handle an exception in your code the JVM hands the exception to the default exception handler. It will terminate your program and print the stack trace.

What is a final variable?

If you make any variable as final, you cannot change the value of final variable(It will be constant).

What is the scope of a protected method?

It can be access by anywhere within the package it's in as well as any of the subclasses that inherit from it. Even if that subclass is not within that same package.

What does the JDK do?

It contains the JRE and other development tools so that we can develop java programs.

What is a Homogeneous collection?

It is a collection that only includes objects of a single type.

What is the XOR operator?

It is denoted by the ^ symbol in Java. It will evaluate as true only if the two conditions it is checking have exactly one true and one false.

What are the advantages of Java?

It is platform independent (architecture neutral) because it is both a platform and a language. It contains similar syntax to other C languages but is easier to write and does not have any explicit pointers. As well, it has automatic garbage collection so you don't need to keep track of deleting your objects in memory.

What is a Has-A relationship?

It refers to composition, when a class can contain an instance of another class.

Will a finally block always execute?

It should, but it will not if your program is interrupted. If you run System.exit(0) it will exit your program before it runs the finally block.

What will be the number of the last index in an array?

It will be the array length minus one. So if an array was of length 5, the last index number will be 4.

What happens if we were to run the code below? System.out.println(null);

It will print the word null to the console. There will be no error or exception thrown, Java is able to take a null and be able to print it as the word null.

Which allows for the development of Java programs? a) JDK b) JRE c) JVM

JDK (Java Development Kit)

The ______________ implements the JVM.

JRE

How do you create an abstract method in an interface?

Just write the method signature with no implementation, no need to label it abstract.

What is a good way to prevent deadlock?

Make sure threads are locking resources in the same order or make sure threads release locks on resources after a certain amount of time if they are not doing anything with that resource.

Is a StringBuilder immutable?

No, it is mutable and its value can be changed.

Once I've initialized an array and set its length, can I change that length?

No, once an array length is set, it cannot be changed to add or remove elements.

Can you restart a thread once it's dead?

No, once it's dead, it has finished running and can not be called again to run a task.

Is a String a primitive value?

No, while strings are often associated with primitive values, they are objects.

What class does every class in Java inherit from?

Object

Which collection doesn't allow for duplicate values?

Set

Is Java purely object-oriented?

Since there are still primitive values within Java, we do have a purely object-oriented language.

Where will a String created without the new keyword be stored?

String Pool

Which is thread safe, StringBuilder or StringBuffer?

StringBuffer

The reverse() method from _____________________ will reverse a String.

StringBuilder or StringBuffer

What does the JDK contain?

The JRE and other development tools to create java programs.

What is Encapsulation?

The OOP concept of "data grouping" and creating a protective shield around code. We are trying to protect code from being accessed by just anyone. One example is when we set attributes in our class to private and only allow access through getters and setters.

What is Abstraction?

The OOP concept that enforces "data hiding" to hide functionality of how code works. We do not care to know how code works or how it is implemented, we just care that it will work. For example, when we call a method, we do not care what the code within a method is, we just care that the method will perform the action we expect it to do.

What happens at run time?

The compiled byte code is interpreted and run.

What does the super keyword refer to?

The direct super class of whatever subclass you are currently in.

What happens when you compile a java program?

The java program will be turned to byte code and saved in a class file. This class file is what is what is used when running your program.

What happens to the lock on a resource when a thread is put to sleep?

The lock on the resource stays, the thread doesn't release any lock while asleep.

What method do you use within Thread to start your program?

The start() method, it will start your thread and call the run() method to begin running your thread.

What is the difference between the throw and throws keyword?

The throw keyword is used to manually throw an Exception within your code. The throws keyword is put at the top of your method signature and propagates your exception up the call stack. You use throws when you don't want to handle your exception with a try-catch block.

What is the naming convention for final variables?

They must be all capital letters and we can separate words within the variable name with an underscore.

Which implementation of Set is ordered?

TreeSet

What is a 2D array?

Two-dimensional arrays form a tabular, two-dimensional arrangement. You access elements with an index pair a[i][j]. Usually, the first bracket represents the "rows" of this table and the second bracket stands for the "columns" of the table.

What are the advantages of generics?

Type-safety : We can hold only a single type of objects in generics. It doesn't allow to store other objects. Type casting is not required: There is no need to typecast the object. Compile-Time Checking: It is checked at compile time so problem will not occur at runtime. The good programming strategy says it is far better to handle the problem at compile time than runtime.

How can you traverse through a Set?

Use a for each loop or use the Iterator class to iterate through the Set.

How do you access a specific value in a Map?

Use the get() method and pass the key associated with the value you want.

How would you compare the memory location of two Strings?

Using ==

In Java, how do we achieve multiple inheritance?

Using interfaces

How do we convert from a String to a Date?

Using the SimpleDateFormat class we can convert from String to Date like so... String dateStr = "10/15/2020"; Date date = new SimpleDateFormat("MM/dd/yyyy").parse(dateStr); System.out.println("date = " + date);

How do you synchronize a thread?

Using the synchronized keyword, you can place it in a method signature to synchronize methods you call within a thread or create a synchronized block that will lock a certain resource and not let go of the lock until that block of code finishes running.

When can you not override a method?

When it is final or static (class method)

What is upcasting?

When you convert from the type of a child class to a parent class.

Where will a String created with the new keyword be stored?

Within Heap Memory.

Where is the system library contained in Java?

Within the JRE.

Can Enums have constructors?

Yes.

How do we create a custom exception?

You create a class and have it extend the Exception class (can extend any subclass of Exception).

What happens when casting from a double to an int?

You may lose precision because a double is a more precise value than an int.

What happens when you return a value within a loop?

You return that value and exit the loop.

How do you delete an object from an array objects?

You set the value where the object is stored in the array to null. You remove the pointer to the object from the array and the automatic garbage collector will see the object is not being referenced in your code and delete it.

An abstract can have...

abstract and implemented methods, static and non-static attributes, final and non-final attributes

At each index in an array of objects ________________ is stored.

an address in memory where the object is located

A class uses the _____________________ keyword to inherit from an interface.

implements

From what package do we import LocalDate from?

java.time

What is the difference between notify() and notifyAll()

notify() will notify a single thread waiting on a resource that that resource is now available (thread notified is chosen by your system) while notifyAll() will notify all the threads waiting on a resource

A newly initialized array of objects will contain ________________ values in all its indexes.

null

How do you write the method signature for the main method?

public static void main (String[] args);

The first index in any array in Java begins with the number _______.

zero

When you create a new array of ints, what will be the default value at each of the indexes?

zero


Kaugnay na mga set ng pag-aaral

Exercise Prescription -- Final Exam

View Set

Fluid & Electrolytes Practice Questions

View Set

Chapter 18: (Accounting for Dividends)

View Set

Biology 10-2 Review DNA Structure Work Sheet

View Set