Tuesday, June 7, 2022

Testing 1,2,3: Question part 2

● What is an interface in Java and why would you, as a software developer,

use interfaces?

-They are an abstract type used to explain a behaviour a class must implement. They allow developers to make the coupling between classes very loose

● What is the difference between an abstract class and an interface?

-An abstract class is type that can be instantiated directly whereas an interfaces is explaining the implemented behaviours a class carries out

● Why is abstraction an important concept in software development and

what role do interfaces play in abstraction?

-It allows us to access object attributes and allows us to invoke behaviours of an object, lastly, it is important for encapsulation, inheritance and polymorphism

● What must a class do in order to implement an interface?

-Interface Test{}

-class Example implements Test{}

-This will allow class Example to implement the interface Test

● What is an abstract method?

-Method that can only be used by the abstract class with no body

● Can you instantiate an interface?

-No, Interfaces cannot be instantiated directly, However its members can be implemented by any class which implements the interface

● Can you declare a constructor inside an interface? If not, why?

-No, Interfaces cannot have constructers since interfaces allows default and static methods

● Can we override an interface method with visibility that is not public?

-No, we interface cannot override with a none public visibility. In the case of that visibility is public we can use the dame method signature to override the interface 

Testing 1,2,3: Questions Part 1

 ●What is the difference between process and thread?

-A process is a program that has been loaded into memory along with all the

resources it needs in order to run .Whereas, a thread is, unit of execution within a process

●How do you create a thread in Java and run it?

-Thread threadname =new Thread();

● What are the different states of a thread and when do the state transitions

occur?

-New: when a new thread is created

-Runnable: when a tread is ready ready to run or is running

-Blocked and Waiting: when the thread is inactive

-Timed Wait: when a thread calls sleep or a conditional wait

-Terminated: Threads that exit normally or an error occured

● What is a daemon thread and what are its use cases?

-

● How do you create a daemon thread?

-set void set Daemon(boolean stat):

-Throw illegalThreadException

-or Throw SecurityException

-check the method to see if thread thread is Daemon

What is Java Memory Model (JMM)?

-Its the definition of the allowed behaviour of multithread programs

● What are deadlock, livelock, and starvation? What causes these

conditions?

-Deadlock: a state in which each member of a group of actions is waiting for some member to release a lock

-LiveLock: The states constantly change with respect to one another. It occurs when the system has a finite number of resources for quasi-infinite processs

Starvation: It's similar to both deadlock and livelock, it is when a system request resources , but the same policy is needed to decide who get these resources. Occurs when greedy threads make shared resources unavailable for long periods. 

● What happens if you don’t override the thread class run() method?

-The complier won't output any error and it trigger the the run method() of the thread class that is empty, outputting an empty class

● What is atomic operation and what are atomic classes in the Java

Concurrency API?

-Atomic operations are operations that are executed together

-Atomic classes give a lock free and safe enviroment or programming on single variable

● What are Executor and ExecutorService and what are the differences

between them?

-Executor is an interface that contains a method called execute() to rub a task specifically designed by a runnable object

-ExecutorService is a sub-interface of a Executor which only adds functionality to manage task lifecycles

● What are Concurrent Collection Classes?

-A number of classes designed to specifically deal with concurrent operations

Testing 1,2,3: Question part 2

● What is an interface in Java and why would you, as a software developer, use interfaces? -They are an abstract type used to explain a beha...