Kahoot Questions- Java review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Name a String that match the regex: ba?b

"bb" or "bab"

What is the annotation for a test method in our JUnit class?

@Test

The LocalDate class allows us to store....

A date, cannot store information on time or timezone.

What is the scope of a public modifier

A member with a public modifier can be accessed globally, whether within its class, package, its subclass that is not within the same package, or anywhere else even if it does not inherit from the class containing that member.

What is a relative path?

A path to a file or directory relative to where you are

What will happen if a condition is false at the start of a while loop? What if it's false?

A while loop will run until the condition it is checking for is false or a break/return statement is hit. If the condition is false at the start, it will not run.

What OOP concept encourages "data hiding"?

Abstraction

What are the 4 pillars of object oriented programming?

Abstraction, Polymorphism, Encapsulation, Inheritance

Why is an Error more serious than an Exception?

An Error, unlike an Exception, cannot be handled and indicates a problem with the JVM itself.

What causes a program to terminate?

An unhandled Exception or Error

What exception is thrown when we divide by zero?

ArithmeticException

Which set is faster at adding elements, HashSet or TreeSet?

HashSet

Will a finally block always execute?

If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues. We can also call System.exit(0) in the try block and it will shut down the JVM before we can reach the finally block.

What do assertions check for?

If the condition is true

What information does LocalTime store?

Information on Time

_______________________ is an OOP pillar that describes that two or more entities can be different but can share common features.

Inheritance

What Exception is thrown when Scanner expects to read an int but gets a String?

InputMismatchException

Is Java a programming language or platform?

It is both.

What is the ^ operator called? What does it do?

It is the XOR operator and checks that only one of the conditions it is checking is true.

What does the Enum ordinal method do?

It returns the index of an Enum constant.

A developer would download the _________ from the Oracle website to develop Java programs.

JDK

Does the JVM, JRE, or JDK contain the development tools?

JDK

Which allows for the development of java programs, JVM, JRE, or JDK?

JDK

Which contains the system library, JVM, JRE, or JDK?

JRE

What is the name of the abstract machine that loads, verifies, and executes Java code?

JVM (Java Virtual Machine)

What happens during compile time?

Java code is compiled to bytecode

The compareTo() method compares two Strings by ______________________.

Lexiographic Value

Does ArrayList or LinkedList perform better at adding/removing elements?

LinkedList

Are Exceptions more serious than Errors?

No, Errors are more serious. Exceptions can be handled, Errors cannot.

When we append using StringBuilder, are we creating a new String each time?

No, StringBuilder will append to the String within without needing to create a new String each time.

Does Map inherit from the Collection interface?

No, but it is still part of the Collections Framework

Is everything in Java an object?

No, everything except primitives are objects.

Is a String a primitive data type?

No, it is an object!

Can Collections store primitive values?

No, they can only store objects.

Do Exceptions have to be handled in the method they occur?

No, they do not need to be handled, they can be propagated up the call stack.

Would the following be valid syntax to assign a float variable? float var = 2.3;

No, you should either cast the 2.3 to a float (since it will be read as a double) or add an F to the end of the number to indicate it's a float. float var = (float) 2.3; float var = 2.3F;

The XOR operator checks if...

Only one condition is true

What is the proper format for naming a package

OrganizationType.CompanyName.OrganizationTopic

What will the code below print: String str = "123456789"; System.out.println(str.substring(1, 7));

Prints "234567"

What does the values() method from Enum do?

Return all values present inside an enum

What does the ordinal() method from Enum do?

Returns the index of the enum constant

What does the name() method from Enum do?

Returns the name of the enum constant

What class do we use to convert a String to a Date object?

SimpleDateFormat

___________________ is also known as a desktop or window-based application.

Standalone Application

Which is thread safe, StringBuilder or StringBuffer?

StringBuffer

In what order are the JVM, JRE, and JDK stored within each other?

The JVM is stored within the JRE. The JRE is in turn stored within the JDK.

What happens when an Exception is thrown and not handled?

The program will terminate and print the stack trace to your console.

How does Java achieve multiple inheritance?

Through Interfaces

What interface do Exception and Error inherit from?

Throwable

What will the following code print? String str1 = "123"; String str2 = "123"; if(str1 == str2) { System.out.println("Equal"); } else { System.out.println("Not Equal"); }

Will print "Equal"

How do we compare the value of two Strings?

With the equals() method

Can we remove the String "Hello" from a List this way: myList.remove("Hello");

Yes

Is a final class immutable?

Yes

