Free Sample questions for Oracle Certified Professional Java Programmer, Web Component Developer, Master Developer, JSP Servlet, EJB, JPA Certification. How to crack the TOP 1. Updated on February 2. What is the difference between Throw and Throws in Java Exception Handling?”You stare at the person asking you that question and think, I should know this! But at that moment, you can’t quite remember, and then kick yourself mentally for not preparing for your interview. Good thing that’s just a fake scenario and you’re definitely going to be able to answer that question and more when the time comes! The typical company hiring a Java programmer is looking for someone who can program well beyond the level taught in an introductory Java class. Java Certification Sample questions, Mock Exams. Select your Certification Exam and download the Question Bank. I spent a good amount of time for each Enthuware exam reviewing every question afterwards. Java Interview Questions; How System.out.println() works. Bit Manipulation Interview Questions and Answers; XOR in Java; Java Inner Class Example; When to use inner classes in Java; Inner vs nested class; Java. Interviewers ask questions that aren’t necessarily stumpers, but are meant to elicit a candidate’s deeper knowledge of the subject matter. While we would suggest you to learn Java thoroughly before facing an interview, this article will give you a special sneak peek into the Top 1. Java Interview Questions that one might confront during a job interview. Let’s start off with the easier questions and head out to the slightly tougher ones. Why is Java called the . Here’s a sequential step establishing the Platform independence feature in Java: The Java Compiler outputs Non- Executable Codes called . What is the Difference between JDK and JRE? When asked typical Java Interview Questions most startup Java developers get confused with JDK and JRE. And eventually, they settle for .
I. e., the JDK is bundle of software that you can use to develop Java based software. The “JRE” is the Java Runtime Environment. I. e., the JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Typically, each JDK contains one (or more) JRE’s along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc. We are sure you must be well- acquainted with the Java Basics. Now that we are settled with the initial concepts, let’s look into the Language specific offerings. Static variable is associated with a class and not objects of that class. For example: public class Explain. Static . We directly use the class name itself: Explain. Static. name. 4. What are the Data Types supported by Java? What is Autoboxing and Unboxing? This is one of the most common and fundamental Java interview questions. This is something you should have right at your finger- tips when asked. The eight Primitive Data types supported by Java are: Byte : 8- bit signed two’s complement integer. It has a minimum value of - 1. Short : 1. 6- bit signed two’s complement integer. It has a minimum value of - 3. Int : 3. 2- bit signed two’s complement integer. It has a minimum value of - 2,1. Long : 6. 4- bit signed two’s complement integer. It has a minimum value of - 9,2. Float. Double. Autoboxing: The Java compiler brings about an automatic transformation of primitive type (int, float, double etc.) into their object equivalents or wrapper type (Integer, Float, Double,etc) for the ease of compilation. Unboxing: The automatic transformation of wrapper types into their primitive equivalent is known as Unboxing. What is the difference between STRINGBUFFER and STRING? String object is immutable. Consider the following code snippet: String my. String = “Hello”. String = my. String + ” Guest”; When you print the contents of my. String the output will be “Hello Guest”. Although we made use of the same object (my. String), internally a new object was created in the process. That’s a performance issue. String. Buffer/String. Builder objects are mutable: String. Buffer/String. Builder objects are mutable; we can make changes to the value stored in the object. What this effectively means is that string operations such as append would be more efficient if performed using String. Buffer/String. Builder objects than String objects. String str = “Be Happy With Your Salary.''. Because Increments are a myth. Because Increments are a myth. What is Function Over- Riding and Over- Loading in Java? This is a very important concept in OOP (Object Oriented Programming) and is a must- know for every Java Programmer. Over- Riding: An override is a type of function which occurs in a class which inherits from another class. An override function “replaces” a function inherited from the base class, but does so in such a way that it is called even when an instance of its class is pretending to be a different type through polymorphism. That probably was a little over the top. The code snippet below should explain things better. Car . It is unrelated to either overriding or polymorphism. Functions in Java could be overloaded by two mechanisms ideally: Varying the number of arguments. Varying the Data Type. Calculate. Area. What is Constructors, Constructor Overloading in Java and Copy- Constructor? Constructors form the basics of OOPs, for starters. Constructor: The sole purpose of having Constructors is to create an instance of a class. They are invoked while creating an object of a class. Here are a few salient features of Java Constructors: Constructors can be public, private, or protected. If a constructor with arguments has been defined in a class, you can no longer use a default no- argument constructor – you have to write one. They are called only once when the class is being instantiated. They must have the same name as the class itself. They do not return a value and you do not have to specify the keyword void. If you do not create a constructor for the class, Java helps you by using a so called default no- argument constructor. Boss. Example snippet could be as follows: public class Boss. We don’t call him names.”. The copy constructor accepts a reference to its own class as a parameter. Note: Java Doesn’t support Copy Constructor. Nevertheless folks from C/C++ background often get confused when asked about Java Copy Constructors. What is Java Exception Handling? What is the difference between Errors, Unchecked Exception and Checked Exception? Anything that’s not Normal is an exception. Exceptions are the customary way in Java to indicate to a calling method that an abnormal condition has occurred. In Java, exceptions are objects. When you throw an exception, you throw an object. You can’t throw just any object as an exception, however — only those objects whose classes descend from Throwable. Throwable serves as the base class for an entire family of classes, declared in java. Here’s a hierarchical Exception class structure: An Unchecked Exception inherits from Runtime. Exception (which extends from Exception). The JVM treats Runtime. Exception differently as there is no requirement for the application- code to deal with them explicitly. A Checked Exception inherits from the Exception- class. The client code has to handle the checked exceptions either in a try- catch clause or has to be thrown for the Super class to catch the same. A Checked Exception thrown by a lower class (sub- class) enforces a contract on the invoking class (super- class) to catch or throw it. Errors (members of the Error family) are usually thrown for more serious problems, such as Out. Of. Memory. Error (OOM), that may not be so easy to handle. So we would suggest you to spend some time brushing up your Java skills. What is the difference between Throw and Throws in Java Exception Handling (remember this queston?)Throws: A throws clause lists the types of exceptions that a method might throw, thereby warning the invoking method – . You need to handle this list of exceptions I might throw.’ Except those of type Error or Runtime. Exception, all other Exceptions or any of their subclasses, must be declared in the throws clause, if the method in question doesn’t implement a try. It is therefore the onus of the next- on- top method to take care of the mess. Method() throws PRException. The Throw clause can be used in any part of code where you feel a specific exception needs to be thrown to the calling method. What is the Difference between byte stream and Character streams? Every Java Programmer deals with File Operations. To generate User reports, send attachments through mails and spill out data files from Java programs. And a sound knowledge on File Operation becomes even more important while dealing with Java questions. For reading and writing binary data, byte stream is incorporated. Programs use byte streams to perform byte input and output. Performing Input. Stream operations or Output. Stream operations means generally having a loop that reads the input stream and writes the output stream one byte at a time. You can use buffered I/O streams for an overhead reduction (overhead generated by each such request often triggers disk access, network activity, or some other operation that is relatively expensive). Character streams: Character streams work with the characters rather than the byte. In Java, characters are stored by following the Unicode (allows a unique number for every character) conventions. In such kind of storage, characters become the platform independent, program independent, language independent. What are File. Input. Stream and File. Output. Stream ? Explain with an example to read and write into files. File. Input. Stream : It contains the input byte from a file and implements an input stream. File. Output. Stream : It uses for writing data to a file and also implements an output stream. File. Handling . What are File. Reader and File. Writer ? Explain with an example to read and write into files. File. Reader : The File. Reader class makes it possible to read the contents of a file as a stream of characters. It works much like the File. Input. Stream, except the File. Input. Stream reads bytes, whereas the File. Reader reads characters. The File. Reader is intended to read text, in other words. One character may correspond to one or more bytes depending on the character encoding scheme. The File. Reader object also lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user’s computer, using File or Blob objects to specify the file or data to read. Java interview Questions . In java,c++ there are two types of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding). When you override methods, JVM determines the proper methods to call at the program’s run time, not at the compile time. Overloading occurs when several methods have same names but different number or type of parameters. Overloading is determined at the compile time. Different method signature and different number or type of parameters. Same method signature but different number of parameters. Same method signature and same number of parameters but of different type. Example of Overloading. Book. Details . This class definition is stored as a part of the serialized object. This stored metadata enables the deserialization process to reconstitute the objects and map the stream data into the class attributes with the appropriate type. Everytime an object is serialized the java serialization mechanism automatically computes a hash value. Object. Stream. Class's compute. Serial. Version. UID() method passes the class name, sorted member names, modifiers, and interfaces to the secure hash algorithm (SHA), which returns a hash value. The serial. Version. UID is also called suid. So when the serilaize object is retrieved , the JVM first evaluates the suid of the serialized class and compares the suid value with the one of the object. If the suid values match then the object is said to be compatible with the class and hence it is de- serialized. If not Invalid. Class. Exception exception is thrown. Changes to a serializable class can be compatible or incompatible. Following is the list of changes which are compatible: Add fields. Change a field from static to non- static. Change a field from transient to non- transient. Add classes to the object tree List of incompatible changes: Delete fields. Change class hierarchy. Change non- static to static. Change non- transient to transient. Change type of a primitive field So, if no suid is present, inspite of making compatible changes, jvm generates new suid thus resulting in an exception if prior release version object is used . The only way to get rid of the exception is to recompile and deploy the application again. If we explicitly mention the s. Uid using the statement. Version. UID = < integer value> then if any of the metioned compatible changes are made the class need not to be recompiled. But for incompatible changes there is no other way than to compile again. Q) What is the difference between final, finally and finalize() in Java? Ans) final - A final variable acts as a constant, a final class is immutable and a final method cannot be ovrriden while doing inheritance. 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. Object class. The method that is invoked while doing the garbage collection of the object. It could be used for allowing it to clean up its state. Good use cases will be to free connection pools , deallocate resources etc. Q)What is difference between Hash. Map and Hash. Table ? Ans) Both collections implements Map. Both collections store value as key- value pairs. The key differences between the two are. Hashmap is not synchronized in nature but hashtable is. Another difference is that iterator in the Hash. Map is fail- safe while the enumerator for the Hashtable isn't. Fail- safe - if the Hashtable is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a Concurrent. Modification. Exception? Hash. Map permits null values and only one null key, while Hashtable doesn't allow key or value as null. Q) What is difference between abstract class and interface ? Ans) A class is called abstract when it is declared with keywordabstract. Abstract class may contain abstract method. It can also contain n numbers of concrete method. Interface can only contain abstract methods. Abstract class can have concerete and abstract methods. The abstract class can have public, private, protected or default variables and also constants. In interface the variable is by default public final. In nutshell the interface doesnt have any variables it only has constants. A class can extend only one abstract class but a class can implement multiple interfaces. Abstract class doesn't support multiple inheritance whereas abstract class does. If an interface is implemented its mandatory to implement all of its methods but if an abstract class is extended its mandatory to implement all abstract methods. The problem with an interface is, if you want to add a new feature (method) in its contract, then you MUST implement those method in all of the classes which implement that interface. However, in the case of an abstract class, the method can be simply implemented in the abstract class and the same can be called by its subclass. Q) What is the difference between equals() and == ? Ans) == operator is used to compare the references of the objects. The default implementation uses == operator to compare two objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |