mode 1 Flashcards

maven, log4j, junit

1
Q

What is a Thread?

A

A split in execution. A process. A line of logic. (aka a series of instruction)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can we create a thread?

A

There are two ways to create a thread.

It can be created by EXTENDING the Thread class and overriding its run() method:
public class Main extends Thread {
  public void run() {
    System.out.println("This code is running in a thread");
  }
}
Another way to create a thread is to implement the Runnable interface:
public class Main implements Runnable {
  public void run() {
   for(int i =0; i<50; i++) {
			System.out.println("\t:\t"+Thread.currentThread().getName());
		}

}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the run method do?

A

The run method acts as the entry point into this thread’s logic JUST like the main method in the main thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

PROS AND CONS OF THE TWO WAYS OF CREATING A CUSTOM THREAD:

A

Pros of extending:

  • -less lines of code to “start” the thread
  • -far easier to override the functionality of the Thread class when extending

Pros of implementing:

  • -you do NOT use up the one slot you have to extend another class
  • -lightweight, meaning you don’t have to include unwanted methods/baggage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the Start Method do?

A

The START method has special logic that will create a separate process (thread) THEN inside that separate thread it will invoke your run() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a subprocess?

A

A child process that occupies the same heap as the parent process.
>In java, all threads are ACTUALLY subprocesses.
»This means that threads in Java have the same heap, but different stacks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is multithreading?

A

It’s when multiple processes run concurrently (at the same time)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In Java, What are the states of a thread?

A
  • New: the thread is new (just created)
  • Runnable: it’s able to have processor time (not sure if CURRENTLY running though)
  • Waiting: functionality is paused until a specific event has happened (waiting for a “resume” signal)
  • Timed Waiting: functionality is paused until a certain time has passed
  • Blocked: it can’t continue its process because another process has hogged/claimed a necessary resource (synchronized methods)
  • Terminated: terminated aka completed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the synchronized keyword do in Java?

A

The synchronized keyword goes on a method
>For a synchronized method two threads can NOT access THAT SPECIFIC method concurrently
>THAT specific method inside of THAT SPECIFIC object.
>that is to say, that is method1() is synchronized then ThreadOne and ThreadTwo cannot access method1() inside of ObjectOne
>HOWEVER, ThreadOne can access method1() insode of ObjectOne AT THE SAME TIME as ThreadTwo accessing method1() inside of ObjectTwo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a marker interface, functional interface?

A

A marker interface is an interface that has NO abstract methods that you need to implement (marker interfaces allow you to implement black/whitelist scenario in OOP). Serializable is a marker interface.

A functional interface is an interface that has EXACTLY ONE method for you to implement

If an interface has two or more methods for you to implement then it doesn’t have a special name
, its just an interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the different between a white list and a black list?

A
  • in a blacklist by default EVERYONE is allowed access, those on the blacklist have had their access revoked
  • in a whitelist by default NO ONE is allowed access, those on the whitelist have been granted access

Serializable happens to be a whitelist scenario

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the transient keyword do?

A

the “transient” keyword stops a field from being written to a file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Reflection

A

Reflection allows one to view an object or primitive during runtime of the application. YOu may
also modify the object’s structure/state during runtime. It’s VERY powerful.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are Streams

A

Streams are essentially a tool that helps you manipulate and perform calculations upon a Collection or Array using a functional programming approach. (a bit of sugar syntax)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the filter Stream Method

A

Filter is going to LOOK AT a collection then create a SECONDARY collection that contains ONLY the elements that pass a given conditio

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the sorted method

A

Sorted is going to LOOK AT a collection then create a SECONDARY collection that contains ALL the original elements, but sorted. If the elements aren’t of type Comparable then an exception will be thrown.

17
Q

Types of completion methods

A

collect()

forEach(): the forEach stream method is basically just a for each loop

reduce(): what the reduce stream method does is it reduces the entire collection down to a single value.

18
Q

What is Covariance

A

Covariant return types allow an overridden method to alter the method’s return type.

The new return type must be a SUBSET of the original return type