{"id":19536314,"url":"https://github.com/denezt/java-coding-examples","last_synced_at":"2025-02-26T04:19:39.626Z","repository":{"id":94028119,"uuid":"52238132","full_name":"denezt/java-coding-examples","owner":"denezt","description":"Java Programming and Design Examples","archived":false,"fork":false,"pushed_at":"2023-12-30T08:16:36.000Z","size":52,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T17:58:04.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denezt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-02-22T01:24:15.000Z","updated_at":"2024-12-28T07:19:48.000Z","dependencies_parsed_at":"2023-04-15T01:31:11.481Z","dependency_job_id":null,"html_url":"https://github.com/denezt/java-coding-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denezt%2Fjava-coding-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denezt%2Fjava-coding-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denezt%2Fjava-coding-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denezt%2Fjava-coding-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denezt","download_url":"https://codeload.github.com/denezt/java-coding-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240789656,"owners_count":19857879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T02:22:13.360Z","updated_at":"2025-02-26T04:19:39.313Z","avatar_url":"https://github.com/denezt.png","language":"Java","readme":"# Java-Sessions\nJava Programming and Computational Design\ndate: 2013-06-01 00:34:15\nname: Computer Science 046 | factsheets\n---\n\u003c!-- I don't see a discussion page for the fact sheet so I hope this is okay. --\u003e\n\u003c!-- What does the \"Note\" column add? The bad examples already say \"error\" on the left; \"NOT recommended\" seems redundant. --\u003e\n\n\u003c!--  --\u003e\n\n# Factsheets\n\n**Variables**\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eVariable_Declaration\u003c/TH\u003e\n\u003cTH\u003eComment\u003c/TH\u003e\n\u003cTH\u003eNote\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003eint age = 21;\u003c/TD\u003e\n\n\u003cTD\u003eThis declares an integer variable and initializes it to 21.\u003c/TD\u003e\n\u003cTD\u003eRecommended\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eint nextAge = age + 1;\u003c/TD\u003e\n\u003cTD\u003eThe initial value of a variable can be an expression (as long as age has been previously declared.)\u003c/TD\u003e\n\u003cTD\u003eRecommended\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eString course= \"Udacity\";\u003c/TD\u003e\n\u003cTD\u003eThe variable has type  String and is assigned an initial value of \"Udacity\". \u003c/TD\u003e\n\u003cTD\u003eRecommended\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003escore= 80;\u003c/TD\u003e\n\u003cTD\u003eERROR: the type is required. This statement will not declare a variable. It is an assignment statement which assigns a new value to an existing variable. \u003c/TD\u003e\n\u003cTD\u003eNOT Recommended\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eint age= \"42\";\u003c/TD\u003e\n\u003cTD\u003eERROR: You cannot initialize a number with a String.  \"42\" is a String. See the quotation marks. \u003c/TD\u003e\n\u003cTD\u003eNOT Recommended\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eint age;\u003c/TD\u003e\n\u003cTD\u003eThis declares an integer variable without initializing it. It is best to initialize variables when they are created: int age = 0; If you do not know what value you  want yet \u003c/TD\u003e\n\u003cTD\u003e----\u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eNaming Rule\u003c/TH\u003e\n\u003cTH\u003eExample\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003eNames must consist of letters, numbers, an underscore, or a dollar sign only.\u003c/TD\u003e\n\u003cTD\u003escore_1\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eDon't use single letter variable name as you do in  mathematics. While it is legal in Java, it is usually not a good idea because it can make programs harder to understand. (you will encounter a couple of exceptions later)\u003c/TD\u003e\n\u003cTD\u003ea\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eWARNING: Names are case sensitive. Note that by convention, variable names start with a lowercase letter\u003c/TD\u003e\n\u003cTD\u003eFinalGrade, finalGrade, and FINALGRADE are all different variables\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eERROR Names cannot start with a number.\u003c/TD\u003e\n\u003cTD\u003e7up\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eERROR. You cannot use a reserved word as a name.\u003c/TD\u003e\n\u003cTD\u003eint\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eERROR: You cannot use special characters such as * or \u0026 in names.\u003c/TD\u003e\n\u003cTD\u003em\u0026m\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eERROR: Names cannot contain spaces.\u003c/TD\u003e\n\u003cTD\u003efinal grade\u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n**Number Types**\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eType\u003c/TH\u003e\n\u003cTH\u003eRange\u003c/TH\u003e\n\u003cTH\u003eSize\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003eint (integer)\u003c/TD\u003e\n\u003cTD\u003e–2,147,483,648 to 2,147,483,647(~2.14 billion)\u003c/TD\u003e\n\u003cTD\u003e4 bytes\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eshort (integer)\u003c/TD\u003e\n\u003cTD\u003e-32,768 to 32,767\u003c/TD\u003e\n\u003cTD\u003e 2 bytes \u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003elong (integer)\u003c/TD\u003e\n\u003cTD\u003e–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807\u003c/TD\u003e\n\u003cTD\u003e 8 bytes\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003ebyte\u003c/TD\u003e\n\u003cTD\u003e-128 to 127\u003c/TD\u003e\n\u003cTD\u003e 1 byte \u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003edouble(double-precision floating point)\u003c/TD\u003e\n\u003cTD\u003erange of about + or - 10^308\u003c/TD\u003e\n\u003cTD\u003e 8 bytes \u003c/TD\u003e\u003c/TR\u003e\n\u003cTD\u003efloat(single-precision floating point)\u003c/TD\u003e\n\u003cTD\u003erange of about + or - 10^38 \u0026 about 7 significant decimal places\u003c/TD\u003e\n\u003cTD\u003e 4 bytes \u003c/TD\u003e\u003c/TR\u003e\n\u003cTD\u003echar\u003c/TD\u003e\n\u003cTD\u003erepresents a Unicode character\u003c/TD\u003e\n\u003cTD\u003e 2 bytes \u003c/TD\u003e \u003c/TR\u003e\n\u003cTD\u003eboolean\u003c/TD\u003e\n\u003cTD\u003ehas only 2 possible values: true or false\u003c/TD\u003e\n\u003cTD\u003e 1 bit \u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eNumber Literals\u003c/TH\u003e\n\u003cTH\u003eDescription\u003c/TH\u003e\n\u003cTH\u003eExamples\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003eint\u003c/TD\u003e\n\u003cTD\u003eAn integer has no fractional part and can be positive, negative, or 0.\u003c/TD\u003e\n\u003cTD\u003e5,-100,0\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003edouble\u003c/TD\u003e\n\u003cTD\u003eA number with fractional part\u003c/TD\u003e\n\u003cTD\u003e1.7, 1.0, 2.4E5, 3.47E-2\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eERROR\u003c/TD\u003e\n\u003cTD\u003eDo not use a comma to separate thousands\u003c/TD\u003e\n\u003cTD\u003e1,000,000\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eERROR\u003c/TD\u003e\n\u003cTD\u003e Do not use a fraction. Use a decimal instead.\u003c/TD\u003e\n\u003cTD\u003e 3 1/4 \u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n**Integer Arithmetic**\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eExpression\u003c/TH\u003e\n\u003cTH\u003eValue (when n =2497)\u003c/TH\u003e\n\u003cTH\u003eDescription\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003en/10\u003c/TD\u003e\n\u003cTD\u003e249\u003c/TD\u003e\n\u003cTD\u003eNotice that the answer is an integer with no decimal part.\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003en % 10\u003c/TD\u003e\n\u003cTD\u003e7\u003c/TD\u003e\n\u003cTD\u003e Always the last digit of n\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003en /100 \u003c/TD\u003e\n\u003cTD\u003e24\u003c/TD\u003e\n\u003cTD\u003eAgain, decimal part is discarded. Removes the last 2 digits.\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003en % 100\u003c/TD\u003e\n\u003cTD\u003e 97 \u003c/TD\u003e\n\u003cTD\u003e The last two digits. \u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003en % 2\u003c/TD\u003e\n\u003cTD\u003e 1 \u003c/TD\u003e\n\u003cTD\u003e If n % 2 is 0 the number is even. Otherwise it is odd. \u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n**Math Functions**\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eMethod\u003c/TH\u003e\n\u003cTH\u003eReturn Value\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003eMath.sqrt (n)\u003c/TD\u003e\n\u003cTD\u003eSquare root of n ( if n is \u003e or = to 0)\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eMath.pow(a,b)\u003c/TD\u003e\n\u003cTD\u003ea^b( if a = 0, b must be \u003e0)\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.sin(n)\u003c/TD\u003e\n\u003cTD\u003eSine of n where n is in radians\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.cos(n)\u003c/TD\u003e\n\u003cTD\u003eCosine of n where n is in radians\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.tan(n)\u003c/TD\u003e\n\u003cTD\u003eTangent of n where n is in radians\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.round(n)\u003c/TD\u003e\n\u003cTD\u003eclosest integer to n as a long\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.ceil(n)\u003c/TD\u003e\n\u003cTD\u003esmallest integer \u003e or = to n as a double\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.floor(n)\u003c/TD\u003e\n\u003cTD\u003elargest integer \u003c or = to n as a double\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.toRadians(n)\u003c/TD\u003e\n\u003cTD\u003eConverts n degrees to radians\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.toDegrees(n)\u003c/TD\u003e\n\u003cTD\u003eConverts n radians to degrees\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.abs(n)\u003c/TD\u003e\n\u003cTD\u003eAbsolute value of n |n|\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.max(a,b)\u003c/TD\u003e\n\u003cTD\u003eThe larger of a and b\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.min(a,b)\u003c/TD\u003e\n\u003cTD\u003eThe smaller of a and b\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.exp(n)\u003c/TD\u003e\n\u003cTD\u003ee^n\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.log(n)\u003c/TD\u003e\n\u003cTD\u003enatural log of n\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTD\u003eMath.log10(n)\u003c/TD\u003e\n\u003cTD\u003eBase 10 log of n\u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n**String Formatting**\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eCode\u003c/TH\u003e\n\u003cTH\u003eIn an Example\u003c/TH\u003e\n\u003cTH\u003eType\u003c/TH\u003e\n\u003cTH\u003eWhat It Prints\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003ed\u003c/TD\u003e\n\u003cTD\u003e\"%4d\"\u003c/TD\u003e\n\u003cTD\u003eDecimal integer\u003c/TD\u003e\n\u003cTD\u003e 123\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003ex\u003c/TD\u003e\n\u003cTD\u003e\"%x\"\u003c/TD\u003e\n\u003cTD\u003eHexadecimal integer\u003c/TD\u003e\n\u003cTD\u003e7A\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eo\u003c/TD\u003e\n\u003cTD\u003e\"%o\"\u003c/TD\u003e\n\u003cTD\u003eOctal integer\u003c/TD\u003e\n\u003cTD\u003e173\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003ef\u003c/TD\u003e\n\u003cTD\u003e\"%5.2f\"\u003c/TD\u003e\n\u003cTD\u003eFixed floating-point\u003c/TD\u003e\n\u003cTD\u003e12.30\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003ee\u003c/TD\u003e\n\u003cTD\u003e\"%e\"\u003c/TD\u003e\n\u003cTD\u003eExponential (very large or small) floating-point\u003c/TD\u003e\n\u003cTD\u003e1.23e+1\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eg\u003c/TD\u003e\n\u003cTD\u003e\"%3.2g\"\u003c/TD\u003e\n\u003cTD\u003eGeneral (medium sized) floating-point\u003c/TD\u003e\n\u003cTD\u003e12.3\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003es\u003c/TD\u003e\n\u003cTD\u003e\"%s\"\u003c/TD\u003e\n\u003cTD\u003eString\u003c/TD\u003e\n\u003cTD\u003eTax: \u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003en\u003c/TD\u003e\n\u003cTD\u003e\"%n\" or \"\\n\"\u003c/TD\u003e\n\u003cTD\u003eLine end\u003c/TD\u003e\n\u003cTD\u003e\u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n**Format Flags**\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eFlag\u003c/TH\u003e\n\u003cTH\u003eIn an Example\u003c/TH\u003e\n\u003cTH\u003eMeaning\u003c/TH\u003e\n\u003cTH\u003eWhat It Prints\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003e-\u003c/TD\u003e\n\u003cTD\u003e\"%-6d\"\u003c/TD\u003e\n\u003cTD\u003eAlign left\u003c/TD\u003e\n\u003cTD\u003ean integer that takes 6 spaces and starts in the first one\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003e0\u003c/TD\u003e\n\u003cTD\u003e\"%07.2f\"\u003c/TD\u003e\n\u003cTD\u003eShow leading zeroes\u003c/TD\u003e\n\u003cTD\u003e0001.23\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003e+\u003c/TD\u003e\n\u003cTD\u003e\"%+7.2f\"\u003c/TD\u003e\n\u003cTD\u003eShow a plus sign for positive numbers\u003c/TD\u003e\n\u003cTD\u003e+1.23\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003e(\u003c/TD\u003e\n\u003cTD\u003e\"%(6.2f\"\u003c/TD\u003e\n\u003cTD\u003eEnclose negative numbers in parentheses\u003c/TD\u003e\n\u003cTD\u003e-1.23 would look like (1.23)\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003e,\u003c/TD\u003e\n\u003cTD\u003e\"%,10d\"\u003c/TD\u003e\n\u003cTD\u003eShow decimal separators\u003c/TD\u003e\n\u003cTD\u003e12,300\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003e^\u003c/TD\u003e\n\u003cTD\u003e\"%^s\"\u003c/TD\u003e\n\u003cTD\u003econvert letters to uppercase\u003c/TD\u003e\n\u003cTD\u003e\"tax:\" would print as \"TAX:\"\u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\n**Strings**\n\n\u003cTABLE class=\"table-default\"\u003e\n\u003cTHEAD\u003e\n\u003cTR\u003e\n\u003cTH\u003eExample_Code_For_String_Methods\u003c/TH\u003e\n\u003cTH\u003eResult\u003c/TH\u003e\n\u003cTH\u003eOther info\u003c/TH\u003e\n\u003c/TR\u003e\n\u003c/THEAD\u003e\n\u003cTBODY\u003e\n\u003cTR\u003e\n\u003cTD\u003eString str = \"Java \";\u003cbr/\u003e str = str + \"Programming\"\u003c/TD\u003e\n\u003cTD\u003estr is assigned the value \"Java Programming\"\u003c/TD\u003e\n\u003cTD\u003eThe + sign is used to concatenate Strings\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString answer = \"Total: \" + 42;\u003c/TD\u003e\n\u003cTD\u003eanswer is set to \"Total: 42\"\u003c/TD\u003e\n\u003cTD\u003eBecause \"Total: \" is a string 42 is converted to a string and then the concatenation takes place\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString name = \"Sara T\";\u003cbr/\u003e int len = name.length();\u003c/TD\u003e\n\u003cTD\u003elen is set to 6\u003c/TD\u003e\n\u003cTD\u003eThe number of characters in a string. A space counts as a character\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString city = \"San Jose\"; \u003cbr/\u003e String sub = city.substring(1, 3);\u003c/TD\u003e\n\u003cTD\u003esub is set to \"an\"\u003c/TD\u003e\n\u003cTD\u003eTakes the substring starting at position 1 and ending before position 3\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString city = \"San Jose\"; \u003cbr/\u003e String first = city.substring(0, 1);\u003c/TD\u003e\n\u003cTD\u003efirst is set to \"S\"\u003c/TD\u003e\n\u003cTD\u003eGets the first character. The substring has length 1 \u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString city = \"San Jose\"; \u003cbr/\u003e\nString sub = city.substring(4);\"\u003c/TD\u003e\n\u003cTD\u003esub is set to \"Jose\"\u003c/TD\u003e\n\u003cTD\u003eIf you only supply one parameter, the substring consists of all characters from that position until the end of the String\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString city = \"San Jose\"; \u003cbr/\u003e \nString last = city.substring(city.length() - 1);\u003c/TD\u003e\n\u003cTD\u003ereturns the string containing the last letter in the string (\"e\") and assigns it to last\u003c/TD\u003e\n\u003cTD\u003estr.substring(str.length() - 1) will always give you the last character as a String\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString city = \"San Jose\";\u003cbr/\u003e\nint index = city.indexOf(\"Jose\")\n\u003c/TD\u003e\n\u003cTD\u003eindex is set to 4\u003c/TD\u003e\n\u003cTD\u003ereturns the index where \"Jose\" starts\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString city = \"Santa Barbara\";\u003cbr/\u003e\nint index = city.lastIndexOf(\"a\")\n\u003c/TD\u003e\n\u003cTD\u003eindex is set to 12\u003c/TD\u003e\n\u003cTD\u003ereturns the index of the last \"a\" in the string\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString cityWithTypo = \"Son Jose\";\u003cbr/\u003e\nString cityCorrected = cityWithTypo.replace(\"Son\",\"San\");\n\u003c/TD\u003e\n\u003cTD\u003eChanges all ocurrences of \"Son\" to \"San\" in cityWithTypo and put the result in cityCorrected\u003c/TD\u003e\n\u003cTD\u003eWill also worked the following (\"So\",\"Sa\");\u003c/TD\u003e\n\u003c/TR\u003e\n\u003cTR\u003e\n\u003cTD\u003eString sentence = \"Joseph is in San Jose\";\u003cbr/\u003e\nint index = sentence.indexOf(\"Jose\", 2)\u003c/TD\u003e\n\u003cTD\u003eindex is set to 17\u003c/TD\u003e\n\u003cTD\u003eindexOf returns the index where \"Jose\" starts. When an index position is supplied as the second argument (2 in this case), search will begin AFTER that index\u003c/TD\u003e\n\u003c/TR\u003e\n\u003c/TBODY\u003e\n\u003c/TABLE\u003e\n\nCommon Loop Algorithms\n======================\n\nSum\n-------\n\u003cpre style='font-family: \"Consolas\"', cursive\u003e\ntotal = 0\nfor each item\n     total = total + input\n\u003c/pre\u003e\n\nCounting Matches\n----------------\n\u003cpre style='font-family: \"Consolas\"', cursive\u003e\nmatches = 0\nfor each item\n    if the item matches\n        matches = matches + 1\n\u003c/pre\u003e\n\nFinding the Location of the First Match\n----------------\n\u003cpre style='font-family: \"Consolas\"', cursive\u003e\nfound = false\nposition = 0\nwhile it's not found, and there are more items\n    if the item at position matches\n        found = true\n    else \n        position = position + 1\nif the item was found\n    its location is position\n\u003c/pre\u003e\n\nMaximum\n-----------\n\n\u003cpre style='font-family: \"Consolas\"', cursive\u003e\nlargest = the first item\nfor all the items except the first\n    if the current item is larger than largest\n        replace the value in largest with the current item\n\u003c/pre\u003e\n\n\u003cspan\u003eLast Update: 21.08.2021\u003c/span\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenezt%2Fjava-coding-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenezt%2Fjava-coding-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenezt%2Fjava-coding-examples/lists"}