Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
48 Cards in this Set
- Front
- Back
Differences between Abstraction and Encapsulation |
Abstraction and encapsulation are complementary concepts. On the one hand, abstraction focuses on the behavior of an object.
|
|
What is JVM ? |
A Java virtual machine (JVM) is a process virtual machine that can execute Java bytecode. Each Java source file is compiled |
|
What does the “static” keyword mean ? |
The static keyword denotes that a member variable or method can be accessed, without requiring an instantiation of the class to |
|
Can you access non static variable in static context ? |
A static variable is initialized |
|
What are the Data Types supported by Java ? |
The eight primitive data types supported by the Java programming language are: |
|
What is autoboxing and unboxing? |
Autoboxing is the automatic conversion made by the Java compiler between the primitive types and their corresponding object |
|
What is Function Overriding and Overloading in Java ? |
Method overloading in Java occurs when two or more methods in the same class have the exact same name, but different parameters.
On the other hand, method overriding is defined as the case when a child class redefines the same method as a parent |
|
What are pass by reference and pass by value ? |
When an object is passed by value, this means that a copy of the object is passed. Thus, even if changes are made to that object, it doesn’t affect the original value.
When an object is passed by reference, this means that the actual object is not passed, rather |
|
What is the difference between processes and threads ? |
A process is an execution of a program, while a Thread is a single execution sequence within a process. A process can contain |
|
Explain different ways of creating a thread. Which one would you prefer and |
• A class may extend the Thread class.
|
|
What is the difference between a synchronized method and a synchronized
|
In Java programming, each object has a lock. A thread can acquire the lock for an object by using the synchronized keyword.
|
|
What’s a deadlock ? |
A condition that occurs when two processes are waiting for each other to complete, before proceeding. |
|
How do you ensure that N threads can access N resources without deadlock ? |
A very simple way to avoid deadlock while using N threads is to impose an ordering on the locks and force each thread to follow |
|
What are the basic interfaces of Java Collections Framework ? |
Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of
|
|
Why Collection doesn’t extend Cloneable and Serializable interfaces ? |
The Collection interface specifies groups of objects known as elements. Each concrete implementation of a Collection can choose
Some collections allow duplicate keys, while some other collections don’t. |
|
What is an Iterator ? |
The Iterator interface provides a number of methods that are able to iterate over any Collection.
Each Java Collection contains the iterator method that returns an Iterator instance. Iterators are capable of removing elements from the underlying collection during the iteration.
|
|
What is difference between fail-fast and fail-safe? |
The Iterator’s fail-safe property works with the clone of the underlying collection and thus, it is not affected by any modification |
|
How HashMap works in Java ? |
The HashMap requires a hash function and uses hashCode and equals methods,
If the key exists, its value is updated with the new value. Some important characteristics of a HashMap are its capacity, its load factor and the threshold resizing. |
|
What differences exist between HashMap and Hashtable ? |
• Both the HashMap and Hashtable classes implement the Map interface • A HashMap allows the existence of null keys and values, while a Hashtable doesn’t allow neither null keys, nor null values. • A Hashtable is synchronized, while a HashMap is not. Thus, HashMap is preferred in single-threaded environments, while a |
|
What is difference between Array and ArrayList ? |
• Arrays can contain primitive or objects, while an ArrayList can contain only objects.
|
|
What is the tradeoff between using an unordered array versus an ordered array ?
|
The major advantage of an ordered array is that the search times have time complexity of O(log n), compared to that of an unordered array, which is O (n).
The disadvantage of an ordered array is that the insertion operation has a time complexity of O(n), because the elements with higher values must be moved to make room for the new element. Instead, the insertion operation
|
|
What are some of the best practices relating to the Java Collection framework ? |
• Choosing the right type of the collection to use, based on the application’s needs, is very crucial for its performance. For example if the size of the elements is fixed and know a priori, we shall use an Array, instead of an ArrayList. |
|
What’s the difference between Enumeration and Iterator interfaces ? |
Enumeration is twice as fast as compared to an Iterator and uses very less memory. However, the Iterator is much safer compared
Also, Iterators allow the caller to remove elements from the underlying collection, something which is not possible with Enumerations.
|
|
What is the difference between HashSet and TreeSet ?
|
The HashSet is Implemented using a hash table and thus, its elements are not ordered. The add, remove, and contains methods of
On the other hand, a TreeSet is implemented using a tree structure. The elements in a TreeSet are sorted, and thus, the add, remove, and contains methods have time complexity of O(logn). |
|
What is the purpose of garbage collection in Java, and when is it used ? |
The purpose of garbage collection is to identify and discard those objects that are no longer needed by the application, in order for the resources to be reclaimed and reused.
|
|
What does System.gc() and Runtime.gc() methods do ?
|
These methods can be used as a hint to the JVM, in order to start a garbage collection. However, this it is up to the Java Virtual Machine (JVM) to start the garbage collection immediately or later in time.
|
|
When is the finalize() called ? What is the purpose of finalization ? |
The finalize method is called by the garbage collector, just before releasing the object’s memory. It is normally advised to release |
|
If an object reference is set to null, will the Garbage Collector immediately free the memory held by that object ? |
No, the object will be available for garbage collection in the next cycle of the garbage collector.
|
|
What is structure of Java Heap ? What is Perm Gen space in Heap ? |
The JVM has a heap that is the runtime data area from which memory for all class instances and arrays is allocated. It is created at the JVM start-up. Heap memory for objects is reclaimed by an automatic memory management system which is known as a
Heap memory consists of live and dead objects. Live objects are accessible by the application and will not be a subject of garbage collection. Dead objects are those which will never be accessible by the application, but have not been collected by the garbage collector yet. Such objects occupy the heap memory space until they are eventually collected by the |
|
What is the difference between Serial and Throughput Garbage collector ? |
The throughput gc uses a parallel version of the young generation collector |
|
When does an Object becomes eligible for Garbage collection in Java ? |
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is currently used |
|
Does Garbage collection occur in permanent generation space in JVM ? |
Garbage Collection does occur in PermGen space and if PermGen space is full or cross a threshold, it can trigger a full garbage |
|
What are the two types of Exceptions in Java ? Which are the differences between them ?
|
Java has two types of exceptions: checked exceptions and unchecked exceptions. Unchecked exceptions do not need to be
On the other hand, checked exceptions must be declared in a method or a constructor’s throws clause |
|
What is the difference between Exception and Error in java ?
|
Exception and Error classes are both subclasses of the Throwable class. The Exception class is used for exceptional conditions that a user’s program should catch.
The Error class defines exceptions that are not excepted to be caught by the user program.
|
|
What is the difference between throw and throws ? |
The throw keyword is used to explicitly raise a exception within the program. On the contrary, the throws clause is used to
Each method must explicitly specify which exceptions does not handle, so the callers of that method can guard against possible exceptions. Finally, multiple exceptions are separated by a comma |
|
What is the importance of finally block in exception handling ?
|
A finally block will always be executed, whether or not an exception is actually thrown. Even in the case where the catch statement is missing and an exception is thrown, the finally block will still be executed.
Last thing to mention is that the finally block is used to release resources like I/O buffers, database connections, etc. |
|
How does finally block differ from finalize() method ? |
A finally block will be executed whether or not an exception is thrown and is used to release those resources held by the application.
Finalize is a protected method of the Object class, which is called by the Java Virtual Machine (JVM) just before an object is garbage collected. |
|
What is the advantage of PreparedStatement over Statement ? |
PreparedStatements are precompiled and thus, their performance is much better. Also, PreparedStatement objects can be reused |
|
What is a Servlet ? |
The servlet is a Java programming language class used to process client requests and generate dynamic web content. Servlets are mostly used to process or store data submitted by an HTML form, provide dynamic content and manage state information that does not exist in the stateless HTTP protocol. |
|
Explain the architecture of a Servlet. |
The core abstraction that must be implemented by all servlets is the javax.servlet.Servlet interface.
Each servlet must implement it either directly or indirectly, either by extending javax.servlet.GenericServlet or javax.servlet.http.HTTPServlet.
Finally, each servlet is able to serve multiple requests in parallel using multithreading. |
|
What is the difference between an Applet and a Servlet ? |
An Applet is a client side java program that runs within a Web browser on the client machine. On the other hand, a servlet is a server side component that runs on the web server.
An applet can use the user interface classes, while a servlet does not have a user interface. Instead, a servlet waits for client’s HTTP requests and generates a response in every request. |
|
How are Observer and Observable used? |
Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. |
|
What is the Vector class? |
The Vector class provides the capability to implement a growable array of objects |
|
What is an Iterator interface? |
The Iterator interface is used to step through the elements of a Collection |
|
What is the difference between yielding and sleeping? |
When a task invokes its yield() method, it returns to the ready state.
When a task invokes its sleep() method, it returns to the waiting state. |
|
Which java.util classes and interfaces support event handling? |
The EventObject class and the EventListener interface support event processing. |
|
What are wrapped classes? |
Wrapped classes are classes that allow primitive types to be accessed as objects. |
|
Does garbage collection guarantee that a program will not run out of memory? |
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection |