Skip to content

Commit 6a120b4

Browse files
committed
Update notebook samples
1 parent f42e1bf commit 6a120b4

File tree

2 files changed

+391
-27
lines changed

2 files changed

+391
-27
lines changed

samples/notebooks/LearningSample.ijnb

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{
1111
"id": "1c4583aa-a137-4e55-915e-5c218bc02744",
1212
"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.",
1414
"metadata": {
1515
"language": "markdown",
1616
"id": "1c4583aa-a137-4e55-915e-5c218bc02744"
@@ -25,6 +25,39 @@
2525
"id": "21015b6e-8260-43d6-a629-4e7c2b5d6ff3"
2626
}
2727
},
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+
},
2861
{
2962
"id": "98ba9913-0b56-458d-ab0e-0bdad5744159",
3063
"cell_type": "markdown",
@@ -55,24 +88,24 @@
5588
{
5689
"id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8",
5790
"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);",
5992
"metadata": {
6093
"language": "java",
6194
"id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8",
6295
"executionSummary": {
63-
"executionOrder": 1,
96+
"executionOrder": 2,
6497
"success": true
6598
}
6699
},
67-
"execution_count": 1,
100+
"execution_count": 2,
68101
"outputs": [
69102
{
70103
"output_type": "execute_result",
71104
"data": {
72105
"text/plain": "=== Integer data types Demo ===\nbyte: 127\nshort: 32000\nint: 2147483647\nlong: 9223372036854775807\n"
73106
},
74107
"metadata": {},
75-
"execution_count": 1
108+
"execution_count": 2
76109
}
77110
]
78111
},
@@ -88,23 +121,24 @@
88121
{
89122
"id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4",
90123
"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",
92125
"metadata": {
93126
"language": "java",
127+
"id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4",
94128
"executionSummary": {
95-
"executionOrder": 2,
129+
"executionOrder": 3,
96130
"success": true
97131
}
98132
},
99-
"execution_count": 2,
133+
"execution_count": 3,
100134
"outputs": [
101135
{
102136
"output_type": "execute_result",
103137
"data": {
104138
"text/plain": "=== Floating point data types Demo ===\nfloat: 3.14\ndouble: 3.141592653589793\n"
105139
},
106140
"metadata": {},
107-
"execution_count": 2
141+
"execution_count": 3
108142
}
109143
]
110144
},
@@ -120,9 +154,10 @@
120154
{
121155
"id": "dff83078-4563-4831-b012-1f5e6c61df5d",
122156
"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);",
124158
"metadata": {
125159
"language": "java",
160+
"id": "dff83078-4563-4831-b012-1f5e6c61df5d",
126161
"executionSummary": {
127162
"executionOrder": 4,
128163
"success": true
@@ -161,24 +196,24 @@
161196
{
162197
"id": "9d083943-839f-4ab1-b652-21d05f1827fe",
163198
"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);",
165200
"metadata": {
166201
"language": "java",
167202
"id": "9d083943-839f-4ab1-b652-21d05f1827fe",
168203
"executionSummary": {
169-
"executionOrder": 2,
204+
"executionOrder": 5,
170205
"success": true
171206
}
172207
},
173-
"execution_count": 2,
208+
"execution_count": 5,
174209
"outputs": [
175210
{
176211
"output_type": "execute_result",
177212
"data": {
178213
"text/plain": "=== Conditional if-else statement example ===\nYou are allowed to enter.\n=== Conditional switch-case statement example ===\nDay 3 is: Wednesday\n"
179214
},
180215
"metadata": {},
181-
"execution_count": 2
216+
"execution_count": 5
182217
}
183218
]
184219
},
@@ -203,24 +238,24 @@
203238
{
204239
"id": "17fed500-4e81-49b5-9576-99bfd1bdeea7",
205240
"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();",
207242
"metadata": {
208243
"language": "java",
209244
"id": "17fed500-4e81-49b5-9576-99bfd1bdeea7",
210245
"executionSummary": {
211-
"executionOrder": 3,
246+
"executionOrder": 6,
212247
"success": true
213248
}
214249
},
215-
"execution_count": 3,
250+
"execution_count": 6,
216251
"outputs": [
217252
{
218253
"output_type": "execute_result",
219254
"data": {
220255
"text/plain": "Counting 1-5: 1 2 3 4 5 \n"
221256
},
222257
"metadata": {},
223-
"execution_count": 3
258+
"execution_count": 6
224259
}
225260
]
226261
},
@@ -236,24 +271,24 @@
236271
{
237272
"id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d",
238273
"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!\");",
240275
"metadata": {
241276
"language": "java",
242277
"id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d",
243278
"executionSummary": {
244-
"executionOrder": 4,
279+
"executionOrder": 7,
245280
"success": true
246281
}
247282
},
248-
"execution_count": 4,
283+
"execution_count": 7,
249284
"outputs": [
250285
{
251286
"output_type": "execute_result",
252287
"data": {
253288
"text/plain": "Countdown: 5 4 3 2 1 Countdown completed!\n"
254289
},
255290
"metadata": {},
256-
"execution_count": 4
291+
"execution_count": 7
257292
}
258293
]
259294
},
@@ -269,24 +304,24 @@
269304
{
270305
"id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba",
271306
"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 (int num : numbers) {\n IO.print(num + \" \");\n}",
273308
"metadata": {
274309
"language": "java",
275310
"id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba",
276311
"executionSummary": {
277-
"executionOrder": 5,
312+
"executionOrder": 8,
278313
"success": true
279314
}
280315
},
281-
"execution_count": 5,
316+
"execution_count": 8,
282317
"outputs": [
283318
{
284319
"output_type": "execute_result",
285320
"data": {
286-
"text/plain": "Array elements: 10 20 30 40 50 "
321+
"text/plain": "List elements: 10 20 30 40 50 "
287322
},
288323
"metadata": {},
289-
"execution_count": 5
324+
"execution_count": 8
290325
}
291326
]
292327
}

0 commit comments

Comments
 (0)