Arulkumaran's Books Author Published 4+ Java/JEE career companion books that have sold over 30, copies. Maintaining a eBook (PDF): $ Learn Java/J2EE core concepts and design/coding issues. With. Java/J2EE sheets) files, Java Script files, pdf files, image files, html files etc from direct access. Employee logisticsTeamLead = new Manager("Cooma kumar", );. Java/J2EE Job Interview Companion [Arulkumaran Kumaraswamipillai, Sivayini Arulkumaran] on derscontcyptuhors.gq *FREE* shipping on qualifying offers. + Java/ J2EE Interview questions with clear and concise answers for: job Anuj Kumar.
|Language:||English, French, Japanese|
|Genre:||Health & Fitness|
|ePub File Size:||30.54 MB|
|PDF File Size:||17.50 MB|
|Distribution:||Free* [*Registration needed]|
Java Interview Questions - Ebook download as PDF File .pdf), Text File .txt) or read Download as PDF, TXT or read online from Scribd Arulazi Dhesiaseelan Employee logisticsTeamLead = new Manager("Cooma kumar" ))). + Java/J2EE Interview questions with clear and concise answers for: job seekers (junior/senior developers, architects, team/technical leads), promotion. arul kumar java pdf. Sandeep Kumar Nayak, Raees. Ahmad Khan, derscontcyptuhors.gq Beg. Arul Prakasham.S, derscontcyptuhors.gq,. GargX – Revolutionizing Java Based.
So start asking questions on appium. On which android version have you worked What are the functionalities you worked on Application? Have you worked on UFT? Okay, I am done with the interview, do you have any questions for me. Capgemini Selenium Interview Questions: How did you report failed test cases? Create Xpath for dynamically changing element.
How to handle pop-ups and frames? Write a Script for writing failed test cases. What are locators, types and which one is your favorite? Tell me why we need the test cases if we already write test scenarios? Tell me the quality of testing? Nishant Kanungo rated it liked it May 15, Qzjake rated it it was amazing Oct 30, Sneha rated it it was ok Oct 07, GuangliangLi rated it liked it Feb 12, Manasa Siri rated it it was amazing Mar 10, Vladimir Nikolov rated it really liked it May 05, Jimi Trianta rated it really liked it Feb 24, Kanna rated it it was amazing Mar 16, Meghala Devi rated it it was amazing May 27, Gonka rated it it was amazing May 03, Hekol rated it it was amazing Dec 29, Eduard Antsupov rated it it was amazing Apr 01, Dhirendra Bamrara rated it liked it Mar 13, Chandan rated it really liked it Jul 09, Krishna Kumar rated it really liked it Jun 17, There are no discussion topics on this book yet.
Readers Also Enjoyed. Goodreads is hiring! If you like books and love to build cool products, we may be looking for you. About Arulkumaran Kumaraswamipillai. Arulkumaran Kumaraswamipillai. Books by Arulkumaran Kumaraswamipillai. No trivia or quizzes yet. Now if you decide to modify the equals method of class Y so that it also provides equality comparison with class Z, then you will be violating this principle because no proper equals comparison exist for class X and class Z objects.
Similarly, if they are not equal, they must remain non-equal as long as they are not modified. So if you pass a null as an argument to your object o1, then it should return false. If you define a equals method then you must define a hashCode method as well.
Also it means that if you have two objects that are equal then they must have the same hashCode, however the reverse is not true i. So, If a field is not used in equals , then it must not be used in hashCode method.
Mastering EJB3.0 – Free PDF Book Download
If a class overrides the equals method, it must implement the hashCode method as well. The general contract of the hashCode method is that: Whenever hashCode method is invoked on the same object more than once during an execution of a Java public program, this method must consistently return the same integer result.
The integer result need not remain access consistent from one execution of the program to the next execution of the same program. If two objects are equal as per the equals method, then calling the hashCode method in each of the two objects must return the same integer result. If two objects are unequal as per the equals method, each of the two objects can return either two different integer results or same integer results i.
This hexadecimal representation is not what the users of your class want to see. Implementing a properly functioning clone method is complex and it is rarely necessary. You are better off providing some alternative means of object copying refer Q26 in Java section or simply not providing the capability.
A better approach is to provide a copy constructor or a static factory method in place of a constructor. The finalize method should method only be used in rare instances as a safety net or to terminate non-critical native resources.
If you do happen to call the finalize method in some rare instances then remember to call the super. When providing a user defined key class for storing objects in the HashMaps or Hashtables, what methods do you have to provide or override i.
You should override the equals and hashCode methods from the Object class. The default implementation of the equals and hashcode , which are inherited from the java.
MyObject 6c60f2ea. Also the toString method can be overridden to provide a proper string representation of your object. Key index array …. It is simplified for clarity. If two keys are equal then they must have the same hashCode value, But if two keys have the same hashCode value does not mean that they are equal. Why it is a best practice to implement the user defined key class as an immutable object?
The original key object will still be in the HashMap i.
Java/J2ee Job Interview Companion - 400+ Questions & Answers
These types of errors are very hard to trace and fix. Generally you use a java. Similar issues are possible with the Set e. HashSet as well. Java programming language enums are more powerful than their counterparts in other languages.
What is the main difference between a String and a StringBuffer class? StringBuilder was added in Java 5 and it is instance. Creating a new instance is rather identical in all respects to StringBuffer except that it is not synchronized, expensive. The above code would build 99 new String The above code creates only two new objects, the StringBuffer and the objects, of which 98 would be thrown away final String that is returned.
StringBuffer expands as needed, which is immediately. Creating new objects is not costly however, so it would be better to initialize the StringBuffer with the efficient. So use StringBuffer or StringBuilder for computation intensive operations, which offer better performance.
What is an immutable object? Immutable objects whose state i. Integer, java. Float, java. BigDecimal etc are immutable objects , enumerated types, colors e. Color is an immutable object , short lived objects like events, messages etc. So there is no chance of negative performance consequences. These types of errors are hard to debug and fix. Writing an immutable class is generally easy but there can be some tricky situations. Follow the following guidelines:.
A class is declared final i. All its fields are final final fields cannot be mutated once assigned. Do not provide any methods that can change the state of the immutable object in any way — not just setXXX methods, but any methods which can change the state. Wrong way to write an immutable class Right way to write an immutable class Wrong way to write a constructor: Right way is to copy the array before assigning in the constructor.
Out put: Before constructing Numbers are: After constructing Numbers are: This is because the object reference gets been mutated. Wrong way to write an accessor. A caller could get the array Right way to write an accessor by cloning. You have to deep copy the mutable objects referenced by your immutable class. Refer Q26 in Java section for deep vs. What is the main difference between pass-by-reference and pass-by-value? Other languages use pass-by-reference or pass-by-pointer.
But in Java no matter what type of argument you pass the corresponding parameter primitive variable or object reference will get a copy of that data, which is exactly how pass-by-value i. In Java, if a calling method passes a reference of an object as an argument to the called method then the passed- in reference gets copied first and then passed to the called method.
Both the original reference that was passed-in and the copied reference will be pointing to the same object. So no matter which reference you use, you will be always modifying the same original object, which is how the pass-by-reference works as well.
Pass-by-value for primitive variables vs Object references. If your method call involves inter-process e. Hence inter-process communication involves calling method passing objects as arguments to called method by-value in a serialized form, which can adversely affect performance due to marshaling and unmarshaling cost. What is serialization? How would you exclude a field of a class from serialization or what is a transient variable?
What is the common use? What is a serial version id? Serialization is a process of reading or writing an object. An object is marked serializable by implementing the java. Serializable interface, which is only a marker interface -- it simply allows the serialization mechanism to verify that the class can be persisted, typically to a file.
Transient variables cannot be serialized. The fields marked transient in a serializable object will not be transmitted in the byte stream. An example would be a file handle, a database connection, a system thread etc.
Such objects are only meaningful locally. So they should be marked as transient in a serializable class. When to use serialization? Do not use serialization if you do not have to. A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.
Refer Q57 on Enterprise section. Deep cloning or copy can be achieved through serialization. This may be fast to code but will have performance implications Refer Q26 in Java section. The objects stored in an HTTP session should be serializable to support in-memory replication of sessions to achieve scalability Refer Q20 in Enterprise section.
The flattened car object sits in the file system for some time. Later on, when you try to read i. InvalidClassException — because all serializable classes are automatically given a unique identifier. This exception is thrown when the identifier of the class is not equal to the identifier of the flattened object.
If you really think about it, the exception is thrown because of the addition of the new field. You can avoid this exception being thrown by controlling the versioning yourself by declaring an explicit serialVersionUID.
So, it is best practice to add your own serialVersionUID to your Serializable classes as soon as you create them as shown below:. This tool takes a full class name on the command line and returns the serialVersionUID for that compiled class.
There are 2 kinds of streams. Reader and Writer. The decorator design pattern attaches responsibilities to objects at runtime. Decorators are more flexible than inheritance because the inheritance attaches responsibility to classes at compile time.
Attaching responsibilities to classes at Attaching responsibilities to objects at runtime using a decorator compile time using subclassing. Inheritance aka subclassing attaches By attaching responsibilities to objects at runtime, you can apply changes responsibilities to classes at compile time. When to each individual object you want to change. Decorators decorate an object by enhancing or restricting functionality of an object it decorates.
The decorators add or restrict functionality to decorated objects either before or after forwarding the request. At runtime the BufferedInputStream bis , which is a decorator aka a wrapper around decorated object , forwards the method call to its decorated object FileInputStream fis.
InputStream java. OutputStream java. System java. Reader java. FileInputStream java. FileOutputStream java. InputStreamReader java.
Core Java Interview Questions
Only a few subclasses of abstract classes are java. BufferedReader java. FileReader java. FileWriter shown for clarity. One way to cater for this scenario in Java is to use threads but having almost one-to-one ratio of threads clients will have threads is prone to enormous thread overhead and can result in performance and scalability problems due to consumption of memory stacks i.
Process Multiplexing. The good thing about NIO channels is that they can be asynchronously interrupted and closed. The keys i. Key1, Key2 etc represented by the SelectionKey class encapsulate the relationship between a specific selectable channel and a specific selector.
Buffers hold data. Channels can fill and drain Buffers. Buffers replace the need for you to do your own buffer management using byte arrays. NIO uses a reactor design pattern, which demultiplexes events separating single stream into multiple streams and dispatches them to registered object handlers. The reactor pattern is similar to an observer pattern aka publisher and subscriber design pattern , but an observer pattern handles only a single source of events i.
The intent of an observer pattern is to define a one-to-many dependency so that when one object i. Another sought after functionality of NIO is its ability to map a file to memory.
Top 100 Hadoop Interview Questions and Answers 2018
Another feature of NIO is its ability to lock and unlock files. Locks can be exclusive or shared and can be held on a contiguous portion of a file. But file locks are subject to the control of the underlying operating system. PI BP A As shown below, with buffering large chunks of a file are read from a disk and then accessed a byte or character at a time. Without buffering: Instead of reading a character or a byte at a time, the above code with buffering can be improved further by reading one line at a time as shown below:.
By default the System. This is required for any interactivity between an input prompt and display of output. Frameworks like Log4J are configurable, flexible, extensible and easy to use. The Java runtime itself cannot know the length of a file, querying the file system for isDirectory , isFile , exists etc must query the underlying operating system. What is the main difference between shallow cloning and deep cloning of objects? So to achieve a deep copy the classes must be edited or adjusted.
Shallow copy: If a shallow copy is performed on obj-1 as shown in fig-2 then it is copied but its contained objects are not. The contained objects Obj-1 and Obj-2 are affected by changes to cloned Obj Java supports shallow cloning of objects by default when a class implements the java.
Cloneable interface. Deep copy: If a deep copy is performed on obj-1 as shown in fig-3 then not only obj-1 has been copied but the objects contained within it have been copied as well. Serialization can be used to achieve deep cloning. Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead. O bj-1 O bj-1 C loned O bj-1 O bj D eep cloning O bj For example invoking clone method on a collection like HashMap, List etc returns a shallow copy of HashMap, List, instances.
This means if you clone a HashMap, the map instance is cloned but the keys and values themselves are not cloned. If you want a deep copy then a simple method is to serialize the HashMap to a ByteArrayOutputSream and then deserialize it. This creates a deep copy but does require that all keys and values in the HashMap are Serializable. Main advantage of this approach is that it will deep copy any arbitrary object graph. Refer Q23 in Java section for deep copying using Serialization.
Alternatively you can provide a static factory method to deep copy. What is the difference between an instance variable and a static variable? How does a local variable compare to an instance or a static variable? Give an example where you might use a static variable? Static variables Instance variables Class variables are called static variables. There is only one Instance variables are non-static and there is one occurrence of a class variable per JVM per class loader.
Also known as a member variable or a variables are initialized. A static variable is used in the singleton pattern. Refer Q51 in Java section. A static variable is used with a final modifier to define constants. Local variables Instance and static variables Local variables have a narrower scope than instance Instance variables have a narrower scope than static variables.
The lifetime of a local variable is determined by execution Instance and static variables are associated with objects and path and local variables are also known as stack variables therefore live in the heap.
Refer Q34 in Java section for because they live on the stack. For a local variable, it is illegal for code to fail to assign it a Both the static and instance variables always have a value. If value. It is the best practice to declare local variables only your code does not assign them a value then the run-time where required as opposed to declaring them upfront and system will implicitly assign a default value e.
Java does not support global, universally accessible variables. You can get the same sorts of effects with classes that have static variables. Give an example where you might use a static method? Static methods prove useful for creating utility classes, singleton classes and factory methods Refer Q51, Q52 in Java section. Utility classes are not meant to be instantiated.
Improper coding of utility classes can lead to procedural coding. Math, java. Collections etc are examples of utility classes in Java. What are access modifiers?
Modifier Used with Description public Outer classes, interfaces, A class or interface may be accessed from outside the constructors, Inner classes, methods package. Constructors, inner classes, methods and field and field variables variables may be accessed wherever their class is accessed. Outer classes, inner classes, Accessed only from within the package in which they are Package by interfaces, constructors, methods, and declared.
Where and how can you use a private constructor? Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing. The instantiation is done by a public static method i. Collections class Refer Q16 in Java section.
StringUtils etc. What is a final modifier? Explain other Java modifiers? A final class can not be subclassed. Modifier Class Method Variable static A static inner class is just an inner A static method is called by classname. There is only one class.
If a method is abstract whenever one or more abstract then the entire class must be abstract. Acquires a lock on the instance for non- static methods.
Method cannot be overridden. Makes the variable extended immutable. No body, only signature. Since other threads cannot see local variables, there is no need to mark local variables as volatile. What is the difference between final, finally and finalize in Java? Refer Q31 in Java section. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block except System.
Use the finally block to close files or to release other system resources like database connections, statements etc. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state.
Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize method. Refer Q19 in Java Section. If you use the logical operator you can get a NullPointerException. Short-circuiting means that an operator only evaluates as far as it has to, not as far as it can.
If the variable 'obj' equals null, it won't even try to evaluate the 'obj. This protects the potential NullPointerException. How does Java allocate stack and heap memory? MI CI A Each time an object is created in Java it goes into the area of memory known as heap. The primitive variables like int and double are allocated in the stack i.
Last In First Out queue , if they are local variables and in the heap if they are member variables i. In Java methods and local variables are pushed into stack when a method is invoked and stack pointer is decremented when a method call is completed. In a multi-threaded application each thread will have its own stack but will share the same heap. This is why care should be taken in your code to avoid any concurrent access issues in the heap space. The stack is thread-safe because each thread will have its own stack with say 1MB RAM allocated for each thread but the heap is not thread-safe unless guarded with synchronization through your code.
The stack space can be increased with the —Xss option. All Java methods are automatically re-entrant. It means that several threads can be executing the same method at once, each with its own copy of the local variables. A Java method may call itself without needing any special declarations. This is known as a recursive method call.
Given enough stack space, recursive method calls are perfectly valid in Java though it is tough to debug. Recursive methods are useful in removing iterations from many sorts of algorithms. All recursive functions are re-entrant but not all re-entrant functions are recursive. Idempotent methods are methods, which are written in such a way that repeated calls to the same method with the same arguments yield same results.
For example clustered EJBs, which are written with idempotent methods, can automatically recover from a server failure as long as it can reach another server i. Explain Outer and Inner classes or Nested classes in Java? When will you use an Inner Class? LF SE A In Java not all classes have to be defined separate from each other. You can put the definition of one class inside the definition of another class.
The inside class is called an inner class and the enclosing class is called an outer class. So when you define an inner class, it is a member of the outer class in much the same way as other members like attributes, methods and constructors.
Where should you use inner classes? Code without inner classes is more maintainable and readable. When you access private data members of the outer class, the JDK compiler creates package-access member functions in the outer class for the inner class to access the private members. This leaves a security hole. In general we should avoid using inner classes. Inner classes are used primarily to implement helper classes like Iterators, Comparators etc which are used in the context of an outer class.
Explain outer and inner classes? Inner Local class Defined within a block of code. Most commonly used in button. StaticNestedClass ;. The above line is valid. It is an instantiation of a member inner class. An instance of an inner class can exist only within an instance of an outer class. The sample code for the above is shown below:. What is type casting? Explain up casting vs. When do you get ClassCastException? Type casting means treating a variable of one type as though it is another type.
When up casting primitives as shown below from left to right, automatic conversion occurs. But if you go from right to left, down casting or explicit casting is required. Casting in Java is safer than in C or other languages that allow arbitrary casting. Java only lets casts occur when they make sense, such as a cast between a float and an int. However you can't cast between an int and a String is an object in Java. Down casting or explicit casting is required.
When it comes to object references you can always cast from a subclass to a superclass because a subclass object is also a superclass object.
You can cast an object implicitly to a super class type i. You can cast down the hierarchy as well but you must explicitly write the cast and the object must be a legitimate instance of the class you are casting to.
The ClassCastException is thrown to indicate that code has attempted to cast an object to a subclass of which it is not an instance. Using these constructs can be unmaintainable due to large if and elseif statements and can affect performance if used in frequently accessed methods or loops. Look at using visitor design pattern to avoid these constructs where applicable.
Refer Q11 in How would you go about section….
You can also get a ClassCastException when two different class loaders load the same class because they are treated as two different classes. What do you know about the Java garbage collector?
When does the garbage collection occur? Explain different types of references in Java? Each time an object is created in Java, it goes into the area of memory known as heap. The Java heap is called the garbage collectable heap. The garbage collection cannot be forced. The garbage collector runs in low memory situations. When it runs, it releases the memory allocated by an unreachable object. The garbage collector runs on a low priority daemon i.
You can nicely ask the garbage collector to collect garbage by calling System. Then the object becomes unreachable and the garbage collector will figure it out. Java automatically collects all the unreachable objects periodically and releases the memory consumed by those unreachable objects to be used by the future reachable objects. We can use the following options with the Java command to enable tracing for garbage collection events. Explain types of references in Java?
So it is useful for implementing caches while avoiding memory leaks. Can be used for implementing canonical maps.
WeakHashMap implements a HashMap with keys held by weak references. Can be useful when you want to be notified that an object is about to be collected. If you have a circular reference of objects, but you no longer reference it from an execution thread, will this object be a potential candidate for garbage collection? LF MI A Refer diagram below. Garbage Collecting Circular References. Discuss the Java error handling mechanism?
What is the difference between Runtime unchecked exceptions and checked exceptions? Typical Java programs should not catch Errors. Most programs throw and catch objects that derive from the Exception class. Exceptions indicate that a problem occurred but that the problem is not a serious JVM problem. An Exception class has many subclasses.
These descendants indicate various types of exceptions that can occur. For example, NegativeArraySizeException indicates that a program attempted to create an array with a negative size. One exception subclass has special meaning in the Java language: All the exceptions except RuntimeException are compiler checked exceptions.
Failure to do so raises a compiler error. A RuntimeException class represents exceptions that occur within the Java virtual machine during runtime. An example of a runtime exception is NullPointerException. The cost of checking for the runtime exception often outweighs the benefit of catching it.
Attempting to catch or specify all of them all the time would make your code unreadable and unmaintainable. The compiler allows runtime exceptions to go uncaught and unspecified.
If you like, you can catch these exceptions just like other exceptions. In addition, you can create your own RuntimeException subclasses and this approach is probably preferred at times because checked exceptions can complicate method signatures and can be difficult to follow.
Exception handling in Java is polymorphic in nature. For example if you catch type Exception in your code then it can catch or throw its descendent types like IOException as well. So if you catch the type Exception before the type IOException then the type Exception block will catch the entire exceptions and type IOException block is never reached. As shown in the diagram , think basket of catching an exception in a basket. Right approach.
The diagram above is an example for illustration only.
We should only catch specific subtypes of the Exception class. Having a bigger basket i. Exception will hide or cause problems. The FileNotFoundException is extended i. The exception stack trace helps you pinpoint where an exception occurred by showing you the exact sequence of method calls that lead to the exception. By throwing your exception early, the exception becomes more accurate and more specific.
Avoid suppressing or ignoring exceptions. Also avoid using exceptions just to get a flow control. Use the following code because you get a more accurate stack trace: You should not try to catch the exception before your program can handle it in an appropriate manner.
The natural tendency when a compiler complains about a checked exception is to catch it so that the compiler stops reporting errors. It is a bad practice to sweep the exceptions under the carpet by catching it and not doing anything with it.Anonymous inner class always extend a class or implement an interface.
This is because if you move one class up the hierarchy then you will have to move other classes up the hierarchy as well. The features of the OO programming languages like polymorphism, inheritance and encapsulation make it powerful. The process used by object- oriented programming languages to implement polymorphism is called dynamic binding. We can also get a ClassCastException when two different class loaders load the same class because they are treated as two different classes. Where and how can you use a private constructor?
How would you go about describing Web services? Veera rated it liked it Jun 25, When a thread arrives at the first instruction in a block of code it must obtain a lock on the referenced object.
For a detailed explanation with a sample program, read Java Heap vs Stack Memory.
- BURNT OFFERINGS PDF
- CHUK AND GEK EBOOK
- WARHAMMER 40K NECRON CODEX PDF
- BROADWAY SHEET MUSIC PDF
- THE PASSION OF THE WESTERN MIND PDF
- DISTRIBUTED SYSTEM COULOURIS EBOOK
- NETWORK SYNTHESIS FOSTER CAUER FORM PDF
- IMCI PHILIPPINES PDF
- GOOGLE EBOOK ER
- MAYYAZHIPPUZHAYUDE THEERANGALIL PDF
- PROIBITO TABITHA SUZUMA EPUB DOWNLOAD
- EXCITOTOXINS THE TASTE THAT KILLS PDF
- ADOBE PDF WRITER TRIAL
- ISO 45001 PDF PORTUGUES