{"id":65852,"date":"2021-07-16T04:10:06","date_gmt":"2021-07-16T08:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/scjp-short-notes-java-short-notes-scjp\/"},"modified":"2022-05-28T19:53:50","modified_gmt":"2022-05-28T23:53:50","slug":"scjp-short-notes-java-short-notes-scjp","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=65852","title":{"rendered":"SCJP: Short Notes #Java Short Notes #SCJP"},"content":{"rendered":"<ul>\n<li> For the package\n<pre>package com.sun2;public enum Seasons {SUMMER, FALL, WINTER, SPRING}      <\/pre>\n<p>Valid import statements are:<\/p>\n<pre>import com.sun2.Seasons; \/\/ the class import static com.sun2.Seasons.*; \/\/all enum valuesimport static com.sun2.Seasons.FALL; \/\/only one enum value<\/pre>\n<\/li>\n<li> An interface can extend many interfaces<\/li>\n<li>Interfaces can have variables, overrides and overloads<\/li>\n<li> An enum can have methods and can override those methods for a specific enum constant<\/li>\n<li> var-args can be used to pass arrays, var args can be of 0 or more lengths<\/li>\n<li> A var-args argument must be a method&#8217;s last argument<\/li>\n<li> An override cannot change the return type. Override can use covariant as a return type<\/li>\n<li> Overloading does not depend on the return type<\/li>\n<li> From J2se 5.0, a method in a subclass may return an object whose type is a subclass of the type returned by the method with the same signature in the superclass<\/li>\n<li>  <a href='http:\/\/java.sun.com\/docs\/books\/tutorial\/java\/IandI\/super.html' target='new' rel=\"noopener\">When a subclass constructor does not explicitly invoke a superclass constructor, the no-argument constructor of the superclass is automatically called from the subclass constructor. If the super class does not have a no-argument constructor, a compile-time error is displayed<\/a><\/li>\n<li> When subclasses override superclass methods, these superclass methods can be accesses using the super keyword (from subclass methods)<\/li>\n<li> From java 1.5, enums can be used in a switch<\/li>\n<li> To enable asserts in java program use -ea switch.<\/li>\n<li> <a href='http:\/\/java.sun.com\/j2se\/1.4.2\/docs\/guide\/lang\/assert.html' target='' rel=\"noopener\">assert has two forms: assert Expression1 ;,  assert Expression1 : Expression2 ;. In the first form only AssertionErorr is displayed, in the second form you can add additional message(Expression2) to the AssertionError. Assert when finds its arguments to be false, it throws AssertionError<\/a><\/li>\n<li> Good places to use assertions: Internal Invariants,     Control-Flow Invariants,  Preconditions, Postconditions, and Class Invariants <\/li>\n<li>bad use of assertions: argument checking in public methods, to do any work that your application requires for correct operation<\/li>\n<li> Assertions should be free of side effects: evaluating the expression should not affect any state that is visible after the evaluation is complete<\/li>\n<li> An overriding method does not need to throw the overridden method&#8217;s exception<\/li>\n<li> Nesting try\/catches are ok and normal flow rules apply in case of nesting.<\/li>\n<li> Accessing uninitialized instance\/class wrapper variables (Integer, Short) will cause NullPointerException<\/li>\n<li> NumberFormatException extends IllegalArgumentException<\/li>\n<li> JVM when calling a method, to make data types compatible, will widen the parameters before boxing. <\/li>\n<li> java.io.Console class: Only a single instance exists for a given JVM, All of the methods that read user input are synchronized<\/li>\n<li> Among File, FileReader, BufferedReader only BufferedReader has a readLine method<\/li>\n<li> A class&#8217;s superclasses don&#8217;t have to implement Serializable in order to be serialized<\/li>\n<li> if a superclass doesn&#8217;t implement Serializable then it&#8217;s constructor will run during deserialization. <\/li>\n<li> A transient variable&#8217;s state is lost during serialization<\/li>\n<li> A volatile variable&#8217;s state is not lost during serialization<\/li>\n<li> If Dog has-a Collar, then Collar must implement java.io.Serializable in order to serialize an instance of Dog.<\/li>\n<li> If Dog extends Animal and Animal implements java.io.Serializable but Dog does NOT implement java.io.Serializable, you can serialize an instance of Dog.<\/li>\n<li> Serialization rules: # Rule #1: The object to be persisted must implement the Serializable interface or inherit that implementation from its object hierarchy,# Rule #2: The object to be persisted must mark all nonserializable fields transient<\/li>\n<li> To make thread instance unserializable: transient private Thread animator;<\/li>\n<li> java.lang.Object does not implement Serializable. AWT and Swing GUI components, strings, and arrays &#8212; are serializable<\/li>\n<li> <a href='http:\/\/java.sun.com\/developer\/technicalArticles\/Programming\/serialization\/' target='new' rel=\"noopener\">Serialization Details<\/a><\/li>\n<li> NumberFormat, Calendar, and DateFormat are abstract. Use the getInstance method to get instances.<\/li>\n<li> For java.util.Scanner, the default separator is a blank NOT a comma<\/li>\n<li> Multiple threads can be created using the same Runnable object, but a given thread can be started only once<\/li>\n<li><a href='http:\/\/www.ime.uerj.br\/javatutor\/essential\/concurrency\/syncmeth.html' target='new' rel=\"noopener\">Two invocations of synchronized methods on the same object to interleave &#8211; is not possible. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object. When a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads. <\/a><\/li>\n<li> In object oriented design, low coupling is more desirable than high coupling. High cohesion is more desirable than low cohesion. Coupling: class interdependence. Cohesion: Class activities should be well focused.<\/li>\n<li> Polymorphism does NOT apply to static methods<\/li>\n<li> Polymorphic calls and co-variant returns can be mixed <\/li>\n<li> no modifier (package private) is weaker than protected. The order is: public, protected, package private, private<\/li>\n<li> Kind of&#8217; translates to extends, &#8216;contract&#8217; translates to implements, and &#8216;composed&#8217; translates to a has-a implementation.<\/li>\n<li> <a href='http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/api\/java\/util\/TreeMap.html' target='new' rel=\"noopener\">TreeMap: headMap() method returns keys that are less than the argument, and tailMap() returns keys that are greater than(&gt;=) the argument.<\/a>   <\/li>\n<\/ul>\n<p> From: http:\/\/sitestree.com\/?p=4888<br \/> Categories:Java Short Notes, SCJP<br \/>Tags:<br \/> Post Data:2011-10-20 04:13:02<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the package package com.sun2;public enum Seasons {SUMMER, FALL, WINTER, SPRING} Valid import statements are: import com.sun2.Seasons; \/\/ the class import static com.sun2.Seasons.*; \/\/all enum valuesimport static com.sun2.Seasons.FALL; \/\/only one enum value An interface can extend many interfaces Interfaces can have variables, overrides and overloads An enum can have methods and can override those methods &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=65852\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1917,1954],"tags":[],"class_list":["post-65852","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","category-scjp-ocjp","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":65860,"url":"http:\/\/bangla.sitestree.com\/?p=65860","url_meta":{"origin":65852,"position":0},"title":"SCJP Training: Lesson 1: Develop code that declares classes (including abstract and all forms of nested classes), interfaces, and enums, and includes the appropriate use of package and import statements (including static imports). #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"Declaring ClassesAbstract Methods and ClassesNested ClassesInterfacesEnum TypesCreating and Using Packages Using Package Members (import statements, static imports)Defining an InterfaceImplementing an InterfaceAbstract Methods and ClassesPrimitive Data TypesArraysEnum TypesUnderstanding Instance and Class MembersVariables Declaring Member VariablesUnderstanding Instance and Class MembersPassing Information to a Method or ConstructorOverriding and Hiding MethodsDefining Methods (overloading)Returning a\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65844,"url":"http:\/\/bangla.sitestree.com\/?p=65844","url_meta":{"origin":65852,"position":1},"title":"Java : SCJP: Important Resources #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"How to use generics to avoid runtime errors. More Generics Class casting in Java: How to avoid runtime exception - ClassCastException: overloading, overriding, variable and method hiding Java HotSpot virtual machine What Java Technology can do? Offers from Java Technology Java:Common Problems (and Their Solutions) Benefits of OOP: Modularity, Information-hiding,\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65842,"url":"http:\/\/bangla.sitestree.com\/?p=65842","url_meta":{"origin":65852,"position":2},"title":"SCJP: Random Stuffs #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"An enum may NOT be declared in a method An enum can be imported If the JVM has a choice, it will select a method without varargs before selecting a method with varargs When enums are equal, both .equals and == always return true The headMap() method returns the portion\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65816,"url":"http:\/\/bangla.sitestree.com\/?p=65816","url_meta":{"origin":65852,"position":3},"title":"JAVA: Some links: useful for exams like scjp\/scja #Java Short Notes #SCJP #Blog","author":"Sayed","date":"July 15, 2021","format":false,"excerpt":"Assertions in Java: http:\/\/java.sun.com\/j2se\/1.4.2\/docs\/guide\/lang\/assert.html Enum in Java:http:\/\/www.java2s.com\/Code\/Java\/Language-Basics\/Enum.htmStringBuffer and StringBuilder Classes have similar methods where StringBuffer is synchronized: http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/api\/java\/lang\/StringBuilder.htmlSerialize and Deserialize: http:\/\/java.sun.com\/j2se\/1.4.2\/docs\/api\/java\/io\/Serializable.htmljava.util package is very important: http:\/\/java.sun.com\/j2se\/1.4.2\/docs\/api\/java\/util\/package-summary.html From: http:\/\/sitestree.com\/?p=4845 Categories:Java Short Notes, SCJP, BlogTags: Post Data:2013-06-11 18:38:25 Shop Online: https:\/\/www.ShopForSoul.com\/ (Big Data, Cloud, Security, Machine Learning): Courses: http:\/\/Training.SitesTree.com In Bengali: http:\/\/Bangla.SaLearningSchool.com\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65838,"url":"http:\/\/bangla.sitestree.com\/?p=65838","url_meta":{"origin":65852,"position":4},"title":"SCJP: Class Declarations #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"class declarations Start with modifiers such as public, private followed by class keyword The class name, with the initial letter capitalized The name of the class's parent (superclass), preceded by the keyword extends (if any). A class can only extend (subclass) one parent. list of interfaces implemented by the class,\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65822,"url":"http:\/\/bangla.sitestree.com\/?p=65822","url_meta":{"origin":65852,"position":5},"title":"SCJP: Language Fundamentals #Java Short Notes #SCJP","author":"Sayed","date":"July 15, 2021","format":false,"excerpt":"Class declaration and java source file. Only \"one\" top-level public class is allowed per java source file. The name of the java source file and the name of the top-level public class MUST be the same. If no public class is there in a file, after compiling separate class files\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65852"}],"version-history":[{"count":2,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65852\/revisions"}],"predecessor-version":[{"id":74737,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65852\/revisions\/74737"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65852"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}