0% found this document useful (0 votes)
2 views

Compiled Interview Questions Advanced Java Developer Shuhrath Jamil

Uploaded by

Jamil Shuhrath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Compiled Interview Questions Advanced Java Developer Shuhrath Jamil

Uploaded by

Jamil Shuhrath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Compiled Interview Questions : Advanced Java Developer:

Shuhrath Jamil
10:09

1. How does a garbage collection prevent a Java application from going


out of memory?
○ It does not; Garbage collection simply cleans up unused memory when an object goes
out of scope and is no longer needed. However, an application can create a huge
number of large objects that causes an out of memory error.

2. What differences exist between Hash-map and Hash-table in Java?


- 3 basic differences :
- Hash-table is synchronized; whereas Hash-map is not; This makes
Hash-map better for nonthreaded applications, as unsynchronized
objects typically perform better than synchronized ones.
- Hash-table does not allow null keys or values; Hash-map allows one
null key and any number of null values;
- One of Hash-map's subclasses is Linked-Hash-map, so in the event that
you'd want predictable iteration order, you could easily swap out the
Hash-map for a linked-HashMap. This is difficult during Hash-table;

3. What is reflection and why is it useful?


-Reflection means a code able to inspect other code in the same system
or in itself and to modifications at runtime;
Example : You have an object of an unknown type in Java and you
would like to call a 'dosomething4 method on it if one exists; Java's
static typing system is not really designed to support this unless the
object conforms to a known interface; But using reflection your code
can look at the object and find out if it has a method called 'do-
something' and then call it if you want to.

4. What is the difference between Exception and Error in Java?


-An error indicates serious problem that a reasonable application should
not try to catch;
-An exception indicates conditions that a reasonable application might
want to catch ;

5. What is the difference between an interface and an abstract class?


6. Can == be used on Enum?
-Yes, Enums have tight instance controls that allows you to use ==to
compare instances

7. How can I synchronize two java processes?


- It is not possible to do something like that in Java. Different Java

Quick Notes Page 1


- It is not possible to do something like that in Java. Different Java
applications will use different JVM's fully separating themselves into
different black-boxes; However you have to options:
- Use sockets or channels; Basically one application will open the
listening socket and start waiting until it receives some signal; The other
application will connect there, and send signals when it had completed
something; This is used in 99% cases;
- You can call 'winapi' from Java (on Windows)

8. Is Java pass-by-reference or pass-by-value?


-Java is always pass-by-value; Unfortunately, when we pass the value
of an object, we are passing the reference to it; There is no such thing as
pass-by-reference in Java. This is confusing to beginners;

9. Is there anything like static class in Java?


- Java has no way of making a top-level class static but you can stimulate
a static class like this
- Declare your class final-prevents extension of the class since extending
a static class makes no sense;
- Make the constructor private-prevents instantiation by client code as it
makes no sense to instantiate a static class;
- Make all the members and functions of the class static-since the class
cannot be instantiated, no instance methods can be called or instance
fields accessed;
- Note that the compiler will not prevent you from declaring an instance
member; the issue will only show up if you attempt to call the instance
member.

10. What is difference between fail-fast and fail-safe?

11. What is the structure of Java Heap?


- The JVM has a heap that is the runtime data area from which memory
for all class instances and arrays is located; It is created at the JVM
start-up. Heap memory for objects is reclaimed by an automatic
memory management system which is known as the garbage collector;
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 garbage collector.

12. What is the JIT?


-The JVM's mechanism by which it can optimize code at runtime.
JIT means just in time. It is a central feature of any JVM. Among other
optimizations, it can perform code inlining, lock coarsening, lock
eliding, escape analysis etc. The main benefit of JIT is on the
programmer's side; code should be written so that it just works; If the
code can be optimized at runtime, more often than not, the JIT will find

Quick Notes Page 2


code can be optimized at runtime, more often than not, the JIT will find
a way.

13. What is the difference between throw and throws?


- The throw keyword is specifically used to raise an exception within the
program. On the contrary, the throws clause is used to indicate those
exceptions that are not handled by a method; Each method must clearly
specify which exceptions it does not handle, so the callers of the method
can guard against possible exceptions. Finally, multiple exceptions are
separated by a comma.

14. What is the main difference between String-buffer and String-builder?


- String-buffer is synchronized, string-builder is not. When something I
synchronized, then multiple threads can access and modify it without
any problem or side effect. String-buffer is synchronized; so it can be
used with multiple threads without any problem.
- String-builder is faster because it is not synchronized.

15. What is the trade-off between using an un-ordered array versus an


ordered array?
-The major benefit of an ordered array is that the search times have time
complexity of O (log n), compared to that of an un-ordered array, which
is O (n).. The disadvantage of an ordered array is that the inserting
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 for an unordered array takes constant
time of O(1).

16. Why does Java have transient fields?


-The transient keyword in Java is used to indicate that a field should not
be part of the serialization;
By default, all of object's variables get converted into a persistent state;
In some cases, you may want to avoid persisting some variables because
you do not have the need to persist those variables; So you can declare
those variables as transient.

17. Does Java support default parameter values?


- NO; but we can use overloading instead of default parameters.

18. Explain Marshalling and De-marshalling?


- Marshalling is the process of transforming the memory representation
of an object to a data format suitable for storage or submission; It is
typically used when data must be moved between different parts of a
computer program or from one program to another; The opposite

Quick Notes Page 3


computer program or from one program to another; The opposite
process is called de-marshalling.

Quick Notes Page 4

You might also like