{"id":163,"date":"2016-02-01T17:12:25","date_gmt":"2016-02-01T17:12:25","guid":{"rendered":"http:\/\/kaizen-koka.com\/?p=163"},"modified":"2016-02-02T17:15:24","modified_gmt":"2016-02-02T17:15:24","slug":"java-interview-questions","status":"publish","type":"post","link":"https:\/\/kaizen-koka.com\/?p=163","title":{"rendered":"Java Interview Questions"},"content":{"rendered":"<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif;\"><span style=\"font-size:14px;\"><strong>Different ways to create an Object in java?<\/strong><br \/>\n\t&nbsp; 1) using new&nbsp;<br \/>\n\t&nbsp; &nbsp; &nbsp; Netflix netflix = new Netflix();<br \/>\n\t&nbsp; 2) using class.forName()<br \/>\n\t&nbsp; &nbsp; &nbsp; Netflix netflix =Class.forName(&quot;com.bellinfo.Netflix&quot;).newInstance();<br \/>\n\t&nbsp; 3) by clone()<br \/>\n\t&nbsp; &nbsp; &nbsp; Netflix netflix1 = new Netflix();<br \/>\n\t&nbsp; &nbsp; &nbsp; Netflix netflix2 = (Netflix) netflix1.clone();<br \/>\n\t&nbsp; 4) by desearlization (the object which is already Seralized)<br \/>\n\t&nbsp; &nbsp; &nbsp; ObjectInputStream ooi = new ObjectInputStream(anInputStream);<br \/>\n\t&nbsp; &nbsp; &nbsp; Netflix netflix = (Netflix) ooi.readObject();<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif;\"><span style=\"font-size:14px;\"><strong>Can we create an instance for a private constructor class out-side of the same class?<\/strong>&nbsp;<br \/>\n\t&nbsp; Yes,&nbsp;<br \/>\n\t&nbsp;<\/span><\/span>\n<\/p>\n<pre class=\"brush:java;\">\r\n class Netflix {\r\n&nbsp; &nbsp; &nbsp;private Netflix(){}\r\n&nbsp; }\r\n&nbsp; public static void main(String args[]){\r\n&nbsp; &nbsp; &nbsp; &nbsp;try {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Class c = Class.forName(&quot;com.bellinfo.corejava.Netflix&quot;);\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Constructor con[] = c.getDeclaredConstructors();\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con[0].setAccessible(true);\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con[0].newInstance();\r\n&nbsp; &nbsp; &nbsp; &nbsp;} catch (ClassNotFoundException e) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();\r\n&nbsp; &nbsp; &nbsp; &nbsp;} catch (InvocationTargetException e) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();\r\n&nbsp; &nbsp; &nbsp; &nbsp;} catch (InstantiationException e) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();\r\n&nbsp; &nbsp; &nbsp; &nbsp;} catch (IllegalAccessException e) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();\r\n&nbsp; &nbsp; &nbsp; &nbsp;}\r\n&nbsp; }<\/pre>\n<p>\n\t<strong><span style=\"font-family:verdana,geneva,sans-serif;\"><span style=\"font-size:14px;\">Difference between instance vs object ?<\/span><\/span><\/strong>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><strong><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&nbsp;&nbsp;<\/span><\/strong><span style=\"font-family:verdana,geneva,sans-serif;\">A blueprint for a house design is like a class description. All the houses built from that blueprint are objects of that class. A given house is an instance. <\/span>&nbsp;An &#39;instance&#39; is a variable in memory that&nbsp;<em>only<\/em>&nbsp;has a memory address of an object in it.&nbsp; &nbsp;<\/span>\n<\/p>\n<p>\n\t<strong><span style=\"font-family:verdana,geneva,sans-serif;\"><span style=\"font-size:14px;\">Difference between association vs aggregation vs composition ?<\/span><\/span><\/strong>\n<\/p>\n<p>\n\t<strong><span style=\"font-family:verdana,geneva,sans-serif;\"><span style=\"font-size:14px;\">is a vs has a relationship in java ?<\/span><\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Different ways to create an Object in java? &nbsp; 1) using new&nbsp; &nbsp; &nbsp; &nbsp; Netflix netflix = new Netflix(); &nbsp; 2) using class.forName() &nbsp; &nbsp; &nbsp; Netflix netflix =Class.forName(&quot;com.bellinfo.Netflix&quot;).newInstance(); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[11,2],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-interview-questions","category-technology"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p70lnf-2D","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163"}],"version-history":[{"count":2,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":172,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions\/172"}],"wp:attachment":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}