Skip to content

Commit 5ac37ca

Browse files
committed
Added notebook sample
1 parent 840ba4e commit 5ac37ca

File tree

1 file changed

+294
-0
lines changed

1 file changed

+294
-0
lines changed
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 5,
4+
"metadata": {
5+
"language_info": {
6+
"name": "java"
7+
}
8+
},
9+
"cells": [
10+
{
11+
"id": "1c4583aa-a137-4e55-915e-5c218bc02744",
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.",
14+
"metadata": {
15+
"language": "markdown",
16+
"id": "1c4583aa-a137-4e55-915e-5c218bc02744"
17+
}
18+
},
19+
{
20+
"id": "21015b6e-8260-43d6-a629-4e7c2b5d6ff3",
21+
"cell_type": "markdown",
22+
"source": "# Learning Java Basics",
23+
"metadata": {
24+
"language": "markdown",
25+
"id": "21015b6e-8260-43d6-a629-4e7c2b5d6ff3"
26+
}
27+
},
28+
{
29+
"id": "98ba9913-0b56-458d-ab0e-0bdad5744159",
30+
"cell_type": "markdown",
31+
"source": "## Lesson-1: Primitive Data Types\n### Learning Objectives:\n- Understand primitive data types in Java\n- Learn variable declaration and initialization\n\n### Key Concepts:\n- **Primitive Types**: byte, short, int, long, float, double, boolean, char\n- **Variable Declaration**: `dataType variableName = value;`\n\nLet's start with basic variable declarations and see how different data types work:",
32+
"metadata": {
33+
"language": "markdown",
34+
"id": "98ba9913-0b56-458d-ab0e-0bdad5744159"
35+
}
36+
},
37+
{
38+
"id": "d996dd73-556b-4856-9a20-8f54da5615fc",
39+
"cell_type": "markdown",
40+
"source": "#### Primitive Types",
41+
"metadata": {
42+
"language": "markdown",
43+
"id": "d996dd73-556b-4856-9a20-8f54da5615fc"
44+
}
45+
},
46+
{
47+
"id": "fcad594a-7c8f-42fe-ac06-7415cb734163",
48+
"cell_type": "markdown",
49+
"source": "##### Integer Types\n\n<small>\n\n| Type | Size (bytes) | Range |\n|--------|--------------|-----------------------------|\n| `byte` | 1 | -128 to 127 |\n| `short` | 2 | -32,768 to 32,767 |\n| `int` | 4 | -2³¹ to 2³¹ − 1 |\n| `long` | 8 | -2⁶³ to 2⁶³ − 1 |\n\n</small>\n",
50+
"metadata": {
51+
"language": "markdown",
52+
"id": "fcad594a-7c8f-42fe-ac06-7415cb734163"
53+
}
54+
},
55+
{
56+
"id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8",
57+
"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);",
59+
"metadata": {
60+
"language": "java",
61+
"id": "d5dcf964-eeb5-4966-9ac6-58352b3606a8",
62+
"executionSummary": {
63+
"executionOrder": 1,
64+
"success": true
65+
}
66+
},
67+
"execution_count": 1,
68+
"outputs": [
69+
{
70+
"output_type": "execute_result",
71+
"data": {
72+
"text/plain": "=== Integer data types Demo ===\nbyte: 127\nshort: 32000\nint: 2147483647\nlong: 9223372036854775807\n"
73+
},
74+
"metadata": {},
75+
"execution_count": 1
76+
}
77+
]
78+
},
79+
{
80+
"id": "a8d96d05-5a00-4322-91ca-aa2878e8c757",
81+
"cell_type": "markdown",
82+
"source": "##### Floating-Point Types\n\n<small>\n\n| Type | Size (bytes) | Range |\n|----------|-------------|------------------------|\n| `float` | 4 | ~6-7 significant decimal digits |\n| `double` | 8 | ~15-16 significant decimal digits |\n\n</small>",
83+
"metadata": {
84+
"language": "markdown",
85+
"id": "a8d96d05-5a00-4322-91ca-aa2878e8c757"
86+
}
87+
},
88+
{
89+
"id": "71fbbad5-54d6-4d7a-8840-2101f61ca0a4",
90+
"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",
92+
"metadata": {
93+
"language": "java",
94+
"executionSummary": {
95+
"executionOrder": 2,
96+
"success": true
97+
}
98+
},
99+
"execution_count": 2,
100+
"outputs": [
101+
{
102+
"output_type": "execute_result",
103+
"data": {
104+
"text/plain": "=== Floating point data types Demo ===\nfloat: 3.14\ndouble: 3.141592653589793\n"
105+
},
106+
"metadata": {},
107+
"execution_count": 2
108+
}
109+
]
110+
},
111+
{
112+
"id": "65548da3-5558-4683-97ac-5cdd341001a3",
113+
"cell_type": "markdown",
114+
"source": "##### Other primitive Types\n\n<small>\n\n| Type | Size (bytes) | Range |\n|-----------|--------------|------------------------|\n| `char` | 2 | (Unicode Values) `\\u0000` (0) to `\\uFFFF` (65,535) |\n| `boolean` | JVM-dependent (typically 1 byte) | `true`, `false` |\n\n</small>",
115+
"metadata": {
116+
"language": "markdown",
117+
"id": "65548da3-5558-4683-97ac-5cdd341001a3"
118+
}
119+
},
120+
{
121+
"id": "dff83078-4563-4831-b012-1f5e6c61df5d",
122+
"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);",
124+
"metadata": {
125+
"language": "java",
126+
"executionSummary": {
127+
"executionOrder": 4,
128+
"success": true
129+
}
130+
},
131+
"execution_count": 4,
132+
"outputs": [
133+
{
134+
"output_type": "execute_result",
135+
"data": {
136+
"text/plain": "=== Other primitive data types Demo ===\nboolean: true\nchar: A\n"
137+
},
138+
"metadata": {},
139+
"execution_count": 4
140+
}
141+
]
142+
},
143+
{
144+
"id": "686ef654-eae5-450f-82d3-716c1844a09d",
145+
"cell_type": "markdown",
146+
"source": "## Lesson 2: Control Structures\n\n### Learning Objectives:\n- Master conditional statements (if-else, switch)\n- Understand different types of loops (for, while, do-while)\n- Learn when to use each control structure\n- Practice nested structures and loop control\n\n### Key Concepts:\n- **Conditional Logic**: Making decisions in code\n- **Loops**: Repeating code blocks efficiently\n- **Loop Control**: break, continue statements\n- **Best Practices**: Choosing the right structure for the task",
147+
"metadata": {
148+
"language": "markdown",
149+
"id": "686ef654-eae5-450f-82d3-716c1844a09d"
150+
}
151+
},
152+
{
153+
"id": "28fe4501-0c0e-4f10-ba51-521464c6f6f1",
154+
"cell_type": "markdown",
155+
"source": "#### Conditional Logic\nExplore `if-else` and `switch` expresssions below.",
156+
"metadata": {
157+
"language": "markdown",
158+
"id": "28fe4501-0c0e-4f10-ba51-521464c6f6f1"
159+
}
160+
},
161+
{
162+
"id": "9d083943-839f-4ab1-b652-21d05f1827fe",
163+
"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);",
165+
"metadata": {
166+
"language": "java",
167+
"id": "9d083943-839f-4ab1-b652-21d05f1827fe",
168+
"executionSummary": {
169+
"executionOrder": 2,
170+
"success": true
171+
}
172+
},
173+
"execution_count": 2,
174+
"outputs": [
175+
{
176+
"output_type": "execute_result",
177+
"data": {
178+
"text/plain": "=== Conditional if-else statement example ===\nYou are allowed to enter.\n=== Conditional switch-case statement example ===\nDay 3 is: Wednesday\n"
179+
},
180+
"metadata": {},
181+
"execution_count": 2
182+
}
183+
]
184+
},
185+
{
186+
"id": "325f07b7-e35c-440b-ae36-066d3c74d3f4",
187+
"cell_type": "markdown",
188+
"source": "#### Loops\nExplore different kinds of loops, using statements such as `for`, `enhanced-for` and `while` below.",
189+
"metadata": {
190+
"language": "markdown",
191+
"id": "325f07b7-e35c-440b-ae36-066d3c74d3f4"
192+
}
193+
},
194+
{
195+
"id": "03405940-5dc9-4569-8f69-a320bebb1ffe",
196+
"cell_type": "markdown",
197+
"source": "##### `for` loop - counting",
198+
"metadata": {
199+
"language": "markdown",
200+
"id": "03405940-5dc9-4569-8f69-a320bebb1ffe"
201+
}
202+
},
203+
{
204+
"id": "17fed500-4e81-49b5-9576-99bfd1bdeea7",
205+
"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();",
207+
"metadata": {
208+
"language": "java",
209+
"id": "17fed500-4e81-49b5-9576-99bfd1bdeea7",
210+
"executionSummary": {
211+
"executionOrder": 3,
212+
"success": true
213+
}
214+
},
215+
"execution_count": 3,
216+
"outputs": [
217+
{
218+
"output_type": "execute_result",
219+
"data": {
220+
"text/plain": "Counting 1-5: 1 2 3 4 5 \n"
221+
},
222+
"metadata": {},
223+
"execution_count": 3
224+
}
225+
]
226+
},
227+
{
228+
"id": "1272027a-b7d6-4db8-84da-0a97a5510f44",
229+
"cell_type": "markdown",
230+
"source": "##### `while` loop - with condition",
231+
"metadata": {
232+
"language": "markdown",
233+
"id": "1272027a-b7d6-4db8-84da-0a97a5510f44"
234+
}
235+
},
236+
{
237+
"id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d",
238+
"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!\");",
240+
"metadata": {
241+
"language": "java",
242+
"id": "f7135abb-43e7-4eb7-aa45-4f91f8dd485d",
243+
"executionSummary": {
244+
"executionOrder": 4,
245+
"success": true
246+
}
247+
},
248+
"execution_count": 4,
249+
"outputs": [
250+
{
251+
"output_type": "execute_result",
252+
"data": {
253+
"text/plain": "Countdown: 5 4 3 2 1 Countdown completed!\n"
254+
},
255+
"metadata": {},
256+
"execution_count": 4
257+
}
258+
]
259+
},
260+
{
261+
"id": "e5ab8d0b-dfd0-4d5e-a7f6-b9eee6be9bee",
262+
"cell_type": "markdown",
263+
"source": "##### Enhanced `for` loop with array",
264+
"metadata": {
265+
"language": "markdown",
266+
"id": "e5ab8d0b-dfd0-4d5e-a7f6-b9eee6be9bee"
267+
}
268+
},
269+
{
270+
"id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba",
271+
"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}",
273+
"metadata": {
274+
"language": "java",
275+
"id": "3b0d4c9f-b0d2-4e98-bb47-3af51693e0ba",
276+
"executionSummary": {
277+
"executionOrder": 5,
278+
"success": true
279+
}
280+
},
281+
"execution_count": 5,
282+
"outputs": [
283+
{
284+
"output_type": "execute_result",
285+
"data": {
286+
"text/plain": "Array elements: 10 20 30 40 50 "
287+
},
288+
"metadata": {},
289+
"execution_count": 5
290+
}
291+
]
292+
}
293+
]
294+
}

0 commit comments

Comments
 (0)