Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 62 additions & 27 deletions samples/notebooks/LearningSample.ijnb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"id": "1c4583aa-a137-4e55-915e-5c218bc02744",
"cell_type": "markdown",
"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.",
"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.",
"metadata": {
"language": "markdown",
"id": "1c4583aa-a137-4e55-915e-5c218bc02744"
Expand All @@ -25,6 +25,39 @@
"id": "21015b6e-8260-43d6-a629-4e7c2b5d6ff3"
}
},
{
"id": "9de98c25-6285-416d-8a56-d9cad1675efa",
"cell_type": "markdown",
"source": "### Greetings !!\nExecute the code snippet below and enter your name in the input box that opens at the top of your screen.",
"metadata": {
"language": "markdown",
"id": "9de98c25-6285-416d-8a56-d9cad1675efa"
}
},
{
"id": "3df5b924-bc0e-47fd-a556-dcf71eeabfb8",
"cell_type": "code",
"source": "\nString name = IO.readln(\"Enter your name:\\n\");\nIO.println(\"Hello \"+name+\" !!\");",
"metadata": {
"language": "java",
"id": "3df5b924-bc0e-47fd-a556-dcf71eeabfb8",
"executionSummary": {
"executionOrder": 1,
"success": true
}
},
"execution_count": 1,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "Enter your name:\nHello <name> !!\n"
},
"metadata": {},
"execution_count": 1
}
]
},
{
"id": "98ba9913-0b56-458d-ab0e-0bdad5744159",
"cell_type": "markdown",
Expand Down Expand Up @@ -55,24 +88,24 @@
{
"id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8",
"cell_type": "code",
"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);",
"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);",
"metadata": {
"language": "java",
"id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8",
"executionSummary": {
"executionOrder": 1,
"executionOrder": 2,
"success": true
}
},
"execution_count": 1,
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "=== Integer data types Demo ===\nbyte: 127\nshort: 32000\nint: 2147483647\nlong: 9223372036854775807\n"
},
"metadata": {},
"execution_count": 1
"execution_count": 2
}
]
},
Expand All @@ -88,23 +121,24 @@
{
"id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4",
"cell_type": "code",
"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",
"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",
"metadata": {
"language": "java",
"id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4",
"executionSummary": {
"executionOrder": 2,
"executionOrder": 3,
"success": true
}
},
"execution_count": 2,
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "=== Floating point data types Demo ===\nfloat: 3.14\ndouble: 3.141592653589793\n"
},
"metadata": {},
"execution_count": 2
"execution_count": 3
}
]
},
Expand All @@ -120,9 +154,10 @@
{
"id": "dff83078-4563-4831-b012-1f5e6c61df5d",
"cell_type": "code",
"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);",
"source": "boolean isJavaFun = true;\nchar firstAlphabet = 'A'; \n\nIO.println(\"=== Other primitive data types Demo ===\");\nIO.println(\"boolean: \" + isJavaFun);\nIO.println(\"char: \" + firstAlphabet);",
"metadata": {
"language": "java",
"id": "dff83078-4563-4831-b012-1f5e6c61df5d",
"executionSummary": {
"executionOrder": 4,
"success": true
Expand Down Expand Up @@ -161,24 +196,24 @@
{
"id": "9d083943-839f-4ab1-b652-21d05f1827fe",
"cell_type": "code",
"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);",
"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);",
"metadata": {
"language": "java",
"id": "9d083943-839f-4ab1-b652-21d05f1827fe",
"executionSummary": {
"executionOrder": 2,
"executionOrder": 5,
"success": true
}
},
"execution_count": 2,
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "=== Conditional if-else statement example ===\nYou are allowed to enter.\n=== Conditional switch-case statement example ===\nDay 3 is: Wednesday\n"
},
"metadata": {},
"execution_count": 2
"execution_count": 5
}
]
},
Expand All @@ -203,24 +238,24 @@
{
"id": "17fed500-4e81-49b5-9576-99bfd1bdeea7",
"cell_type": "code",
"source": "System.out.print(\"Counting 1-5: \");\nfor (int i = 1; i <= 5; i++) {\n System.out.print(i + \" \");\n}\nSystem.out.println();",
"source": "IO.print(\"Counting 1-5: \");\nfor (int i = 1; i <= 5; i++) {\n IO.print(i + \" \");\n}\nIO.println();",
"metadata": {
"language": "java",
"id": "17fed500-4e81-49b5-9576-99bfd1bdeea7",
"executionSummary": {
"executionOrder": 3,
"executionOrder": 6,
"success": true
}
},
"execution_count": 3,
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "Counting 1-5: 1 2 3 4 5 \n"
},
"metadata": {},
"execution_count": 3
"execution_count": 6
}
]
},
Expand All @@ -236,24 +271,24 @@
{
"id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d",
"cell_type": "code",
"source": "int countdown = 5;\nSystem.out.print(\"Countdown: \");\nwhile (countdown > 0) {\n System.out.print(countdown + \" \");\n countdown--;\n}\nSystem.out.println(\"Countdown completed!\");",
"source": "int countdown = 5;\nIO.print(\"Countdown: \");\nwhile (countdown > 0) {\n IO.print(countdown + \" \");\n countdown--;\n}\nIO.println(\"Countdown completed!\");",
"metadata": {
"language": "java",
"id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d",
"executionSummary": {
"executionOrder": 4,
"executionOrder": 7,
"success": true
}
},
"execution_count": 4,
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "Countdown: 5 4 3 2 1 Countdown completed!\n"
},
"metadata": {},
"execution_count": 4
"execution_count": 7
}
]
},
Expand All @@ -269,24 +304,24 @@
{
"id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba",
"cell_type": "code",
"source": "int[] numbers = {10, 20, 30, 40, 50};\nSystem.out.print(\"Array elements: \");\nfor (int num : numbers) {\n System.out.print(num + \" \");\n}",
"source": "var numbers = List.of(10, 20, 30, 40, 50);\nIO.print(\"List elements: \");\nfor (var num : numbers) {\n IO.print(num + \" \");\n}",
"metadata": {
"language": "java",
"id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba",
"executionSummary": {
"executionOrder": 5,
"executionOrder": 8,
"success": true
}
},
"execution_count": 5,
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "Array elements: 10 20 30 40 50 "
"text/plain": "List elements: 10 20 30 40 50 "
},
"metadata": {},
"execution_count": 5
"execution_count": 8
}
]
}
Expand Down
Loading