{"id":65963,"date":"2021-07-18T10:54:06","date_gmt":"2021-07-18T14:54:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/generics-in-java-java-short-notes\/"},"modified":"2021-07-18T10:54:06","modified_gmt":"2021-07-18T14:54:06","slug":"generics-in-java-java-short-notes","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=65963","title":{"rendered":"Generics in Java #Java Short Notes"},"content":{"rendered":"<ul>\n<li> Generics can prevent many run time errors.    <\/li>\n<li> A generic class:\n<pre>public class Box {    private T t; \/\/ T stands for \"Type\"              public void add(T t) {        this.t = t;    }    public T get() {        return t;    }}Object creation:<br \/>Box integerBox = new Box();<\/pre>\n<\/li>\n<li> Generic method syntax: public <u> void inspect(U u){}\n<li>Type Erasure:Check this code:\n<pre>public class MyClass {    public static void myMethod(Object item) {        if (item instanceof E) {  \/\/Compiler error            ...        }        E item2 = new E();   \/\/Compiler error        E[] iArray = new E[10]; \/\/Compiler error        E obj = (E)new Object(); \/\/Unchecked cast warning    }}<\/pre>\n<\/li>\n<p><\/u><\/li>\n<\/ul>\n<p> From: http:\/\/sitestree.com\/?p=4902<br \/> Categories:Java Short Notes<br \/>Tags:<br \/> Post Data:2007-10-28 07:08:01<\/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>Generics can prevent many run time errors. A generic class: public class Box { private T t; \/\/ T stands for &#8220;Type&#8221; public void add(T t) { this.t = t; } public T get() { return t; }}Object creation:Box integerBox = new Box(); Generic method syntax: public void inspect(U u){} Type Erasure:Check this code: public &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=65963\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-65963","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":65870,"url":"http:\/\/bangla.sitestree.com\/?p=65870","url_meta":{"origin":65963,"position":0},"title":"SCJP Training: Lesson 6: Collections \/ Generics #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"Object OrderingObject as a SuperclassGeneric TypesDeclaring ClassesDefining an InterfacePassing Information to a Method or ConstructorReturning a Value from a MethodGeneric TypesGeneric Methods and ConstructorsWildcardsAlgorithms From: http:\/\/sitestree.com\/?p=5053 Categories:Java Short Notes, SCJPTags: Post Data:2012-07-21 07:53:36 Shop Online: https:\/\/www.ShopForSoul.com\/ (Big Data, Cloud, Security, Machine Learning): Courses: http:\/\/Training.SitesTree.com In Bengali: http:\/\/Bangla.SaLearningSchool.com http:\/\/SitesTree.com 8112223 Canada\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":26966,"url":"http:\/\/bangla.sitestree.com\/?p=26966","url_meta":{"origin":65963,"position":1},"title":"ModificationTest.java Demonstrates changing fields of an object. Inherits from  ReferenceTest.java. #Programming Code Examples #Java\/J2EE\/J2ME #Basic Java","author":"Author-Check- Article-or-Video","date":"May 6, 2021","format":false,"excerpt":"\/** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * \u00a9 2001 Marty Hall and Larry Brown; * may be freely used or adapted. *\/ import java.awt.Point; public class ModificationTest extends ReferenceTest { public static void main(String[] args) { Point p1 = new\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":10510,"url":"http:\/\/bangla.sitestree.com\/?p=10510","url_meta":{"origin":65963,"position":2},"title":"ModificationTest.java Demonstrates changing fields of an object. Inherits from ReferenceTest.java.","author":"","date":"August 29, 2015","format":false,"excerpt":"\/** Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown; \u00a0*\u00a0 may be freely used or adapted. \u00a0*\/ import java.awt.Point; public class ModificationTest extends ReferenceTest { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 Point p1\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10254,"url":"http:\/\/bangla.sitestree.com\/?p=10254","url_meta":{"origin":65963,"position":3},"title":"Counter2Test.java Driver class that creates three threaded objects (Counter2) that count from 0 to 4.","author":"","date":"August 25, 2015","format":false,"excerpt":"\/** Try out a few instances of the Counter2 class. Driver class that creates three threaded objects (Counter2) that count from 0 to 4. In this case, the driver does not start the threads, as each thread is automatically started in Counter2's constructor. Uses the following class: Counter2Test.java Counter2.java **************************\u00a0\u00a0\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65844,"url":"http:\/\/bangla.sitestree.com\/?p=65844","url_meta":{"origin":65963,"position":4},"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":26579,"url":"http:\/\/bangla.sitestree.com\/?p=26579","url_meta":{"origin":65963,"position":5},"title":"Example demonstrating the use of packages #Programming Code Examples #Java\/J2EE\/J2ME #Object Oriented Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"&&&&&&&&&&&&&&&&&&& Example demonstrating the use of packages. * Class1.java defined in package1. * Class2.java defined in package2. * Class3.java defined in package2.package3. * Class1.java defined in package4. * PackageExample.java Driver for package example &&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~ Class1.java defined in package1. ~~~~~~~~~~~~~~~~~~~~~ package package1; ***************** public class Class1 { public static void\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\/65963","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\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65963"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65963\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65963"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}