Java 1 Flashcards Preview

Java > Java 1 > Flashcards

Flashcards in Java 1 Deck (98)
Loading flashcards...
1

What is a processor core?

A single logical or physical engine capable of performing standalone execution of a program.

2

What is clock speed?

The frequency at which a processor can execute instructions, expressed in Hz.

3

What is concurrency?

Executing multiple programs or multiple parts of a program at the same time.

4

What is a Thread?

A single sequential chain of execution.

5

What are the lifecycles of a Thread?

New, Runnable, Running, Waiting, Dead.

6

What is the state of a Thread when it is instantiated?

New

7

What is the state of a Thread after Thread.start()?

Runnable

8

What method is called to move a Thread to the Running state?

run()

9

What is the state of a thread while waiting for resources or waiting for another thread to complete?

Waiting

10

What is the state of a thread after its task has completed?

Dead

11

What interface should you implement if your class is intended to be executed as a thread?

Runnable

12

Which method in Runnable needs to be implemented to provide an entry point to execute your logic?

run()

13

How do you create a Thread using the Runnable a?

new Thread(a);

14

What command launches thread b?

b.start();

15

What is the most common design model for parallel programming?

Fork-Join approach.

16

What is the Fork-Join model?

A way of setting up and executing parallel programs, such that execution branches off in parallel at designated points in the program, to "join" (merge) at a subsequent point and resume sequential execution.

17

What is the executor service?

The executor service contains a configurable set of thread which can be used to do work.

18

How is the executor used in the Fork-Join approach?

Work can be asynchronously submitted to the executor service, which executes the work across all the threads in its thread pool. This is the 'Fork' part. After the work is done, the results are joined together.

19

What is Deadlock with multi-threading?

When two competing processes are waiting for each other to finish, so neither does.

20

What is Starvation with multi-threading?

When a process never gains access to resources.

21

What is a Race Condition?

When a process that should run in a particular order runs out of order producing an unexpected result, i.e. when two threads have access to a section of code that needs to be atomic.

22

What is Livelock with multi-threading?

When two threads depend on each other and get stuck in a loop of releasing and locking the same resource.

23

What common strategies can be used to break a deadlock or prevent starvation?

Use synchronized code blocks where only one thread at a time can enter the block and contain all the shared resources within it. Use a semaphore for a single variable but apply a time sharing or timeout policy to ensure it is automatically released.

24

What annotation should libraries be marked with in a thread safe application?

@ThreadSafe

25

How do you run a Java application from the command line if the main method is in a class called Painter?

java Painter

26

What is the syntax for an end-of-line comment?

//

27

What is the syntax for a multi-line comment?

/* */

28

What is the syntax for a documentation comment?

/** */

29

What keywords are used when declaring a new public class?

public class

30

How is the main method strictly declared?

public static void main(String[] args){}