Core Java -101 Flashcards

1
Q

Can we do array[i] and i could be long type also?

A

No i must be only int

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

What is a Runtime class?

A

Every Java Application has one instance of this , this will allow instance to interface with env it is running

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

How to obtain the Runtime?

A

getRuntime

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

What is addShutdownHook(Thread hook)

A

Registers a new virtual-machine shutdown hook.

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

What is exec methods?

A

So this has many overloads & use to give the commands on the given environment

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

exit(int status)

A

Terminates the currently running Java virtual machine by initiating its shutdown sequence.

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

freeMemory()

A

Returns the amount of free memory in the Java Virtual Machine.

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

gc()

A

Runs the garbage collector.

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

halt(int status)

A

Forcibly terminates the currently running Java virtual machine.

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

loadLibrary(String libname)

A

Loads the dynamic library with the specified library name.

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

removeShutdownHook(Thread hook)

A

De-registers a previously-registered virtual-machine shutdown hook.

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

totalMemory()

A

totalMemory()

Returns the total amount of memory in the Java virtual machine.

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

What the exec method returns?

A

Process

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

What is a java.lang.Process class?

A

The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.

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

Does the methods of PRocess works in all env?

A

Not necessarily all, may fail is some basic env

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

How can we obtain the I/O of Process?

A

Process does not have terminal or console, all standard I/O are redirected to the Parent process, and can be obtained with the methods like getInputStream, getErrorStream, getOutputStream,

17
Q

How the deadlock may happen while getting getInputStream like methods?

A

As some env support limited buffer size thus reading and writng to same buffer may cause deadlock

18
Q

Does the subProcess (process instance) do async?

A

Yes

19
Q

destroy()

A

Kills the subprocess.

20
Q

exitValue()

A

Returns the exit value for the subprocess.

21
Q

waitFor()

A

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

22
Q

Where do thread executes?

A

Within a process

23
Q

How can we execute a thread in a thread class?

A

Thread thread = new Thread(new Runnable())
thread.start
The start method will call the run method of runnable

24
Q

Can we use lambda expression to write the THread with runnable IF?

A

Yes since runnable is an functional IF

Thread thread = new Thread( () -> {
   /// do the task
});
25
Q

Why Implementing is better than extending?

A

This way we cannot alter the beahvious of the actual class

Add more

26
Q

Which package is for concurrency?

A

java.util.concurrency

27
Q

What does Executor does?

A

It is exactly to replace the Thread and likewise it provide only one method execute
runnable r
Executor e
e.execute(r)

28
Q

What does ExecutorService does?

A

It is an IF and extends the Executor and provides method like submit to accepts runnable and callable to return value

29
Q

What does ScheduledExecutorService does?

A

It is an IF and extends the ExecutorService and provides method to execute tasks at trepeated intervals

30
Q

What does executor makes use of?

A

They use threadpool and Worker threads

31
Q

Are there fixed thread pools, & what is the concept of it?

A

If a thread is terminated then a new thread created

32
Q

Does Executor class has static methods to create ExecutorSerivice

A

Yes, static ExecutorService newSingleTHreadExecutor()

33
Q

In static ExecutorService newSingleTHreadExecutor(), how many threads are created?

A

One

34
Q

How can we create a multiple thread pool with the Executor?

A

static ExecutorService newScheduledThreadPool(int)