{"id":28594,"date":"2017-06-23T11:07:32","date_gmt":"2017-06-23T11:07:32","guid":{"rendered":"https:\/\/www.whizlabs.com\/?p=28594"},"modified":"2024-05-22T12:14:12","modified_gmt":"2024-05-22T06:44:12","slug":"java-interview-questions","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/","title":{"rendered":"Top 7 Interview Questions for Java Developers"},"content":{"rendered":"<p>This article talks about top 7 of the most frequently asked questions in the job interview for the Java developers. If we go through these questions and its respective answers, it would serve as a good preparation for facing the actual interview questions.<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/www.whizlabs.com\/ocajp-scja\/\">OCAJP 8 Certification Exam<\/a><\/strong><\/li>\n<li><a href=\"https:\/\/www.whizlabs.com\/oracle-certified-associate-java-se-7-programmer\/\"><strong>OCAJP 7 Certification Exam<\/strong><\/a><\/li>\n<\/ul>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ea7e02;color:#ea7e02\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ea7e02;color:#ea7e02\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#1_Describe_4_fundamental_principles_of_object-oriented_programming_and_give_code_examples_to_demonstrate_those_principles_in_Java\" >1. Describe 4 fundamental principles of object-oriented programming, and give code examples to demonstrate those principles in Java.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#2_How_does_the_Java_virtual_machine_manage_the_lifecycle_of_an_object_in_the_memory\" >2. How does the Java virtual machine manage the lifecycle of an object in the memory?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#3_What_are_annotations_and_how_to_define_and_use_them\" >3. What are annotations and how to define and use them?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#4_What_is_generics_Describe_and_illustrate_generic_types_and_generic_methods\" >4.\u00a0What is generics? Describe and illustrate generic types and generic methods.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#5_Describe_Java_lambda_expressions_and_give_examples_to_demonstrate_their_usage\" >5.\u00a0Describe Java lambda expressions and give examples to demonstrate their usage.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#6_Describe_commonly_used_methods_of_three_interfaces_of_the_Java_Collections_API_List_Set_and_Map\" >6.\u00a0Describe commonly used methods of three interfaces of the Java Collections API: List, Set and Map.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.whizlabs.com\/blog\/java-interview-questions\/#7_What_is_serialization_and_how_to_implement_it_in_the_Java_programming_language\" >7.\u00a0What is serialization and how to implement it in the Java programming language?<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Describe_4_fundamental_principles_of_object-oriented_programming_and_give_code_examples_to_demonstrate_those_principles_in_Java\"><\/span>1. Describe 4 fundamental principles of object-oriented programming, and give code examples to demonstrate those principles in Java.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Object-oriented programming is a program paradigm based on the concept of objects. An object may contain data, in the form of fields, and behavior, in the form of methods.<\/p>\n<p>Object-oriented programming features 4 fundamental principles, including inheritance, polymorphism, abstraction and encapsulation.<\/p>\n<ol>\n<li><b> Inheritance<\/b><\/li>\n<\/ol>\n<p>Inheritance is a mechanism where one type acquires, or inherits, data and behavior from another. This mechanism facilitates code reuse through type hierarchies.<\/p>\n<p>The type that inherits from the other is called subtype (or child), and the one that is inherited from is called supertype (or parent). When inheritance is related to classes, they are called subclass and superclass; when it is about interfaces, they are called subinterface and superinterface.<\/p>\n<p>Inheritance allows members of a supertype to be reused in its subtypes, while still lets subtypes declare their own fields and methods. Note that a supertype can be inherited by any number of subtypes, but a subtype can only directly inherit from a supertype.<\/p>\n<p>In the Java programming language, inheritance can be achieved using the\u00a0<i>extends\u00a0<\/i>keyword. The following is an example of class inheritance:<\/p>\n<pre>public class Super {\r\n\u00a0\u00a0\u00a0 protected String name = \"Whizlabs\";\r\n\u00a0\u00a0\u00a0 protected void print() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(name);\r\n\r\n\u00a0\u00a0\u00a0 }\r\n\r\n}\r\n\r\npublic class Sub extends Super { }\r\n<\/pre>\n<p>Since the <i>Sub<\/i> class extends the <i>Super<\/i> class, it inherits the <i>name<\/i> field and <i>print<\/i> method from the superclass and can use these members without defining them.<\/p>\n<p>Let&#8217;s run a code fragment:<\/p>\n<pre>Sub object = new Sub();\r\nobject.print();\r\n<\/pre>\n<p>The above fragment prints <i>&#8220;Whizlabs&#8221;<\/i> when executed, although the <i>Sub<\/i> class does not define any member of its own. The <i>print<\/i> method is, in fact, inherited from the <i>Super<\/i> class.<\/p>\n<ol start=\"2\">\n<li><b> Polymorphism<\/b><\/li>\n<\/ol>\n<p>Polymorphism is a principle in which an object reference can take many different forms. Polymorphic features of the Java language are often demonstrated via the use of one reference variable referencing objects of various types. The reference type is the same as, or a parent of, the referenced object types. As a result, a method can behave differently depending on the actual objects it is invoked on.<\/p>\n<p>The following class declarations illustrate this principle:<\/p>\n<pre>public class Super {\r\n\u00a0\u00a0\u00a0 protected void print() { }\r\n}\r\n\r\npublic class Sub1 extends Super {\r\n\u00a0\u00a0\u00a0 public void print() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Printed from Sub1\");\r\n\u00a0\u00a0\u00a0 }\r\n}\r\n\r\npublic class Sub2 extends Super {\r\n\u00a0\u00a0\u00a0 public void print() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Printed from Sub2\");\r\n\u00a0\u00a0\u00a0 }\r\n}\r\n<\/pre>\n<p>Let&#8217;s execute the following code fragment:<\/p>\n<pre>Super object = null;\r\nobject = new Sub1();\r\nobject.print();\r\nobject = new Sub2();\r\nobject.print();\r\n<\/pre>\n<p>The above fragment prints out <i>&#8220;Printed from Sub1&#8221;<\/i> and <i>&#8220;Printed from Sub2&#8221;<\/i> in sequence, even though the <i>print<\/i> method is invoked twice on the same reference variable, <i>object<\/i>. The reason is that variable <i>object<\/i> references two different objects when these invocations are made. This discrepancy in method behavior is called polymorphism.<\/p>\n<ol start=\"3\">\n<li><b> Abstraction<\/b><\/li>\n<\/ol>\n<p>Abstraction is a process of hiding the implementation details from users and exposing only essential features of the underlying objects. Generally speaking, abstraction allows users to know what an object does without the need to understand how it does.<\/p>\n<p>In the Java programming language, abstraction is typically achieved through the use of interfaces and abstract classes. The following examples illustrate the abstraction principle. Let&#8217;s get started with the declaration of an interface and abstract class:<\/p>\n<pre>public interface MyInterface {\r\n\u00a0 \u00a0 void complicatedLogic();\r\n}\r\n\r\npublic abstract class MyAbsClass {\r\n\u00a0 \u00a0 abstract void complicatedLogic();\r\n}\r\n<\/pre>\n<p>A user can use the <i>complicatedLogic<\/i> method of <i>MyInterface<\/i> or <i>MyAbsClass<\/i> without knowing its implementation:<\/p>\n<pre>public void callInterfaceMethod(MyInterface arg) {\r\n\u00a0 \u00a0 arg.complicatedLogic ();\r\n}\r\n\r\npublic void callAbsClassMethod(MyAbsClass arg) {\r\n\u00a0 \u00a0 arg.complicatedLogic ();\r\n}\r\n<\/pre>\n<p>In the above examples, the <i>MyInterface<\/i> interface and <i>MyAbsClass<\/i> class abstract away the implementation details from the user, allowing the implementation provider to change the code if necessary.<\/p>\n<ol start=\"4\">\n<li><b> Encapsulation<\/b><\/li>\n<\/ol>\n<p>Encapsulation is a mechanism of including within an object everything it needs, and doing this in a way that other objects cannot access its internal structure. In other words, encapsulation refers to wrapping data (variables) and code acting on the data (methods) together as a single unit. When applying encapsulation, variables of a class are hidden from others, and can only be accessed and operated on through methods of their own class.<\/p>\n<p>In the Java programming language, encapsulation is often achieved by declaring variables of a class with the <i>private<\/i> access modifier and providing <i>public<\/i> methods to work on these variables, like the following example:<\/p>\n<pre>public class Data {\r\n\u00a0\u00a0\u00a0 private int value;\r\n\u00a0\u00a0\u00a0 public int getValue() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return this.value;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 public void setValue(int value) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.value = value;\r\n\u00a0\u00a0\u00a0 }\r\n}<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"2_How_does_the_Java_virtual_machine_manage_the_lifecycle_of_an_object_in_the_memory\"><\/span>2. How does the Java virtual machine manage the lifecycle of an object in the memory?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li><b>Background information<\/b><\/li>\n<\/ol>\n<p>The lifecycle of an object starts when it is created with the <i>new<\/i> operator or a similar mechanism. However, it cannot be explicitly destroyed through an executable code. The only way to remove an object in Java is to use garbage collection.<\/p>\n<p>When a new object is generated, it is stored in the heap memory, and kept there as long as this object is referenced from somewhere in the program. It can be referenced from a static variable in the metaspace, an instance variable in the heap memory itself, a local variable in the stack memory, etc.<\/p>\n<p>The most interesting thing about the lifecycle of an object is when it is dereferenced, or no longer referenced from any section of the program. At this point, the object is eligible for automatic garbage collection and ready to be discarded.<\/p>\n<p>Automatic garbage collection is the process of looking into the heap memory to mark live objects and remove the leftover. When an unreferenced object is removed, the memory space it occupied can be reclaimed to be reused. This process helps free developers of a tedious and error-prone task: allocating and deallocating memory.<\/p>\n<ol start=\"2\">\n<li><b> Generational garbage collection process<\/b><\/li>\n<\/ol>\n<p>In general, the collection process works through two steps:<\/p>\n<ul>\n<li>First, object trees are navigated from the garbage collection roots; these roots include local variables, static variables, active Java threads and Java native interface references. All objects in these trees are marked referenced.<\/li>\n<li>Second, unreferenced objects, which have not been marked in the previous step, are removed and the free space is returned to the JVM. If a garbage collection process is major (major and minor garbage collections will be described later), referenced objects may be compacted, allowing new objects to occupy contiguous memory space.<\/li>\n<\/ul>\n<p>Marking and removing objects is a time-consuming process, and always applying it to all objects is inefficient. Empirical analysis has shown that most objects have a very short life. To take advantage of this pattern and insure all unused objects are removed in an effective way, the idea of generational garbage collection has come up.<\/p>\n<p>The following image illustrates memory allocation in a heap with generational garbage collection (the ratios between different areas in the image illustrate default values in a server JVM \u2013 Eden over S0 or S1 = 8:1, Young Generation over Old Generation = 1:2):<\/p>\n<p>The young generation\u00a0is the place where all new objects are allocated. If an object survives minor garbage collections, it will be moved to the old generation, where the object may be destroyed during a major collection, or live until the program terminates.<\/p>\n<p>The young generation is comprised of three spaces &#8211;\u00a0eden\u00a0and two\u00a0survivor spaces, S0 and S1:<\/p>\n<ul>\n<li>The eden space is where all objects are first allocated. When this space fills up, a minor collection is triggered. Referenced objects are moved to the first survivor space (S0), while the unreferenced are deleted. At this point, the eden space is cleared and ready to keep new objects. Both eden and the second survivor space (S1) are empty now.<\/li>\n<li>When the next minor collection cycle is set off, the same things happen again. Unused objects are discarded, and live objects are moved to a survivor space. This time, however, the survivors are moved to S1 instead of S0. Objects in S0 that survived the last collection may be deleted (due to being unreferenced), copied to S1, or promoted to the old generation. Now, both eden and S0 are clear.<\/li>\n<li>The above steps are repeated over and over. An object will eventually be moved to the old generation if it survives all minor collections and a certain criterion is met, such as its age reaches a threshold, the number of times it is copied increases to a limit, or it is too large to be copied to the other survivor space.<\/li>\n<\/ul>\n<p>The\u00a0old generation\u00a0is where long-lived objects that have survived minor collections are promoted to. This space is often garbage-collected when it fills up. A collection in the old generation may include object compaction, and is called major garbage collection.<\/p>\n<p>All garbage collections are &#8220;Stop the World&#8221; events, meaning that all application threads are stopped until the operation finishes. A major collection is typically takes much longer than a minor one as it must go through all referenced objects. This will affect the responsiveness of the program. As a result, the type of the garbage collector in use may have an impact on JVM performance.<\/p>\n<ol start=\"3\">\n<li><b> Performance goals<\/b><\/li>\n<\/ol>\n<p>Different applications have different requirements on garbage collections. Typically, a garbage collector focus on either of two main goals: throughput and responsiveness:<\/p>\n<ul>\n<li>Throughput is the amount of work implemented by an application in a specific duration. Specifically, it is the percentage of total time not spent in garbage collection over a long period of time. This goal is important in a web server, for example, as the number of serviced requests is much more important than pause time, which may be hidden in the disguise of network latencies.<\/li>\n<li>Responsiveness (pause time) refers to how quickly an application responds to a request. This is measured by the time when the application is unresponsive due to a garbage collection in progress. For instance, a game application should consider this goal one of the top priorities since even short pauses may negatively affect the user experience.<\/li>\n<\/ul>\n<p>Some other goals may be taken into consideration, such as footprint or promptness. Footprint\u00a0is the working set of a process, measured in pages and cache lines. This goal is critical in systems with limited physical memory. Promptness\u00a0is the duration between an object becoming unused and the memory being reclaimed. This performance measure is important for distributed systems.<\/p>\n<p>Generally, it is hard to achieve multiple performance goals at the same time. For instance, a large young generation may maximize throughput, but has a negative effect on responsiveness, footprint and promptness.<\/p>\n<p>The Java HotSpot VM includes three different types of collectors to attain various performance goals:<\/p>\n<ul>\n<li>A serial collector uses a single thread to perform all collection operations. This collector is efficient in systems with a single processor as no communication overhead between threads occurs.<\/li>\n<li>A parallel collector performs minor collections in parallel. This can considerably reduce garbage collection overhead.<\/li>\n<li>A mostly concurrent collector performs most of its work concurrently to minimize collection pauses and increase the responsive level.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"3_What_are_annotations_and_how_to_define_and_use_them\"><\/span>3. What are annotations and how to define and use them?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Annotations are a form of metadata that describes the annotated code. Annotations themselves are not part of a program and declared to provide information for tools or other programs to work on. Here are several applications of annotations:<\/p>\n<ul>\n<li>To be used by the compiler to detect errors or suppress warnings at compile time.<\/li>\n<li>To be used by a container to set up the operational environment at deployment time.<\/li>\n<li>To instruct the JVM to implement additional jobs at runtime.<\/li>\n<\/ul>\n<p>An annotation is specified using the at sign character <i>(@)<\/i>, which signifies that what follows in an annotation, such as <i>@MyAnnotation<\/i>. The following sections describe annotations in detail.<\/p>\n<ol>\n<li><b> Declaring annotation types<\/b><\/li>\n<\/ol>\n<p>The definition of an annotation type is similar to that of an interface where the <i>interface<\/i> keyword\u00a0is preceded by the <i>@<\/i> character. An annotation definition may contain elements, whose declaration is akin to abstract methods and may consist of default values.<\/p>\n<p>Here is an example of annotation type definitions:<\/p>\n<pre>@interface MyAnnotation {\r\n\u00a0\u00a0\u00a0 String url() default \"whizlabs.com\";\r\n\u00a0\u00a0\u00a0 String[] exams();\r\n\u00a0\u00a0\u00a0 int year();\r\n}\r\n<\/pre>\n<p>The above annotation type defines three elements: <i>url<\/i>, <i>exams<\/i> and <i>year<\/i>. The values of these elements are of types <i>String<\/i>, <i>String[]<\/i> and <i>int<\/i>, respectively. If the value of <i>url<\/i> is not specified, it defaults to <i>&#8220;whizlabs.com&#8221;<\/i>.<\/p>\n<p>The Java SE API declares several built-in useful annotations. One of the most commonly used is <i>@Override<\/i>. This annotation is useful during development as it helps to make sure that the annotated method actually overrides a superclass method or implements an interface one.<\/p>\n<p>In addition to annotations applied to Java elements of other kinds, e.g. a field, method or type, there are a few annotations that only work on other annotations. These are called meta-annotations, which are important when defining a custom annotation type. Meta-annotations are described below:<\/p>\n<ul>\n<li><i>@Retention\u00a0<\/i>annotation: Specifies how the marked annotation is stored, with the following allowable values:<\/li>\n<li><i>SOURCE<\/i>: The annotated annotation is used only for compile-time reports and ignored by the compiler when compiling the source code. This does not mean that the compiler completely skip the annotation. Instead, it may report errors based on the annotated annotation, but still goes ahead despite such an error.<\/li>\n<li><i>CLASS<\/i>: The annotated annotation is preserved by the compiler at compile time. It is compiled into the class file, but ignored by the Java virtual machine at runtime. This is the default behavior if no value is set.<\/li>\n<li><i>RUNTIME<\/i>: The annotated annotation is recorded in the class file and utilized by the Java virtual machine at runtime.<\/li>\n<li><i>@Target\u00a0<\/i>annotation: Indicates the contexts in which the annotated annotation is applicable. The following are values allowed to be specified in this annotation:<\/li>\n<li><i>ANNOTATION_TYPE<\/i>: The annotated annotation can be applied to an annotation type.<\/li>\n<li><i>CONSTRUCTOR<\/i>: The annotated annotation\u00a0can be applied to a constructor.<\/li>\n<li><i>FIELD<\/i>: The annotated annotation\u00a0can be applied to a field or property.<\/li>\n<li><i>LOCAL_VARIABLE<\/i>:\u00a0The annotated annotation\u00a0can be applied to a local variable.<\/li>\n<li><i>METHOD<\/i>: The annotated annotation\u00a0can be applied to a method.<\/li>\n<li><i>PACKAGE<\/i>:\u00a0The annotated annotation\u00a0can be applied to a package declaration.<\/li>\n<li><i>PARAMETER<\/i>: The annotated annotation\u00a0can be applied to the parameters of a method.<\/li>\n<li><i>TYPE<\/i>: The annotated annotation\u00a0can be applied to a class, interface (including annotation type) or enum.<\/li>\n<\/ul>\n<p>In the absence of the <i>@Target<\/i> meta-annotation, an annotation may be used on any declarations except for the declaration of type parameters.<\/p>\n<ul>\n<li><i>@Documented\u00a0<\/i>annotation: Indicates that an annotation is to be documented by javadoc or similar tools. This annotation is important to clients if the annotated annotation influences the use of the element it is declared on. By default, annotation types are not included in the generated Java API.<\/li>\n<li><i>@Inherited\u00a0<\/i>annotation: Indicates that the annotated annotation can be inherited in a class hierarchy. If a parent class is declared with an <i>@Inherited<\/i> annotation, subclasses of this superclass can use the annotation without re-declaring it. The annotated annotation applies to type declarations only. By default, annotation types are not inheritable.<\/li>\n<li><i>@Repeatable\u00a0<\/i>annotation: Indicates that the annotated annotation can be applied more than once to the same declaration or type use. The value of\u00a0<i>@Repeatable<\/i><i><\/i>indicates the\u00a0containing annotation type\u00a0for the repeatable annotation type.<\/li>\n<\/ul>\n<ol start=\"2\">\n<li><b> Using annotations<\/b><\/li>\n<\/ol>\n<p>Annotations are often applied to declaration of various Java elements, such as:<\/p>\n<pre>@MyAnnotation(exams = { \"OCAJP\", \"OCPJP }, year = 2017)\r\npublic class Whizlabs {\r\n\u00a0\u00a0\u00a0 \/\/ class body\r\n}\r\n<\/pre>\n<p>Or:<\/p>\n<pre>@Override\r\npublic void myMethod() { ... }\r\n<\/pre>\n<p>From Java SE 8, annotations can also be applied to the use of\u00a0type. In other words, annotations can be used anywhere a type is used. Several examples are shown below:<\/p>\n<ul>\n<li>Class instance creation expression: <i>new @Interned MyObject();<\/i><\/li>\n<li>Type cast: <i>myString = (@NonNull String) string;<\/i><\/li>\n<li>Thrown exception declaration: <i>void myMethod() throws @Severe MyException { &#8230; }<\/i><\/li>\n<\/ul>\n<p>Type annotations were created to support stronger type checking. The Java SE platform does not provide a type checking framework, but many third-party ones are available as pluggable modules that can be used with the Java compiler.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_What_is_generics_Describe_and_illustrate_generic_types_and_generic_methods\"><\/span><b>4.\u00a0<\/b>What is generics? Describe and illustrate generic types and generic methods.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li><b>What is generics?<\/b><\/li>\n<\/ol>\n<p>Generally, generics are a facility that allows types to be used as parameters when defining classes, interfaces and methods. Type parameters provide a way to re-use the same declaration with different type inputs. By using generics, you can implement type-safe algorithms that work on collections of different types.<\/p>\n<p>The following are a couple of use cases demonstrating the application of generic code:<\/p>\n<ul>\n<li>Stronger type checks at compile time: The compiler applies strong type checking when compiling generic code, raising an error if there is a violation. This helps to find many bugs at compile time, which otherwise only emerge at runtime. Fixing a bug at runtime is more expensive than doing so at compile time.<\/li>\n<li>Elimination of casting: Prior to the introduction of generics, many operations need to be cast to the target type, such as:<\/li>\n<\/ul>\n<pre>Map map = new HashMap();\r\nmap.put(\"name\", \"Whizlabs\");\r\nString name = (String) map.get(\"name\");\r\n<\/pre>\n<p>In this case, using generics can eliminate casting:<\/p>\n<pre>Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();\r\nmap.put(\"name\", \"Whizlabs\");\r\nString name = map.get(\"name\");<\/pre>\n<ol start=\"2\">\n<li><b> Generic types<\/b><\/li>\n<\/ol>\n<p>A generic type is a class or interface that is parameterized over types. A generic type is declared as follows:<\/p>\n<pre>class name&lt;T1, T2, ..., Tn&gt; { ... }\r\ninterface name&lt;T1, T2, ..., Tn&gt; { ... }\r\n<\/pre>\n<p>Type parameters <i>T1, T2, &#8230;, Tn<\/i> are enclosed within a pair of angle brackets following the name of the type being declared (a class or interface). These type parameters can be used anywhere in the class or interface.<\/p>\n<p>The following is an example of the definition of a generic type:<\/p>\n<pre>public class Whizlabs&lt;T&gt; {\r\n\u00a0\u00a0\u00a0 private T t;\r\n\u00a0\u00a0\u00a0 public T get() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return t;\r\n\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0 public void set(T t) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.t = t;\r\n\u00a0\u00a0\u00a0 }\r\n}\r\n<\/pre>\n<p>The above generic type can be invoked with any type that are not primitive. An invocation of a generic type, which is also called a parameterized type, replaces type parameters with specific type arguments. A parameterized type can then be used in the same way as a non-generic type:<\/p>\n<pre>Whizlabs&lt;String&gt; whizlabs = new Whizlabs&lt;String&gt;();\r\n<\/pre>\n<p>The type arguments used to invoke the constructor of a generic class in the above statement can be replaced by an empty set of type arguments <i>(&lt;&gt;)<\/i>, also known as the diamond, if the compiler can determine the type arguments from the context:<\/p>\n<pre>Whizlabs&lt;String&gt; whizlabs = new Whizlabs&lt;&gt;();\r\n<\/pre>\n<ol start=\"3\">\n<li><b> Generic methods<\/b><\/li>\n<\/ol>\n<p>A generic method\u00a0is a method with its own type parameters. Declaring type parameters for a generic method is similar to doing for a generic type. These type parameters are scoped to the method where it is declared. This is true for constructors as well.<\/p>\n<p>The syntax of a generic method declaration is shown below:<\/p>\n<p>modifiers &lt;T1, T2, &#8230;, Tn&gt; return-type method-name(parameters) { &#8230; }<\/p>\n<p>Type parameters <i>T1, T2, &#8230;, Tn<\/i> are enclosed within a pair of angle brackets preceding the method&#8217;s return type. These parameters must follow all modifiers.<\/p>\n<p>Here is an example:<\/p>\n<pre>public static &lt;T&gt; boolean compareEquality(T t1, T t2) {\r\n\u00a0 \u00a0 return t1.equals(t2);\r\n}\r\n<\/pre>\n<p>The <i>compareEquality<\/i> method can be invoked as follows (assume it is defined in the <i>Whizlabs<\/i> class):<\/p>\n<p><i>boolean check = Whizlabs.&lt;Integer&gt; compareEquality(1, 2);<\/i><\/p>\n<p>If the compiler can infer the type argument from the context, it can be left out as follows:<\/p>\n<p><i>boolean check = Whizlabs.compareEquality(1, 2);<\/i><\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Describe_Java_lambda_expressions_and_give_examples_to_demonstrate_their_usage\"><\/span><b>5.\u00a0<\/b>Describe Java lambda expressions and give examples to demonstrate their usage.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A Java lambda expression is a function that is defined outside of any class. It was introduced to facilitate functional programming in the Java platform. Lambda expressions enable functionality to be treated as method argument, or code as data.<\/p>\n<ol>\n<li><b> Functional interfaces<\/b><\/li>\n<\/ol>\n<p>Functional interfaces are interfaces that define exactly one abstract method. It may contain any number of non-abstract methods. The following is an example of functional interface:<\/p>\n<pre>interface MyInterface {\r\n\u00a0 \u00a0 void myMethod();\r\n}\r\n<\/pre>\n<p>The following declaration is also a functional interface despite two additional methods:<\/p>\n<pre>interface MyInterface {\r\n\u00a0 \u00a0 void myMethod();\r\n\u00a0 \u00a0 default void defaultMethod() { ... }\r\n\u00a0 \u00a0 static void staticMethod() { ... }\r\n}\r\n<\/pre>\n<p>Assume there is a method that has a parameter of type <i>MyInterface<\/i>:<\/p>\n<pre>public void handleMyInterface(MyInterface arg) {\r\n\u00a0 \u00a0 arg.myMethod();\r\n}\r\n<\/pre>\n<p>Prior to Java SE 8, the most concise way to pass around an instance of a functional interface, like any other interface, is to use an anonymous class, like this:<\/p>\n<pre>handleMyInterface(new MyInterface() {\r\n\u00a0 \u00a0 public void myMethod() {\r\n\u00a0 \u00a0 \u00a0 \u00a0 System.out.println(\"Whizlabs\");\r\n\u00a0 \u00a0 }\r\n});\r\n<\/pre>\n<p>With the introduction of functional interfaces in Java SE 8, the above invocation can be even more succinct:<\/p>\n<pre>handleMyInterface(() -&gt; System.out.println(\"Whizlabs\"))<i>;<\/i>\r\n<\/pre>\n<p>The syntax of lambda expressions is given in the following section.<\/p>\n<ol start=\"2\">\n<li><b> Lambda expression syntax<\/b><\/li>\n<\/ol>\n<p>A lambda expression can only be used in places where a functional interface is expected. Its structure must correspond to the signature and return type of the unique abstract method of that functional interface.<\/p>\n<p>A lambda expression consists of three elements:<\/p>\n<ul>\n<li>A comma-separated list of formal parameters enclosed in parentheses<\/li>\n<li>The arrow token <i>(-&gt;)<\/i><\/li>\n<li>A body, which consists of a single expression or a statement block<\/li>\n<\/ul>\n<p>Let&#8217;s see an example now. Given a functional interface:<\/p>\n<pre><i>public interface NumberComparator {<\/i>\r\n<i>\u00a0\u00a0\u00a0 boolean compare(int i, int j);<\/i>\r\n<i>}<\/i><i><\/i>\r\n<\/pre>\n<p>The following lambda expression can be used anywhere an instance of the <i>NumberComparator<\/i> interface is required:<\/p>\n<pre><i>(int i, int j) -&gt; { return i == j; }<\/i>\r\n<\/pre>\n<p>The above lambda expression takes in two arguments of type <i>int<\/i>, and returns a <i>boolean<\/i> value. These types are the same as those of the abstract method of the corresponding interface, <i>NumberComparator<\/i>.<\/p>\n<p>Since the body of the lambda expression is comprised of only one statement, and the parameter types can be inferred from the <i>NumberComparator.compare<\/i> method, the above lambda expression can be reduced to:<\/p>\n<pre><i>(i, j) -&gt; i == j<\/i><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"6_Describe_commonly_used_methods_of_three_interfaces_of_the_Java_Collections_API_List_Set_and_Map\"><\/span><b>6.\u00a0<\/b>Describe commonly used methods of three interfaces of the Java Collections API: <i>List<\/i>, <i>Set<\/i> and <i>Map<\/i>.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Java Collections API provide many classes and interfaces that are useful to process a collection of Java objects. <i>List<\/i>, <i>Set<\/i> and <i>Map<\/i> are among the most commonly used interfaces. <i>List<\/i> and <i>Set<\/i> are subtypes of the <i>Collection<\/i> interface, while <i>Map<\/i> is not.<\/p>\n<ol>\n<li><b> The <i>Collection<\/i> interface<\/b><\/li>\n<\/ol>\n<p>The\u00a0<i>Collection\u00a0<\/i>interface is used to represent a collection of objects. Its methods are inherited by subinterfaces, including <i>List<\/i> and <i>Set<\/i>.<\/p>\n<p>The\u00a0<i>Collection\u00a0<\/i>interface contains methods that perform basic operations, e.g.:<\/p>\n<ul>\n<li><i>size()<\/i>: Returns the number of elements in this collection.<\/li>\n<li><i>isEmpty()<\/i>: Returns whether this collection contains no elements.<\/li>\n<li><i>contains(Object)<\/i>: Returns whether this collection contains the specified element.<\/li>\n<li><i>add(E)<\/i>: Insures that this collection contains the specified element.<\/li>\n<li><i>remove(Object)<\/i>: Removes a single instance of the specified element from this collection if it is present.<\/li>\n<li><i>iterator()<\/i>: Returns an iterator over the elements in this collection.<\/li>\n<\/ul>\n<p>This interface also defines methods that operate on entire collections, such as:<\/p>\n<ul>\n<li><i>containsAll(Collection&lt;?&gt;)<\/i>: Returns\u00a0true\u00a0if this collection contains all of the elements in the specified collection.<\/li>\n<li><i>addAll(Collection&lt;? extends E&gt;)<\/i>: Adds all of the elements in the specified collection to this collection.<\/li>\n<li><i>retainAll(Collection&lt;?&gt;)<\/i>: Retains only the elements in this collection that are contained in the specified collection.<\/li>\n<li><i>removeAll(Collection&lt;?&gt;)<\/i>: Removes all of this collection&#8217;s elements that are also contained in the specified collection.<\/li>\n<li><i>clear()<\/i>: Removes all of the elements from this collection.<\/li>\n<\/ul>\n<p>Moreover, the <i>Collection<\/i> interface comprises methods converting a collection to an array or stream as well:<\/p>\n<ul>\n<li><i>toArray()<\/i>, <i>toArray(T[])<\/i>: Returns an array containing all of the elements in this collection.<\/li>\n<li><i>stream()<\/i>, <i>parallelStream()<\/i>: Returns a sequential\/parallel\u00a0Stream\u00a0with this collection as its source.<\/li>\n<\/ul>\n<ol start=\"2\">\n<li><b> The <i>Set<\/i> interface<\/b><\/li>\n<\/ol>\n<p>A\u00a0<i>Set\u00a0<\/i>is a\u00a0<i>Collection<\/i> that allows no duplicate elements, and no more than one null value. Specifically, a <i>Set<\/i> contain no pair of elements\u00a0<i>e1\u00a0<\/i>and\u00a0<i>e2\u00a0<\/i>such that <i>e1.equals(e2)<\/i>. This\u00a0interface contains only methods that are inherited from\u00a0<i>Collection\u00a0<\/i>and adds constraints that forbid duplication.<\/p>\n<ol start=\"3\">\n<li><b> The <i>List<\/i> interface<\/b><\/li>\n<\/ol>\n<p>A\u00a0<i>List\u00a0<\/i>is an ordered\u00a0<i>Collection<\/i> allowing duplicate elements. This interface has methods for control over where to insert and access elements of the list. It also contains methods for searching for elements of a <i>List<\/i>.<\/p>\n<p><i>List<\/i> is a subinterface of <i>Collection<\/i>, thus inherits all methods defined in the <i>Collection<\/i> interface. In addition, the <i>List<\/i> interface supports other operations:<\/p>\n<ul>\n<li>Positional access: Facilitates CRUD operations based on the element&#8217;s position in the list, for instance:<\/li>\n<li><i>get(int)<\/i>: Returns the element at the specified position in this list.<\/li>\n<li><i>set(int, E)<\/i>: Replaces the element at the specified position in this list with the specified element.<\/li>\n<li><i>add(E)<\/i>: Appends the specified element to the end of this list.<\/li>\n<li><i>add(int, E)<\/i>: Inserts the specified element at the specified position in this list.<\/li>\n<li><i>remove(Object)<\/i>: Removes the first occurrence of the specified element from this list, if it is present<\/li>\n<li>Iteration: Goes through the list, allowing actions to be taken on each element. Iteration can be obtained using overloaded <i>listIterator<\/i> The <i>Iterator<\/i> returned from these methods is a <i>ListIterator<\/i> that takes advantage of the list&#8217;s sequential characteristic.<\/li>\n<li><i>listIterator()<\/i>: Returns a list iterator over the elements in this list, starting from the beginning of the list.<\/li>\n<li><i>listIterator(int\u00a0index)<\/i>: Returns a list iterator over the elements in this list, starting at the specified position in the list.<\/li>\n<li>Search: Looks for a specified object in the list and returns its numerical position. This kind of operation is provided by methods <i>indexOf(Object)<\/i> and <i>lastIndexOf(Object)<\/i>. These methods return the index of the first\/last occurrence of the specified element in this list, or <i>-1<\/i> if this list does not contain the element.<\/li>\n<li>The <i>List<\/i> interface also defines a method for range-view operations: <i>subList(int, int)<\/i>. This method returns a view of the portion of this list between indexes specified by the first argument, inclusive, and\u00a0the second, exclusive.<\/li>\n<\/ul>\n<ol start=\"4\">\n<li><b> The <i>Map<\/i> interface<\/b><\/li>\n<\/ol>\n<p>A\u00a0<i>Map\u00a0<\/i>is an object that maps keys to values. No duplicate keys are allowed in a map. Each key is associated with at most one value. This\u00a0interface defines methods for various operations introduced below.<\/p>\n<p>The <i>Map<\/i> interface consists of methods for basic operations, such as:<\/p>\n<ul>\n<li><i>size()<\/i>: Returns the number of key-value mappings in this map.<\/li>\n<li><i>isEmpty()<\/i>: Returns\u00a0true\u00a0if this map contains no key-value mappings.<\/li>\n<li><i>put(K,\u00a0V)<\/i>: Associates the specified value with the specified key in this map.<\/li>\n<li><i>get(Object)<\/i>: Returns the value to which the specified key is mapped, or\u00a0<i>null\u00a0<\/i>if this map contains no mapping for the key.<\/li>\n<li><i>remove (Object\u00a0key)<\/i>: Removes the mapping for a key from this map if it is present.<\/li>\n<li><i>containsKey(Object\u00a0key)<\/i>: Returns whether this map contains a mapping for the specified key.<\/li>\n<li><i>containsValue(Object\u00a0value)<\/i>: Returns whether this map maps one or more keys to the specified value.<\/li>\n<\/ul>\n<p>This interface is also comprised of methods for bulk operations:<\/p>\n<ul>\n<li><i>putAll(<\/i><i>Map<\/i><i>&lt;? extends\u00a0<\/i><i>K<\/i><i>,? extends\u00a0<\/i><i>V<\/i><i>&gt;)<\/i>: Copies all of the mappings from the specified map to this map.<\/li>\n<li><i>clear()<\/i>: Removes all of the mappings from this map.<\/li>\n<\/ul>\n<p>In addition, the <i>Map<\/i> interface declares methods to get collection views on a map:<\/p>\n<ul>\n<li><i>entrySet()<\/i>: Returns a\u00a0<i>Set\u00a0<\/i>view of the mappings contained in this map.<\/li>\n<li><i>keySet()<\/i>: Returns a\u00a0<i>Set\u00a0<\/i>view of the keys contained in this map.<\/li>\n<li><i>values()<\/i>: Returns a\u00a0<i>Collection\u00a0<\/i>view of the values contained in this map.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"7_What_is_serialization_and_how_to_implement_it_in_the_Java_programming_language\"><\/span><b>7.\u00a0<\/b>What is serialization and how to implement it in the Java programming language?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Serialization in Java means converting an object&#8217;s state to a byte stream such that the byte stream can be reverted into a copy of the original object. A Java object is\u00a0serializable\u00a0if its class or any of its superclasses implements the\u00a0<i>Serializable\u00a0<\/i>interface. Serialization allows objects to be transferred across the network, persisted to a database, saved to a file and so on. Deserialization is the process of transforming the serialized byte stream back to an object.<\/p>\n<ol>\n<li><b> The <i>Serializable<\/i> interface<\/b><\/li>\n<\/ol>\n<p>The <i>Serializable<\/i> interface enables an object to be serialized and implementing this interface is required for a class to be serializable. The <i>Serializable<\/i> interface, defining no fields and methods, only serves as a marker labeling classes as serializable.<\/p>\n<p>If a class is serializable, all of its subclasses are serializable. This serializable class, however, may extend a non-serializable superclass. If this is the case, the non-serializable class must declare a no-argument constructor that is accessible to the serializable subclass. This requirement is important as such a no-constructor is used to initialize fields of the non-serializable superclass during deserialization.<\/p>\n<p>In the process of serialization and deserialization, a serializable class is associated with a version number. This version number is used to verify that the classes at both sides of the process are compatible. Specifically, when an object is recreated from a byte stream, its blueprint class must match the class from which the original object is instantiated. The version number is essential in maintaining integrity when serialization and deserialization occur in different machines.<\/p>\n<p>The version number of a serializable class can be explicitly set by declaring a <i>static<\/i> <i>final<\/i> field in the class itself as follows:<\/p>\n<pre><i>&lt;access-modifier&gt; static final long serialVersionUID = 2017L;<\/i>\r\n<\/pre>\n<p>Any access modifier is allowable, but it is recommended to specify <i>private<\/i> to avoid accidental changes. The type of that field must be <i>long<\/i>.<\/p>\n<p>If the version number field is not declared, the serialization runtime will calculate a default value based on various aspects of the serializable class. This computation is, however, dependent on the class definition in the class file, which may not be the same across compiler implementations. Therefore, to insure the consistency of a version number value, the <i>serialVersionUID<\/i> field should be explicitly defined and set.<\/p>\n<p>Serialization is implemented by the <i>ObjectOutputStream.writeObject(Object)<\/i> method. The following code<br \/>\nfragment serializes a serializable <i>Whizlabs<\/i> instance to a file named <i>&#8220;whizlabs.ser&#8221;<\/i>:<\/p>\n<pre>Whizlabs origObject = \/\/ an instance of Whizalbs\r\nFileOutputStream fos = new FileOutputStream(new File(\"whizlabs.ser\"));\r\nObjectOutputStream oos = new ObjectOutputStream(fos);\r\noos.writeObject(origObject);\r\nDeserialization is done via the <i>ObjectInputStream.readObject()<\/i> method. The code snippet given below recreates an instance of <i>Whizlabs<\/i> from the <i>\"whizlabs.ser\"<\/i> file:\r\nFileInputStream fis = new FileInputStream(\"whizlabs.ser\");\r\nObjectInputStream ois = new ObjectInputStream(fis);\r\nWhizlabs newObject = (Whizlabs) ois.readObject();\r\n<\/pre>\n<ol start=\"2\">\n<li><b> Customizing serialization<\/b><\/li>\n<\/ol>\n<p>If special handling is required during serialization and deserialization, methods with the exact signatures shown below should be declared within the serializable class:<\/p>\n<pre>private void writeObject(java.io.ObjectOutputStream out) throws IOException\r\nprivate void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException\r\n<\/pre>\n<p>For instance, objects of the following class print out messages when they are serialized and recreated from a byte stream:<\/p>\n<p>class Whizlabs implements Serializable {<\/p>\n<p>\/\/ declarations of fields and methods<\/p>\n<p>private void writeObject(ObjectOutputStream oos) throws IOException {<\/p>\n<p>System.out.println(&#8220;Serializing &#8230;&#8221;);<\/p>\n<p>oos.defaultWriteObject();<\/p>\n<p>}<\/p>\n<p>private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {<\/p>\n<p>System.out.println(&#8220;Deserializing &#8230;&#8221;);<\/p>\n<p>ois.defaultReadObject();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<ol start=\"3\">\n<li><b> The Externalizable interface<\/b><\/li>\n<\/ol>\n<p>The <i>Externalizable<\/i><b> <\/b>interface is a subtype of <i>Serializable<\/i>. It defines two methods, namely <i>writeExternal(ObjectOutput)<\/i> and <i>readExternal(ObjectInput)<\/i>. These methods give the serializable class complete control over the serialization and deserialization of an object and its supertypes. Methods of the <i>Externalizable<\/i> interface override the implementation customization via the <i>writeObject<\/i> and <i>readObject<\/i> methods described in the preceding section.<\/p>\n<p>The following class declaration illustrates the use of the <i>Externalizable<\/i><b> <\/b>interface:<\/p>\n<pre>class Whizlabs implements Externalizable {\r\n<i>\u00a0\u00a0<\/i>\u00a0 \/\/ declarations of fields and methods\r\n@Override\r\npublic void writeExternal(ObjectOutput out) throws IOException {\r\n    System.out.println(\"Serializing ...\");\r\n}\r\n\r\n@Override\r\npublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {\r\n     System.out.println(\"Deserializing ...\");\r\n}\r\n}\r\n<\/pre>\n<p>When an object of the above class is serialized and deserialized, messages on the progress are printed out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article talks about top 7 of the most frequently asked questions in the job interview for the Java developers. If we go through these questions and its respective answers, it would serve as a good preparation for facing the actual interview questions. OCAJP 8 Certification Exam OCAJP 7 Certification Exam 1. Describe 4 fundamental principles of object-oriented programming, and give code examples to demonstrate those principles in Java. Object-oriented programming is a program paradigm based on the concept of objects. An object may contain data, in the form of fields, and behavior, in the form of methods. Object-oriented programming [&hellip;]<\/p>\n","protected":false},"author":220,"featured_media":96498,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[13],"tags":[967],"class_list":["post-28594","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-3"],"uagb_featured_image_src":{"full":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",725,282,false],"thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions-150x150.jpg",150,150,true],"medium":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions-300x117.jpg",300,117,true],"medium_large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",725,282,false],"large":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",725,282,false],"1536x1536":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",725,282,false],"2048x2048":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",725,282,false],"profile_24":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",24,9,false],"profile_48":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",48,19,false],"profile_96":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",96,37,false],"profile_150":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",150,58,false],"profile_300":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions.jpg",300,117,false],"tptn_thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions-250x250.jpg",250,250,true],"web-stories-poster-portrait":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions-640x282.jpg",640,282,true],"web-stories-publisher-logo":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.whizlabs.com\/blog\/wp-content\/uploads\/2017\/06\/java-top-7-interview-questions-150x58.jpg",150,58,true]},"uagb_author_info":{"display_name":"Aditi Malhotra","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/aditi\/"},"uagb_comment_info":0,"uagb_excerpt":"This article talks about top 7 of the most frequently asked questions in the job interview for the Java developers. If we go through these questions and its respective answers, it would serve as a good preparation for facing the actual interview questions. OCAJP 8 Certification Exam OCAJP 7 Certification Exam 1. Describe 4 fundamental&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/28594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/220"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=28594"}],"version-history":[{"count":3,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/28594\/revisions"}],"predecessor-version":[{"id":96500,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/28594\/revisions\/96500"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media\/96498"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=28594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=28594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=28594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}