Will a finally block run if a return statement is hit within the try block?

Yes, a finally block will always run.

Can a final method be overloaded?

Yes, but it cannot be overridden.

Will a Do While loop run if the condition it is checking for is false at the start?

Yes, it will at least go through the loop once.

Can I access a protected method in a parent class from its child class if the child is in a different package?

Yes, the child can access the method.

How many catch blocks can you have for each try block?

You can have multiple, you just need at least one.

How do you create a new ZonedDateTime object?

ZonedDateTime.of(LocalDateTime, ZoneID)

The constructor for BufferedWriter takes in ________________________ as its parameter(s).

a FileWriter object

A try block must be followed by...

a catch or finally block

A Postcondition Assertion checks...

a condition after a method is executed

The value we pass to an object when sending a message is called a(n) ___________________________.

argument

What is the syntax for creating an assertion that displays a message if that assertion is false?

assert condition : "message";

We will break out of a loop if we hit a...

break or return statement

Byte Streams perform input and output of ______________ directly.

bytes

Which of these is false about a String? a) it is immutable b) it is a final class c) it is a primitive d) it stores an array of characters

c) it is a primitive

Give an example of the correct way to assign a character to a variable.

char var = 'c';

A class that inherits from another class is refered to as a(n) _____________________.

child class, sub class, or decendant

If a method is static, it is a _________________ method.

class

What is the scope of a default modifier?

is accessible within its class and package

What is the scope of a private modifier?

is accessible within its class only

What is a protective modifier's scope?

is accessible within its class, package, and subclasses

From what package do we import the LocalDateTime class from?

java.time

From what package do we import the Date class from?

java.util

Which method(s) below propagates an Exception? public void methodA() throws Exception { ... }; public void methodB() throwing Exception { ... }; public void methodC() { ... };

methodA

The ____________________ method from File allows us to create multiple directories at the same time.

mkdirs()

If we run the following code: int num = (int) 5.20; What will be the value of num?

num = 5

An instance method belongs to the...

object

What method do we use to add a key-value pair to a Map?

put()

What updates were introduced to Interfaces with Java 8?

static and default methods

Write a method signature for methodA() that returns no value, is a class method, and has a default scope.

static void methodA()

If we run the following code: String str = 3 + 2.4 + " Hello World".trim(); What will be the value of str?

str = "5.4Hello World"

Which of the Strings below will be stored in Heap Memory? String str1 = "123"; String str2 = "123"; String str3 = new String("123");

str3

Fill the missing code within ClassB constructor so you set var1, var2, and var3: class ClassA { private int var1; private int var2; public ClassA(int var1, int var2) { this.var1 = var1; this.var2 = var2; } } class ClassB extends ClassA { private int var2; public ClassB(int var1, int var2, int var3) { // add missing code here } }

super(var1, var2); this.var3 = var3;

The this keyword refers to...

the current object

We use the __________________ keyword in a method header to propagate an Exception.

throws

A Runtime Exception must be handled or the Eclipse IDE will underline it in red. True or False?

False, you are not forced to handle a Runtime Exception in your code by the IDE

Besides using Iterator, how else can we iterate through a Set?

For Each Loop

What happens if a return statement is hit during a loop?

Breaks out of the loop and returns its value.

What kind of Exception is checked at compile time?

Compile Time/Checked Exception

LocalDateTime stores information for the...

Date and Time

If there is no matching handler for an Exception, the JVM hands it to the _____________________.

Default Exception Handler

Which of the four pillars of OOP matches this definition: Data/code is hidden to protect the inner workings of an object from the outside world.

Encapsulation

What do all Exceptions inherit from?

Exception class

What happens when a continue statement is hit during a loop?

Exits the iteration of the loop its in and continues to the next iteration.

How do we compare the reference in memory of two Strings?

Using the == operator

Which is thread safe? a.) List b.) Vector c.) ArrayList d.) LinkedList

Vector

How do we create a try-with-resources block?

We pass a resource (stream, connection, etc.) as an argument to the try block

What do we use an input stream for when it comes to files?

We use them to write to a file


Set pelajaran terkait

Maternity and Women's Health Nursing - Women's Health

View Set

Intro to Marketing Chapter 5,6,7,8

View Set

Comptia Security+ 01 - Risk Managememt

View Set

ACCT 460 Chapt 3 Multiple Choice Questions

View Set

Chapter 2 - Accounting for Business Transactions

View Set

Chapter 4 Review Questions/Problems

View Set

Study of Drug Use and Addiction chapter 3

View Set