|
10 | 10 | { |
11 | 11 | "id": "1c4583aa-a137-4e55-915e-5c218bc02744", |
12 | 12 | "cell_type": "markdown", |
13 | | - "source": "<!--\n Copyright (c) 2025, Oracle and/or its affiliates.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n-->\n***Sample Note:***\n\nThis notebook demonstrates the use of notebooks in helping learners explore some basic concepts of Java with small, self-contained examples.\n\n**What this sample shows:**\n\n- Markdown-formatted guidance with clearly organized sections\n- Running code cells displays output inline\n - Optionally includes saved outputs from prior runs for reference\n\n**Prerequisites:**\n\nThis notebook requires Java 17+ to run all the cells successfully.", |
| 13 | + "source": "<!--\n Copyright (c) 2025, Oracle and/or its affiliates.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n-->\n***Sample Note:***\n\nThis notebook demonstrates the use of notebooks in helping learners explore some basic concepts of Java with small, self-contained examples.\n\n**What this sample shows:**\n\n- Markdown-formatted guidance with clearly organized sections\n- Running code cells displays output inline\n - Optionally includes saved outputs from prior runs for reference\n\n**Prerequisites:**\n\nThis notebook requires Java 25+ to run all the cells successfully.", |
14 | 14 | "metadata": { |
15 | 15 | "language": "markdown", |
16 | 16 | "id": "1c4583aa-a137-4e55-915e-5c218bc02744" |
|
25 | 25 | "id": "21015b6e-8260-43d6-a629-4e7c2b5d6ff3" |
26 | 26 | } |
27 | 27 | }, |
| 28 | + { |
| 29 | + "id": "9de98c25-6285-416d-8a56-d9cad1675efa", |
| 30 | + "cell_type": "markdown", |
| 31 | + "source": "### Greetings !!\nExecute the code snippet below and enter your name in the input box that opens at the top of your screen.", |
| 32 | + "metadata": { |
| 33 | + "language": "markdown", |
| 34 | + "id": "9de98c25-6285-416d-8a56-d9cad1675efa" |
| 35 | + } |
| 36 | + }, |
| 37 | + { |
| 38 | + "id": "3df5b924-bc0e-47fd-a556-dcf71eeabfb8", |
| 39 | + "cell_type": "code", |
| 40 | + "source": "\nString name = IO.readln(\"Enter your name:\\n\");\nIO.println(\"Hello \"+name+\" !!\");", |
| 41 | + "metadata": { |
| 42 | + "language": "java", |
| 43 | + "id": "3df5b924-bc0e-47fd-a556-dcf71eeabfb8", |
| 44 | + "executionSummary": { |
| 45 | + "executionOrder": 1, |
| 46 | + "success": true |
| 47 | + } |
| 48 | + }, |
| 49 | + "execution_count": 1, |
| 50 | + "outputs": [ |
| 51 | + { |
| 52 | + "output_type": "execute_result", |
| 53 | + "data": { |
| 54 | + "text/plain": "Enter your name:\nHello <name> !!\n" |
| 55 | + }, |
| 56 | + "metadata": {}, |
| 57 | + "execution_count": 1 |
| 58 | + } |
| 59 | + ] |
| 60 | + }, |
28 | 61 | { |
29 | 62 | "id": "98ba9913-0b56-458d-ab0e-0bdad5744159", |
30 | 63 | "cell_type": "markdown", |
|
55 | 88 | { |
56 | 89 | "id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8", |
57 | 90 | "cell_type": "code", |
58 | | - "source": "byte smallNumber = 127;\nshort mediumNumber = 32000;\nint regularNumber = 2147483647; \nlong bigNumber = 9223372036854775807L;\n\nSystem.out.println(\"=== Integer data types Demo ===\");\nSystem.out.println(\"byte: \" + smallNumber);\nSystem.out.println(\"short: \" + mediumNumber);\nSystem.out.println(\"int: \" + regularNumber);\nSystem.out.println(\"long: \" + bigNumber);", |
| 91 | + "source": "byte smallNumber = 127;\nshort mediumNumber = 32000;\nint regularNumber = 2147483647; \nlong bigNumber = 9223372036854775807L;\n\nIO.println(\"=== Integer data types Demo ===\");\nIO.println(\"byte: \" + smallNumber);\nIO.println(\"short: \" + mediumNumber);\nIO.println(\"int: \" + regularNumber);\nIO.println(\"long: \" + bigNumber);", |
59 | 92 | "metadata": { |
60 | 93 | "language": "java", |
61 | 94 | "id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8", |
62 | 95 | "executionSummary": { |
63 | | - "executionOrder": 1, |
| 96 | + "executionOrder": 2, |
64 | 97 | "success": true |
65 | 98 | } |
66 | 99 | }, |
67 | | - "execution_count": 1, |
| 100 | + "execution_count": 2, |
68 | 101 | "outputs": [ |
69 | 102 | { |
70 | 103 | "output_type": "execute_result", |
71 | 104 | "data": { |
72 | 105 | "text/plain": "=== Integer data types Demo ===\nbyte: 127\nshort: 32000\nint: 2147483647\nlong: 9223372036854775807\n" |
73 | 106 | }, |
74 | 107 | "metadata": {}, |
75 | | - "execution_count": 1 |
| 108 | + "execution_count": 2 |
76 | 109 | } |
77 | 110 | ] |
78 | 111 | }, |
|
88 | 121 | { |
89 | 122 | "id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4", |
90 | 123 | "cell_type": "code", |
91 | | - "source": "\nfloat decimal1 = 3.14f;\ndouble decimal2 = 3.141592653589793;\n\nSystem.out.println(\"=== Floating point data types Demo ===\");\nSystem.out.println(\"float: \" + decimal1);\nSystem.out.println(\"double: \" + decimal2);\n", |
| 124 | + "source": "\nfloat decimal1 = 3.14f;\ndouble decimal2 = 3.141592653589793;\n\nIO.println(\"=== Floating point data types Demo ===\");\nIO.println(\"float: \" + decimal1);\nIO.println(\"double: \" + decimal2);\n", |
92 | 125 | "metadata": { |
93 | 126 | "language": "java", |
| 127 | + "id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4", |
94 | 128 | "executionSummary": { |
95 | | - "executionOrder": 2, |
| 129 | + "executionOrder": 3, |
96 | 130 | "success": true |
97 | 131 | } |
98 | 132 | }, |
99 | | - "execution_count": 2, |
| 133 | + "execution_count": 3, |
100 | 134 | "outputs": [ |
101 | 135 | { |
102 | 136 | "output_type": "execute_result", |
103 | 137 | "data": { |
104 | 138 | "text/plain": "=== Floating point data types Demo ===\nfloat: 3.14\ndouble: 3.141592653589793\n" |
105 | 139 | }, |
106 | 140 | "metadata": {}, |
107 | | - "execution_count": 2 |
| 141 | + "execution_count": 3 |
108 | 142 | } |
109 | 143 | ] |
110 | 144 | }, |
|
120 | 154 | { |
121 | 155 | "id": "dff83078-4563-4831-b012-1f5e6c61df5d", |
122 | 156 | "cell_type": "code", |
123 | | - "source": "boolean isJavaFun = true;\nchar firstAlphabet = 'A'; \n\nSystem.out.println(\"=== Other primitive data types Demo ===\");\nSystem.out.println(\"boolean: \" + isJavaFun);\nSystem.out.println(\"char: \" + firstAlphabet);", |
| 157 | + "source": "boolean isJavaFun = true;\nchar firstAlphabet = 'A'; \n\nIO.println(\"=== Other primitive data types Demo ===\");\nIO.println(\"boolean: \" + isJavaFun);\nIO.println(\"char: \" + firstAlphabet);", |
124 | 158 | "metadata": { |
125 | 159 | "language": "java", |
| 160 | + "id": "dff83078-4563-4831-b012-1f5e6c61df5d", |
126 | 161 | "executionSummary": { |
127 | 162 | "executionOrder": 4, |
128 | 163 | "success": true |
|
161 | 196 | { |
162 | 197 | "id": "9d083943-839f-4ab1-b652-21d05f1827fe", |
163 | 198 | "cell_type": "code", |
164 | | - "source": "int age = 20;\nboolean hasID = true;\n\nSystem.out.println(\"=== Conditional if-else statement example ===\");\nif (age >= 18) {\n if (hasID) {\n System.out.println(\"You are allowed to enter.\");\n } else {\n System.out.println(\"You need to show your ID.\");\n }\n} else {\n System.out.println(\"You must be 18 or older to enter.\");\n}\n\n\nSystem.out.println(\"=== Conditional switch-case statement example ===\");\nint dayOfWeek = 3;\nString dayName;\n\nswitch (dayOfWeek) {\n case 1 -> dayName = \"Monday\";\n case 2 -> dayName = \"Tuesday\";\n case 3 -> dayName = \"Wednesday\";\n case 4 -> dayName = \"Thursday\";\n case 5 -> dayName = \"Friday\";\n case 6 -> dayName = \"Saturday\";\n case 7 -> dayName = \"Sunday\";\n default -> dayName = \"Invalid day\";\n}\n\nSystem.out.println(\"Day \" + dayOfWeek + \" is: \" + dayName);", |
| 199 | + "source": "int age = 20;\nboolean hasID = true;\n\nIO.println(\"=== Conditional if-else statement example ===\");\nif (age >= 18) {\n if (hasID) {\n IO.println(\"You are allowed to enter.\");\n } else {\n IO.println(\"You need to show your ID.\");\n }\n} else {\n IO.println(\"You must be 18 or older to enter.\");\n}\n\n\nIO.println(\"=== Conditional switch-case statement example ===\");\nint dayOfWeek = 3;\nString dayName;\n\nswitch (dayOfWeek) {\n case 1 -> dayName = \"Monday\";\n case 2 -> dayName = \"Tuesday\";\n case 3 -> dayName = \"Wednesday\";\n case 4 -> dayName = \"Thursday\";\n case 5 -> dayName = \"Friday\";\n case 6 -> dayName = \"Saturday\";\n case 7 -> dayName = \"Sunday\";\n default -> dayName = \"Invalid day\";\n}\n\nIO.println(\"Day \" + dayOfWeek + \" is: \" + dayName);", |
165 | 200 | "metadata": { |
166 | 201 | "language": "java", |
167 | 202 | "id": "9d083943-839f-4ab1-b652-21d05f1827fe", |
168 | 203 | "executionSummary": { |
169 | | - "executionOrder": 2, |
| 204 | + "executionOrder": 5, |
170 | 205 | "success": true |
171 | 206 | } |
172 | 207 | }, |
173 | | - "execution_count": 2, |
| 208 | + "execution_count": 5, |
174 | 209 | "outputs": [ |
175 | 210 | { |
176 | 211 | "output_type": "execute_result", |
177 | 212 | "data": { |
178 | 213 | "text/plain": "=== Conditional if-else statement example ===\nYou are allowed to enter.\n=== Conditional switch-case statement example ===\nDay 3 is: Wednesday\n" |
179 | 214 | }, |
180 | 215 | "metadata": {}, |
181 | | - "execution_count": 2 |
| 216 | + "execution_count": 5 |
182 | 217 | } |
183 | 218 | ] |
184 | 219 | }, |
|
203 | 238 | { |
204 | 239 | "id": "17fed500-4e81-49b5-9576-99bfd1bdeea7", |
205 | 240 | "cell_type": "code", |
206 | | - "source": "System.out.print(\"Counting 1-5: \");\nfor (int i = 1; i <= 5; i++) {\n System.out.print(i + \" \");\n}\nSystem.out.println();", |
| 241 | + "source": "IO.print(\"Counting 1-5: \");\nfor (int i = 1; i <= 5; i++) {\n IO.print(i + \" \");\n}\nIO.println();", |
207 | 242 | "metadata": { |
208 | 243 | "language": "java", |
209 | 244 | "id": "17fed500-4e81-49b5-9576-99bfd1bdeea7", |
210 | 245 | "executionSummary": { |
211 | | - "executionOrder": 3, |
| 246 | + "executionOrder": 6, |
212 | 247 | "success": true |
213 | 248 | } |
214 | 249 | }, |
215 | | - "execution_count": 3, |
| 250 | + "execution_count": 6, |
216 | 251 | "outputs": [ |
217 | 252 | { |
218 | 253 | "output_type": "execute_result", |
219 | 254 | "data": { |
220 | 255 | "text/plain": "Counting 1-5: 1 2 3 4 5 \n" |
221 | 256 | }, |
222 | 257 | "metadata": {}, |
223 | | - "execution_count": 3 |
| 258 | + "execution_count": 6 |
224 | 259 | } |
225 | 260 | ] |
226 | 261 | }, |
|
236 | 271 | { |
237 | 272 | "id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d", |
238 | 273 | "cell_type": "code", |
239 | | - "source": "int countdown = 5;\nSystem.out.print(\"Countdown: \");\nwhile (countdown > 0) {\n System.out.print(countdown + \" \");\n countdown--;\n}\nSystem.out.println(\"Countdown completed!\");", |
| 274 | + "source": "int countdown = 5;\nIO.print(\"Countdown: \");\nwhile (countdown > 0) {\n IO.print(countdown + \" \");\n countdown--;\n}\nIO.println(\"Countdown completed!\");", |
240 | 275 | "metadata": { |
241 | 276 | "language": "java", |
242 | 277 | "id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d", |
243 | 278 | "executionSummary": { |
244 | | - "executionOrder": 4, |
| 279 | + "executionOrder": 7, |
245 | 280 | "success": true |
246 | 281 | } |
247 | 282 | }, |
248 | | - "execution_count": 4, |
| 283 | + "execution_count": 7, |
249 | 284 | "outputs": [ |
250 | 285 | { |
251 | 286 | "output_type": "execute_result", |
252 | 287 | "data": { |
253 | 288 | "text/plain": "Countdown: 5 4 3 2 1 Countdown completed!\n" |
254 | 289 | }, |
255 | 290 | "metadata": {}, |
256 | | - "execution_count": 4 |
| 291 | + "execution_count": 7 |
257 | 292 | } |
258 | 293 | ] |
259 | 294 | }, |
|
269 | 304 | { |
270 | 305 | "id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba", |
271 | 306 | "cell_type": "code", |
272 | | - "source": "int[] numbers = {10, 20, 30, 40, 50};\nSystem.out.print(\"Array elements: \");\nfor (int num : numbers) {\n System.out.print(num + \" \");\n}", |
| 307 | + "source": "var numbers = List.of(10, 20, 30, 40, 50);\nIO.print(\"List elements: \");\nfor (var num : numbers) {\n IO.print(num + \" \");\n}", |
273 | 308 | "metadata": { |
274 | 309 | "language": "java", |
275 | 310 | "id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba", |
276 | 311 | "executionSummary": { |
277 | | - "executionOrder": 5, |
| 312 | + "executionOrder": 8, |
278 | 313 | "success": true |
279 | 314 | } |
280 | 315 | }, |
281 | | - "execution_count": 5, |
| 316 | + "execution_count": 8, |
282 | 317 | "outputs": [ |
283 | 318 | { |
284 | 319 | "output_type": "execute_result", |
285 | 320 | "data": { |
286 | | - "text/plain": "Array elements: 10 20 30 40 50 " |
| 321 | + "text/plain": "List elements: 10 20 30 40 50 " |
287 | 322 | }, |
288 | 323 | "metadata": {}, |
289 | | - "execution_count": 5 |
| 324 | + "execution_count": 8 |
290 | 325 | } |
291 | 326 | ] |
292 | 327 | } |
|
0 commit comments