Advanced Java Code Interview Questions

Q Why Java is platform independent?

Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system.

Advanced Java Interview Questions on Multithreading

  • What do you understand about inter-thread communication in Java?
  • What do you understand about Atomic Action in Java?
  • What is Thread Pooling and ThreadScheduler in Java?
  • What do you understand about the Copy Constructor in Java?
  • What is the function of the finalize() method in Java?
  • What do you understand about Tokens in Java?
  • What are the advantages of Multithreading in Java?
  • Which are the different states in a thread lifecycle?
  • How is thready-safety achieved in Object-Oriented Programming?
  • What are Daemon threads in Java?
  • Check some more Java Multithreading Interview Questions here.

    Q64) What are access specifiers in Java? List all of Java’s access specifiers

    Ans. Java’s access specifiers help to control where an instance field/method of a class is accessible. Java has the following access specifiers:

  • Private – Specified by the private keyword. A private member is accessible only in the class where it is declared
  • Default – When a class member does not have an explicit access specifier, it is said to have default access. A default member is accessible only in other classes within the same package
  • Protected – Specified by the protected keyword. A protected member is accessible in other classes within the same package and in sub-classes that are outside the package
  • Public – Specified by the public keyword. A public member Is accessible from anywhere.
  • 3 How do you create an enum in Java?

    The following example code shows how to create a basic enum:

    ThreadStates is the enum with fixed constants fields START, RUNNING, WAITING, and DEAD. All enums implicitly extend the java.lang.Enum class and implement the Serializable and Comparable interfaces. Enum can have methods also. Learn more about enums in Java.

    Q13) What is the difference between multitasking and multithreading?

    Ans. Multitasking includes two ways of representation: 1. Preemptive multitasking: where the system terminates the idle process without asking the user. For example Unix/Linux, Windows NT 2. Non-preemptive multitasking: where the system asks the process to give control to other processes for execution. For example Windows 3.1 and Mac OS 9.

    Multithreading: 1. Multithreaded programs are the program that extends the functionality of multitasking by dividing the program in the thread and then execute the task as individual threads. 2. Threads run in a different area and each thread utilizes some amount of CPU and memory for execution.

    Q14) What is the difference between an Interface and an Abstract class?

    Ans. An abstract class can have instance methods that implement a default behaviour. An Interface can only declare constants and instance methods, but cannot implement default behaviour and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class that may have the usual flavours of class members (private, protected, etc.), but has some abstract methods.

    Q18) What is an abstract class?

    Ans. Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), an abstract class may contain static data. Any class with an abstract method is automatically abstract itself and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

    Java Interview Questions And Answers | Java Programming Interview Questions And Answers |Simplilearn

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *