




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















●● Synchronization Answer: Restricts access to a resource to one thread ●● Singleton Answer: A design pattern where there is only one instance of the class the entire time. They can be lazily loaded or eagerly loaded. Lazily loaded are not thread-safe, but eagerly loaded singleton are thread-safe. The Singleton design pattern is implemented by creating a class with an accessible method that creates a new instance of the object IF one does not already exist. If an instance already exists, it simply returns a reference to that object. The constructor for a Singleton is private. ●● Factory Answer: Simplifies and abstracts away the instantiation of objects ●● What does POM stand for in software development? Answer: Project Object Model
●● What is the primary format used to store a Project Object Model? Answer: XML file ●● What type of information is defined in a Project Object Model? Answer: Project dependencies, build configurations, versioning, developers, and other relevant project attributes ●● What is the most common tool associated with Project Object Model? Answer: Apache Maven ●● What is the name of the POM file in Apache Maven? Answer: pom.xml ●● What is the purpose of a Project Object Model? Answer: To allow for automated build and management processes ●● Threads Answer: A single path of execution. In Java, multi-threading is possible, and achieved in a concurrent way where threads take turns executing sections of their code ●● What is the purpose of the 'final' keyword in Java?
functions are taken care of (abstracted away) so the programmer does not have to worry about the complex details when writing code. Also, it can be compiled into bytecode that can be interpreted on any machine through the JVM. ●● What is OOP? Answer: Object orientated programming is a programming model centered around the representation of data through objects. Objects contain certain attributes that are represented by fields (which may in turn store primitive values and references to another object). ●● Pillars of OOP Answer: Abstraction, Encapsilation, Polymorphism, Inheritance ●● Define Inheritance Answer: The ability of a class to gain properties from another class, by extending it, or from an interface by implementing it ●● Define polymorphism Answer: The idea that a name can represent multiple forms. Examples include methods with the same name but different functionality (Overriding), or methods with the same name but different parameter requirements (Overloading) ●● Define Encapsulation
Answer: Hiding the visibility of certain features of a class from outside classes. ●● Define Abstraction Answer: The idea that the programmer does not need to worry about the inner workings of the utility being used. The inner workings may be hidden, but for a given input a certain output can be expected ●● What is the default value of an int variable declared within class scope? Answer: 0 ●● What is the default value of variables declared within block scope? Answer: none ●● What is the entry point of any Java application? Answer: The main method ●● What is the syntax for the main method? Answer: public static void main(String[] args) { } ●● What is the difference between the logical operators: & and &&
Answer: if, else if, else,switch ●● What are the different types of looping statements in Java? Answer: while, for loop, for each (enhanced for loop), do-while ●● What are the different types of branching keywords in Java? Answer: break, continue ●● What is an alternative to using a long chain of else-if statements? Answer: Switch statements that take in some primitive types (byte, short, int, char) or a String argument and check them against cases ●● What is meant by fall-through, with regard to switch statements? Answer: Execution of statements in the next case, which occurs when the programmer forgets to use a break statement. Once a case is found true, the remaining cases will also be run unless a break statement is used. ●● Which data types cannot be used within a switch statement? Answer: boolean, long, float, and double ●● Can you use break and continue to alter the flow of an if-statement?
Answer: No, break and continue statements are only allowed in loops and switch statements ●● Why does Java require that the main method be static? Answer: Java does not create an instance of an object before the beginning of the runtime. Static fields, methods, and code blocks are called when a class is loaded into the JVM. ●● What is a static initialization block? Answer: They are anonymous blocks within a class signifyed by the static keyword ●● Static Initialization Block Answer: A block of code that initializes static variables when the class is loaded, executed once per class and not per instance. ●● Purpose of Static Initialization Block Answer: To perform complex initialization of static variables that cannot be handled in a single line. ●● Execution Timing of Static Initialization Block Answer: Executed when the class is first loaded into memory, before any instances are created and before anything else in the class is executed.
●● What are the access modifiers in Java, and the keywords associated with them? Answer: Access modifiers determine the visibility/scope of members and objects in Java, and the keywords associated with them are public, protected, and private. There is also Default, but no keyword is used for that. ●● What is Reflection? Answer: [1]The debugging of a Java program at runtime [2] allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program during runtime ●● What does 'covariant' mean? Answer: Covariance is java's version of type conversion. A sub-class can be cast as the type that is its parent class. The inverse is not possible however. This type conversion can occur implicitly during initialization. Type conversion can also occur when a method returns a sub-type of the return type indicated by the method declaration. ●● What are the four base classes in Java I/O? Answer: Reader, Writer, InputStream, OutputStream ●● How can we override a method by changing the throws clause in its method signature?
Answer: The overridden method can have a more specific throws clause than the method it is overriding ●● How can we override a method by changing the return type in its method signature? Answer: The type needs to be a subclass of the overridden method ●● Can you override the protected methods inherited from a superclass within a different package? Answer: Yes ●● Can you override the package-private methods inherited from a superclass within a different package? Answer: No ●● What is serialization? Answer: It is the act of the Serializable interface by which an object's info is stored in the byte stream ●● What does the transient keyword do? Answer: It prevents any method or field that uses it from being serialized ●● What is deserialization?
●● What is multiple inheritance, and does Java support it? Answer: Yes, through interfaces. ●● What is the difference between an abstract class and an interface? Answer: Interfaces are implemented while abstract classes are extended. ●● What is a default method in an interface? Answer: In Java 8, a default method is a method that can be implemented by the interface and is inherited by classes that "implement" the interface ●● In what version of Java were functional interfaces introduced, and alongside what other key feature? Answer: Functional interfaces were introduced in Java 8, along with interface static methods and default methods ●● What is functional programming? Answer: A programming paradigm where programs are built by composing functions, emphasizing immutability and avoiding shared state and side effects, leading to more predictable and maintainable code ●● Can static methods be overridden? Answer: No, static methods are called by invoking the class.
●● What is variable shadowing, and what pillar of OOP does it relate to? Answer: A programming concept where a variable declared within a certain scope has the same name as a variable in an outer scope, effectively hiding the outer variable. ●● What is method overloading? Answer: allows you to define multiple methods within the same class that share the same name but have different parameters. ●● In what order does Java determine which overloaded method will be used if multiple are compatible for a given parameter? Answer: Java looks at the method's type. the most specific method that matches the arguments ●● Differences between String, StringBuilder, and StringBuffer Answer: String is immutable, whereas StringBuffer and StringBuilder are mutable classes. StringBuffer is thread-safe and synchronized, whereas StringBuilder is not. That is why StringBuilder is faster than StringBuffer ●● Sub-interfaces of Collection Answer: List, Set, and Queue ●● Difference between HashMap and HashTable
A doubly-linked list implementation, offering good performance for insertion and removal operations at both ends. ArrayDeque: An array-based implementation, providing efficient insertion and removal at both ends. It's often faster than LinkedList for most operations. Priority Queue: A special type of queue where each element has a priority, and elements are dequeued based on their priority rather than their order in the queue. Array Queue A queue implementation that uses a fixed-size array to store elements, where the front and rear indices are managed to facilitate enqueue and dequeue operations. ●● Examples of concrete implementations of List Answer: ArrayList: This is the most commonly used implementation. It is backed by an array, which makes it efficient for accessing elements by their index. LinkedList: This implementation uses a doubly-linked list data structure, making it efficient for inserting and deleting elements. Vector: Similar to ArrayList, but synchronized, making it thread-safe for concurrent access.
Stack: A subclass of Vector, implementing a last-in-first-out (LIFO) stack data structure. CopyOnWriteArrayList: A thread-safe variant of ArrayList that creates a new copy of the underlying array on each modification. It's suitable for scenarios where reads are frequent and modifications are infrequent. ●● Examples of concrete implementations of Set Answer: HashSet: Most commonly used implementation. Stores elements in a hash table, providing fast access and insertion. Does not maintain any specific order of elements. LinkedHashSet: Maintains the insertion order of elements. Slightly slower than HashSet due to the overhead of maintaining order. TreeSet: Sorts elements based on their natural ordering or a custom comparator. Slower than HashSet and LinkedHashSet due to the overhead of sorting. EnumSet: Highly efficient implementation for storing enum values. Not suitable for non-enum types.
Answer: Having multiple threads running at once. Allows multiple threads to execute concurrently within a single process ●● What is the default priority of a thread? Answer: The default priority of a thread in Java is set to 5. Thread priorities in Java range from 1 (minimum) to 10 (maximum). ●● What is a deadlock? Answer: The situation in which two or more threads require the resource that the other is currently using. No threads can exit the resource until they have somewhere to go, so the threads are stuck. ●● What does the keyword 'synchronized' do for us in Java? Answer: A keyword that ensures that a method or block of code can only be executed by one thread at a time, preventing thread interference. ●● What are the states of a thread in Java? Answer: New - Created but not yet started. Runnable - Ready to run and is waiting for CPU time. Waiting - Waiting indefinitely for another thread to perform a particular action.
Timed waiting - Waiting for a monitor lock to enter a synchronized block or method. Blocked - Waiting for a monitor lock to enter a synchronized block or method. Terminated - Completed its execution. ●● How can I create a Thread? Answer: Extend the Thread class or implement the Runnable interface, then override the run() method in both cases. ●● What method defines the functionality of my thread? Answer: run() method ●● What method is used to begin the execution of a thread? Answer: start() method ●● Daemon Thread Answer: A type of thread that runs in the background and does not prevent the program from exiting when all user threads have finished executing.