{"id":65836,"date":"2021-07-16T04:10:03","date_gmt":"2021-07-16T08:10:03","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/scjp-flow-controls-and-exception-java-short-notes-scjp\/"},"modified":"2022-05-10T20:04:09","modified_gmt":"2022-05-11T00:04:09","slug":"scjp-flow-controls-and-exception-java-short-notes-scjp","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=65836","title":{"rendered":"SCJP: Flow controls and exception #Java Short Notes #SCJP"},"content":{"rendered":"<p><b>Flow Control and Exceptions<\/b><b>Flow control statements<\/b><\/p>\n<ul>\n<li> Conditional:  if, if-else and switch-case   <\/li>\n<li> Looping: for, while, do-while   <\/li>\n<li>  Exception handling: try-catch-finally, throw   <\/li>\n<li>  Ad hoc flow control: break, continue with or without labels<\/li>\n<\/ul>\n<pre><p><b>switch statement<\/b><\/p>         switch(expression){ <br \/>        case ConstantExpression: statement(s); <br \/>        case ConstantExpression: statement(s);<br \/>        .<br \/>        .<br \/>        .<br \/>        default: statement(s);<br \/>      }<br \/><br \/><\/pre>\n<ul>\n<li> expression: must be char, byte, short, or int, or a compile-time error occurs    <\/li>\n<li> long primitive can be used if type casted to int     <\/li>\n<li> Object reference cannot be used as expression     <\/li>\n<li> Every case expression must be unique    <\/li>\n<li> break statement may be used at the end of a case statement, to discontinue execution.     <\/li>\n<li> There can be at most only one default statement.      <\/li>\n<li> The order of case statements and default can be anything.<\/li>\n<\/ul>\n<p><b>break and continue<\/b><\/p>\n<ul>\n<li> A break statement transfers the control out of an enclosing statement. break used within a loop breaks the execution of the current loop. In case of nested loops, the break statement passes the control to the immediate outer loop.    <\/li>\n<li> A continue statement breaks the current iteration and moves to next iteration.    <\/li>\n<li> break and continue with labels.\n<ul>\n<li> Labels specify the target (statement) for continue and break          <\/li>\n<li> continue with label does not jump to the labeled statement but instead jumps to the end of the labeled loop.          <\/li>\n<li>  Same label identifiers can be reused multiple times as long as they are not nested.          <\/li>\n<li>  Label names do not conflict with the same named identifier(variable, method or class name).       <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><b>Checked and Unchecked Exceptions<\/b><\/p>\n<p>    <b>Checked Exceptions<\/b><\/p>\n<ul>\n<li> Checked Exceptions are checked by the compiler to see if these exceptions are properly caught or specified. If not, the code will fail to compile          <\/li>\n<li> Checked exception forces client program to deal with the scenario in which an exception may be thrown          <\/li>\n<li> Checked exceptions must be either declared or caught at compile time<\/li>\n<\/ul>\n<p>    <b>Unchecked Exceptions<\/b><\/p>\n<ul>\n<li> Unchecked exceptions are RuntimeException and all of its subclasses.          <\/li>\n<li> Class java.lang.Error and its subclasses also are unchecked.          <\/li>\n<li> Unchecked Exceptions are not checked by the compiler.           <\/li>\n<li> Runtime exceptions do not need to be caught or declared.<\/li>\n<\/ul>\n<p> From: http:\/\/sitestree.com\/?p=4864<br \/> Categories:Java Short Notes, SCJP<br \/>Tags:<br \/> Post Data:2008-08-25 00:56:33<\/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>Flow Control and ExceptionsFlow control statements Conditional: if, if-else and switch-case Looping: for, while, do-while Exception handling: try-catch-finally, throw Ad hoc flow control: break, continue with or without labels switch statement switch(expression){ case ConstantExpression: statement(s); case ConstantExpression: statement(s); . . . default: statement(s); } expression: must be char, byte, short, or int, or a compile-time &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=65836\">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_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917,1954],"tags":[],"class_list":["post-65836","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":65822,"url":"http:\/\/bangla.sitestree.com\/?p=65822","url_meta":{"origin":65836,"position":0},"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":[]},{"id":65862,"url":"http:\/\/bangla.sitestree.com\/?p=65862","url_meta":{"origin":65836,"position":1},"title":"SCJP Training: Lesson 2:  Flow Control #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"The if-then and if-then-else StatementsThe switch statementThe for StatementThe while and do-while StatementsBranching StatementsQuestions and Exercises:Classes (assertion example)Catching and Handling ExceptionsThe try BlockThe catch BlocksThe finally BlockPutting It All TogetherThe Catch or Specify RequirementSpecifying the Exceptions Thrown by a MethodPutting It All Together (ArrayIndexOutOfBoundsException)How to Throw Exceptions (NullPointerException)Command-Line Arguments (NumberFormatException)Object\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":65852,"url":"http:\/\/bangla.sitestree.com\/?p=65852","url_meta":{"origin":65836,"position":2},"title":"SCJP: Short Notes #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"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 interfacesInterfaces can have variables, overrides and overloads An enum can have methods and can\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":22132,"url":"http:\/\/bangla.sitestree.com\/?p=22132","url_meta":{"origin":65836,"position":3},"title":"SCJP: Sun Certified Java Programmer: All that you need to know #SCJP","author":"Sayed","date":"March 10, 2021","format":false,"excerpt":"Introduction to Sun Certified Java Programmer Certification CourseJava : SCJP: Important ResourcesJAVA: Some links: useful for exams like scjp\/scjaSCJP Essential KnowledgeSCJP Practice ExamsSCJP 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\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":74773,"url":"http:\/\/bangla.sitestree.com\/?p=74773","url_meta":{"origin":65836,"position":4},"title":"Are you interested in becoming a Java Developer and OCJP","author":"Sayed","date":"May 31, 2022","format":false,"excerpt":"Are you interested in becoming a Java Developer and OCJP? OCJP: Oracle Certified Java Programmer? Are you interested in a Java based career track? Short Notes on: OCJP: Oracle Certified Java Programmer Certification. Written long back in the SCJP time. These are for quick review purposes, not really to learn\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65820,"url":"http:\/\/bangla.sitestree.com\/?p=65820","url_meta":{"origin":65836,"position":5},"title":"SCJP: Java Operators #Java Short Notes #SCJP","author":"Sayed","date":"July 15, 2021","format":false,"excerpt":"Exams like SCJP test your understanding of Java operators and how to use them like: assignment operators: =, +=, -=arithmetic operators: +, -, *, \/, %, ++, --relational operators: < , , >=, ==, !=logical operators: &, |, ^, !, &&, ||conditional operators: ? : Also operators to check the\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\/65836","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=65836"}],"version-history":[{"count":2,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65836\/revisions"}],"predecessor-version":[{"id":74746,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/65836\/revisions\/74746"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65836"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}