· 9 years ago · Oct 13, 2016, 09:26 AM
1
2[
3 {
4 "lesson": {
5 "id": 2131,
6 "name": "Introduction to Java",
7 "type": 0,
8 "mode": 1,
9 "videoID": "Qi954__kQbo",
10 "tags": null,
11 "quizzes": [
12 {
13 "id": 4183,
14 "number": 1,
15 "videoStart": 20.4,
16 "videoEnd": 135,
17 "linkedVideoID": null,
18 "type": 1,
19 "linkedQuizID": null,
20 "tip": null,
21 "hint": null,
22 "time": 0,
23 "answers": [
24 {
25 "id": 92118,
26 "text": "Just one version",
27 "isCorrect": true,
28 "properties": {}
29 },
30 {
31 "id": 92119,
32 "text": "Two versions",
33 "isCorrect": false,
34 "properties": {}
35 },
36 {
37 "id": 92120,
38 "text": "One for each platform",
39 "isCorrect": false,
40 "properties": {}
41 }
42 ],
43 "question": "To distribute your application to different platforms, how many Java versions do you need to create?",
44 "textContent": "[h1]Welcome to Java![/h1]\r\n\r\n[b]Java [/b]is a high level, modern programming language designed in the early 1990s by Sun Microsystems, and currently owned by Oracle. \r\n\r\nJava is [b]Platform Independent[/b], which means that you only need to write the program once to be able to run it on a number of different platforms!\r\nJava is [b]portable[/b], [b]robust[/b], and [b]dynamic[/b], with the ability to fit the needs of virtually any type of application.\r\n[note]Java guarantees that you'll be able to [b]Write Once, Run Anywhere[/b].[/note]"
45 },
46 {
47 "id": 4185,
48 "number": 2,
49 "videoStart": 145,
50 "videoEnd": 209.5,
51 "linkedVideoID": null,
52 "type": 1,
53 "linkedQuizID": null,
54 "tip": null,
55 "hint": null,
56 "time": 0,
57 "answers": [
58 {
59 "id": 92124,
60 "text": "Java is used only in NASA's space related applications",
61 "isCorrect": false,
62 "properties": {}
63 },
64 {
65 "id": 92125,
66 "text": "Java has a huge developer community",
67 "isCorrect": true,
68 "properties": {}
69 },
70 {
71 "id": 92126,
72 "text": "Java is used only in web and mobile applications",
73 "isCorrect": false,
74 "properties": {}
75 }
76 ],
77 "question": "Which one of the following statements is true?",
78 "textContent": "[h1]Java[/h1]\r\n\r\nMore than [b]3 billion[/b] devices run Java. \r\nJava is used to develop apps for Google's [b]Android [/b]OS, various Desktop Applications, such as media players, antivirus programs, Web Applications, Enterprise Applications (i.e. banking), and many more!\r\n[note]Learn, practice, and then join the huge community of Java developers around the world![/note]"
79 }
80 ]
81 }
82 },
83 {
84 "lesson": {
85 "id": 2132,
86 "name": "The Development Cycle",
87 "type": 0,
88 "mode": 1,
89 "videoID": "Qi954__kQbo",
90 "tags": null,
91 "quizzes": [
92 {
93 "id": 4186,
94 "number": 1,
95 "videoStart": 213.5,
96 "videoEnd": 312,
97 "linkedVideoID": null,
98 "type": 2,
99 "linkedQuizID": null,
100 "tip": null,
101 "hint": null,
102 "time": 0,
103 "answers": [
104 {
105 "id": 89549,
106 "text": "java",
107 "isCorrect": false,
108 "properties": {
109 "prefix": ".",
110 "postfix": ""
111 }
112 }
113 ],
114 "question": "What is the extension for Java source code files?",
115 "textContent": "[h1]The Development Cycle[/h1]\r\n\r\nThe basic development process of any Java program includes the following stages: [img id=\"2383\" width=\"100%\"]\r\n[note]In Java, source code files have a [b].java[/b] extension.[/note]"
116 },
117 {
118 "id": 4188,
119 "number": 2,
120 "videoStart": 312,
121 "videoEnd": 411,
122 "linkedVideoID": null,
123 "type": 1,
124 "linkedQuizID": null,
125 "tip": null,
126 "hint": null,
127 "time": 0,
128 "answers": [
129 {
130 "id": 92130,
131 "text": "Using Java archive with .jar extension",
132 "isCorrect": true,
133 "properties": {}
134 },
135 {
136 "id": 92131,
137 "text": "Using Java archive with .exe extension",
138 "isCorrect": false,
139 "properties": {}
140 },
141 {
142 "id": 92132,
143 "text": "Using .java source files",
144 "isCorrect": false,
145 "properties": {}
146 }
147 ],
148 "question": "How are Java applications distributed?",
149 "textContent": "[h1]Distribution[/h1]\r\n\r\nAfter testing and fixing any existing bugs, you will be ready to [b]distribute [/b]your application to end users. \r\nTypically, most Java applications are distributed using a Java archive file, which has the [b].jar[/b] extension.\r\n[note]You will learn more about the distribution process in upcoming lessons.[/note]"
150 }
151 ]
152 }
153 },
154 {
155 "lesson": {
156 "id": 2133,
157 "name": "Installing the JDK",
158 "type": 0,
159 "mode": 1,
160 "videoID": "CWo9IuiroEE",
161 "tags": "jdk",
162 "quizzes": [
163 {
164 "id": 4189,
165 "number": 1,
166 "videoStart": 17,
167 "videoEnd": 72.7,
168 "linkedVideoID": null,
169 "type": 1,
170 "linkedQuizID": null,
171 "tip": null,
172 "hint": null,
173 "time": 0,
174 "answers": [
175 {
176 "id": 92141,
177 "text": "jdb",
178 "isCorrect": true,
179 "properties": {}
180 },
181 {
182 "id": 92142,
183 "text": "cmd",
184 "isCorrect": false,
185 "properties": {}
186 },
187 {
188 "id": 92143,
189 "text": "javac",
190 "isCorrect": true,
191 "properties": {}
192 },
193 {
194 "id": 92144,
195 "text": "jar",
196 "isCorrect": true,
197 "properties": {}
198 }
199 ],
200 "question": "Which three tools are included in the JDK?",
201 "textContent": "[h1]Java Development Kit[/h1]\r\n\r\nThe Java Development Kit ([b]JDK[/b]) is a software development environment for Java applications and applets. It includes:\r\n- The [b]J[/b]ava [b]C[/b]ompiler ([b]javac)[/b]\r\n- The [b]J[/b]ava [b]Ar[/b]chiving Tool ([b]jar)[/b]\r\n- The [b]J[/b]ava [b]D[/b]e[b]b[/b]ugging Tool ([b]jdb)[/b]\r\n- A complete [b]J[/b]ava [b]R[/b]untime [b]E[/b]nvironment [b](JRE[/b]), for running Java programs\r\n\r\nAfter installing the JDK, you will be able to run [b]javac[/b], [b]jar [/b]and [b]jdb[/b] from the Console (Command Prompt in Windows).\r\n[note]JDK is available for free at [b]www.oracle.com [/b]under [b]Java SDKs and Tools -> Java SE[/b].\r\nThe upcoming lessons will explain the installation and setup process. [/note]"
202 },
203 {
204 "id": 4451,
205 "number": 2,
206 "videoStart": 73,
207 "videoEnd": 172,
208 "linkedVideoID": null,
209 "type": 1,
210 "linkedQuizID": null,
211 "tip": null,
212 "hint": null,
213 "time": 0,
214 "answers": [
215 {
216 "id": 92148,
217 "text": "www.oracle.com",
218 "isCorrect": true,
219 "properties": {}
220 },
221 {
222 "id": 92149,
223 "text": "www.google.com",
224 "isCorrect": false,
225 "properties": {}
226 },
227 {
228 "id": 92150,
229 "text": "www.jdk.com",
230 "isCorrect": false,
231 "properties": {}
232 }
233 ],
234 "question": "You can download the JDK from...",
235 "textContent": "[h1]Installing the JDK[/h1]\r\n\r\n[h2]Step 1[/h2]\r\nGo to www.oracle.com > Downloads > Java SE.\r\n\r\n[h2]Step 2[/h2]\r\nClick the \"[b]Accept License Agreement[/b]\" checkbox. \r\nChoose your platform from the list to download the corresponding installer.[img id=\"2384\" width=\"100%\"]\r\n[note]Once you've downloaded the installer, follow the instructions for installing the JDK on your machine.[/note]"
236 },
237 {
238 "id": 4190,
239 "number": 3,
240 "videoStart": 180,
241 "videoEnd": 337,
242 "linkedVideoID": null,
243 "type": 8,
244 "linkedQuizID": null,
245 "tip": null,
246 "hint": null,
247 "time": 0,
248 "answers": [
249 {
250 "id": 106573,
251 "text": "Download the JDK from Oracle website",
252 "isCorrect": false,
253 "properties": {}
254 },
255 {
256 "id": 106574,
257 "text": "Install the JDK",
258 "isCorrect": false,
259 "properties": {}
260 },
261 {
262 "id": 106575,
263 "text": "Set the PATH environment to variable",
264 "isCorrect": false,
265 "properties": {}
266 },
267 {
268 "id": 106576,
269 "text": "Test the installation while running javac from the command line",
270 "isCorrect": false,
271 "properties": {}
272 }
273 ],
274 "question": "Rearrange the following steps in the correct order for successful Java installation.",
275 "textContent": "[h1]JDK & PATH[/h1]\r\n\r\nOn Windows, the [b]JDK [/b]will be installed by default in the directory \"C:\\Program Files\\Java\\jdk1.8.0_xx\" with the latest upgrade number indicated by xx. [b]JRE [/b]defaults to \"C:\\Program Files\\Java\\jre1.8.0_xx\". \r\nOpen the [b]JDK[/b] folder, open the bin folder, and copy the [b]path[/b], which you will need to use in the next step. [img id=\"2390\" width=\"100%\"]\r\nFor the JDK to work, you need to add its path to the PATH environment variable. To do that, right click on My Computer and go to Properties > Advanced system settings.\r\nSwitch to the Advanced tab > Environment Variables and click on [b]New [/b]button if PATH does not exist in the list. If PATH already exists, select it and click [b]Edit[/b].[img id=\"2389\" width=\"100%\"]\r\nAdd the copied path value to the variable.\r\nYou should see something like this when adding the PATH: [img id=\"2391\" width=\"100%\"]\r\n[note]If the PATH variable already exists, just add the value to it, and then separate it from the other values with a semicolon.\r\nDo NOT delete any existing entries; otherwise, some existing applications may not work properly.[/note]\r\nSave the changes. \r\nTo verify that JDK is properly installed, open the Command Prompt, type in [b]javac[/b], and press Enter. (You have to re-open the Command Prompt so the new PATH variable is recognized).\r\nIf the JDK has been successfully installed, you will see something similar to the screen below: [img id=\"2392\" width=\"100%\"]\r\n[note]The latest installers add the PATH variable to your system automatically.\r\nOur tutorial shows the installation in Windows, but the [b]javac [/b]command works on all supported platforms.[/note]"
276 }
277 ]
278 }
279 },
280 {
281 "lesson": {
282 "id": 2134,
283 "name": "The Java Virtual Machine",
284 "type": 0,
285 "mode": 1,
286 "videoID": "Qi954__kQbo",
287 "tags": "jvm",
288 "quizzes": [
289 {
290 "id": 4191,
291 "number": 1,
292 "videoStart": 411,
293 "videoEnd": 489,
294 "linkedVideoID": null,
295 "type": 1,
296 "linkedQuizID": null,
297 "tip": null,
298 "hint": null,
299 "time": 0,
300 "answers": [
301 {
302 "id": 92170,
303 "text": "... compiles source files into machine code.",
304 "isCorrect": false,
305 "properties": {}
306 },
307 {
308 "id": 92171,
309 "text": "... compiles source files into object files.",
310 "isCorrect": false,
311 "properties": {}
312 },
313 {
314 "id": 92172,
315 "text": "... translates bytecode into machine code.",
316 "isCorrect": true,
317 "properties": {}
318 }
319 ],
320 "question": "Complete the statement: The Java Virtual Machine...",
321 "textContent": "[h1]Java Virtual Machine [/h1]\r\n\r\nThe [b]Java Virtual Machine[/b] (JVM) is an execution environment for Java applications.\r\nIt interprets compiled Java binary code (called [b]bytecode[/b]) to enable a computer's processor to carry out a Java program's instructions.\r\nJava was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. The Java virtual machine makes this possible.\r\n[note]Basically, the Java compiler reads Java language source (.java) files, translates the source into Java bytecodes, and places the bytecodes into class (.class) files. \r\nThe class files can then be executed on the Java Virtual Machine (JVM).[/note]"
322 },
323 {
324 "id": 4192,
325 "number": 2,
326 "videoStart": 489.5,
327 "videoEnd": 580,
328 "linkedVideoID": null,
329 "type": 1,
330 "linkedQuizID": null,
331 "tip": null,
332 "hint": null,
333 "time": 0,
334 "answers": [
335 {
336 "id": 94899,
337 "text": "All programming languages have virtual machines",
338 "isCorrect": false,
339 "properties": {}
340 },
341 {
342 "id": 94900,
343 "text": ".class files contain abstract instructions for JVM",
344 "isCorrect": true,
345 "properties": {}
346 },
347 {
348 "id": 94901,
349 "text": "The same bytecode can be run on different JVMs",
350 "isCorrect": true,
351 "properties": {}
352 }
353 ],
354 "question": "Which two of the following statements are true?",
355 "textContent": "[h1]Java Virtual Machine[/h1]\r\n\r\nIn other programming languages, the compiler will typically produce code for a particular system. The Java compiler, however, produces code for a virtual machine. \r\n\r\n- The JVM is a main component of Java architecture, and is part of the JRE (Java Runtime Environment).\r\n- The JVM is operating system-dependent. In other words, the JVM must translate the bytecode into machine language, and the machine language depends on which operating system is being used, which makes the JVM platform-dependent, or operating system-dependent.\r\n- The JVM is responsible for allocating memory needed by the Java program.\r\n[note]Every device that has a JVM installed is able to translate and run your .class files. \r\nThis makes it possible to run the same bytecode on different platforms.[/note]"
356 }
357 ]
358 }
359 },
360 {
361 "lesson": {
362 "id": 2135,
363 "name": "Running a Java Program",
364 "type": 0,
365 "mode": 1,
366 "videoID": "5u8rFbpdvds",
367 "tags": null,
368 "quizzes": [
369 {
370 "id": 4193,
371 "number": 1,
372 "videoStart": 10,
373 "videoEnd": 123,
374 "linkedVideoID": null,
375 "type": 1,
376 "linkedQuizID": null,
377 "tip": null,
378 "hint": null,
379 "time": 0,
380 "answers": [
381 {
382 "id": 105300,
383 "text": ".txt",
384 "isCorrect": false,
385 "properties": {}
386 },
387 {
388 "id": 105301,
389 "text": ".class",
390 "isCorrect": false,
391 "properties": {}
392 },
393 {
394 "id": 105302,
395 "text": ".java",
396 "isCorrect": true,
397 "properties": {}
398 }
399 ],
400 "question": "What is the extension of Java source files?",
401 "textContent": "[h1]Your First Java Program[/h1]\r\n\r\nThe easiest way to write a simple program is by using a text editor. We will use [b]NotePad++[/b], which is available for free.\r\nUsing the text editor of your choice, create a text file with the following code, and name it ExampleProgram.[b]java[/b].[code format=\"java\" ]public class ExampleProgram {\r\n public static void main(String[ ] args) {\r\n System.out.println(\"Hello World\");\r\n }\r\n}[/code]\r\n[note]In lessons to come, our lines of code will be explained in more detail. \r\nRight now, we'll just explain how to compile and run your program.[/note]"
402 },
403 {
404 "id": 4194,
405 "number": 2,
406 "videoStart": 123,
407 "videoEnd": 341,
408 "linkedVideoID": null,
409 "type": 1,
410 "linkedQuizID": null,
411 "tip": null,
412 "hint": null,
413 "time": 0,
414 "answers": [
415 {
416 "id": 92200,
417 "text": "saving our source code",
418 "isCorrect": false,
419 "properties": {}
420 },
421 {
422 "id": 92201,
423 "text": "compiling a Java program",
424 "isCorrect": true,
425 "properties": {}
426 },
427 {
428 "id": 92202,
429 "text": "running a Java program",
430 "isCorrect": false,
431 "properties": {}
432 }
433 ],
434 "question": "We use the javac command line tool for:",
435 "textContent": "[h1]Compile[/h1]\r\n\r\nOpen a command prompt window and go to the directory in which you saved the file. \r\nWe'll say that it's C:\\sololearn.\r\n\r\nTo compile your code, type[b] javac ExampleProgram.java[/b], and press Enter. \r\nIf there are no errors in your code, the command prompt will take you to the next line and generate a bytecode file, [b]ExampleProgram.class[/b].\r\n[note]You have now generated your class file, which contains the program's bytecode.\r\nNext step is to run it![/note]"
436 },
437 {
438 "id": 4195,
439 "number": 3,
440 "videoStart": 341,
441 "videoEnd": 361.8,
442 "linkedVideoID": null,
443 "type": 2,
444 "linkedQuizID": null,
445 "tip": null,
446 "hint": null,
447 "time": 0,
448 "answers": [
449 {
450 "id": 92203,
451 "text": "java",
452 "isCorrect": false,
453 "properties": {
454 "prefix": "",
455 "postfix": " Apples"
456 }
457 }
458 ],
459 "question": "Type in the command to run a program called \"Apples\":",
460 "textContent": "[h1]Run[/h1]\r\n \r\nNow, when we have the .class file containing the bytecode, we can run it. \r\nType [b]java ExampleProgram[/b] to run your program. \r\nThis will print \"Hello World\" to the command prompt window.\r\n[note]Congratulations! You have just compiled and run your first Java program.[/note]"
461 }
462 ]
463 }
464 },
465 {
466 "lesson": {
467 "id": 2136,
468 "name": "Creating a Project with Eclipse",
469 "type": 0,
470 "mode": 1,
471 "videoID": "CE8UIbb_4iM",
472 "tags": "eclipse",
473 "quizzes": [
474 {
475 "id": 4196,
476 "number": 1,
477 "videoStart": 32.5,
478 "videoEnd": 111,
479 "linkedVideoID": null,
480 "type": 1,
481 "linkedQuizID": null,
482 "tip": null,
483 "hint": null,
484 "time": 0,
485 "answers": [
486 {
487 "id": 92207,
488 "text": "It is difficult to find errors in code with Eclipse",
489 "isCorrect": false,
490 "properties": {}
491 },
492 {
493 "id": 92208,
494 "text": "Eclipse is part of the JDK",
495 "isCorrect": false,
496 "properties": {}
497 },
498 {
499 "id": 92209,
500 "text": "Eclipse is like a text editor, but for Java",
501 "isCorrect": true,
502 "properties": {}
503 }
504 ],
505 "question": "Which of the following statements is true?",
506 "textContent": "[h1]Installing Eclipse[/h1]\r\n\r\nIn the previous lesson, we learned how to compile and run Java programs from the command prompt using JDK commands and a simple text editor.\r\nAlternatively, special editors with numerous useful features are available for compiling, running, and debugging Java applications. These editors are called [b]Integrated Development Environments[/b] (IDE).\r\n\r\n[b]Eclipse [/b]is the most popular IDE for Java. It can be obtained as a free download from [b]www.eclipse.org[/b]. For regular Java programs, choose[b] Eclipse IDE for Java Developers[/b].[b][/b]\r\n[note]Eclipse versions are available for various operating systems. Make sure that you find and download the appropriate version for your system.[/note]"
507 },
508 {
509 "id": 4198,
510 "number": 2,
511 "videoStart": 111,
512 "videoEnd": 386.5,
513 "linkedVideoID": null,
514 "type": 1,
515 "linkedQuizID": null,
516 "tip": null,
517 "hint": null,
518 "time": 0,
519 "answers": [
520 {
521 "id": 106334,
522 "text": "Console",
523 "isCorrect": true,
524 "properties": {}
525 },
526 {
527 "id": 106335,
528 "text": "Problems",
529 "isCorrect": false,
530 "properties": {}
531 },
532 {
533 "id": 106336,
534 "text": "Declaration",
535 "isCorrect": false,
536 "properties": {}
537 },
538 {
539 "id": 106337,
540 "text": "Javadoc",
541 "isCorrect": false,
542 "properties": {}
543 }
544 ],
545 "question": "In what window does Eclipse show the output?",
546 "textContent": "[h1]Using Eclipse[/h1]\r\n\r\nOnce you have downloaded the Eclipse archive, the next step is to decompress the file, which creates an unzipped Eclipse folder.\r\nSince Eclipse has no installer, there will be an executable file in the Eclipse folder (for Windows: [b]eclipse.exe[/b]). Double clicking the file launches Eclipse (this also applies to other operating systems).\r\n\r\nWhen opened for the first time, Eclipse requests that you create a [b]Workspace [/b]folder, where it will store all of your Java programs.\r\nTo create a new Eclipse project, go to [b]File->New->Java Project [/b]and enter a name for it (e.g., MyProject). \r\nYou will see your newly created project at the left/right side of your screen. Click the plus sign next to the folder to expand it, and you'll see a folder called src.\r\nRight click on the src folder, go to New, [b]select [/b]Class, name the class (e.g., MyClass), and click Finish.\r\nHere, we'll use the same example code we used in the previous lesson. [code format=\"java\" codeId=\"715\"]class MyClass {\r\n public static void main(String[ ] args) {\r\n System.out.println(\"Hello World\");\r\n }\r\n}[/code]\r\nYou will now have your project's structure, as follows: [img id=\"2861\" width=\"100%\"]\r\nTo run your code, Click the [b]Run [/b]icon on the top bar, select Run As, and select Java Application.[img id=\"2862\" width=\"100%\"]\r\nIn the [b]Console [/b]window at the bottom of the screen, you should see \"Hello World\". [img id=\"2863\" width=\"100%\"] \r\n[note]If something is wrong with your code, Eclipse automatically displays the errors in the [b]Console [/b]and[b] Problems [/b]windows.[/note]"
547 }
548 ]
549 }
550 },
551 {
552 "lesson": {
553 "id": 2137,
554 "name": "A Hello World Program",
555 "type": 0,
556 "mode": 1,
557 "videoID": "SHIT5VkNrCg",
558 "tags": null,
559 "quizzes": [
560 {
561 "id": 4199,
562 "number": 1,
563 "videoStart": 74,
564 "videoEnd": 159,
565 "linkedVideoID": null,
566 "type": 2,
567 "linkedQuizID": null,
568 "tip": null,
569 "hint": null,
570 "time": 0,
571 "answers": [
572 {
573 "id": 99484,
574 "text": "main",
575 "isCorrect": false,
576 "properties": {
577 "prefix": "",
578 "postfix": ""
579 }
580 }
581 ],
582 "question": "Which method is the starting point for all Java programs?",
583 "textContent": "[h1]Your First Java Program[/h1]\r\n\r\nNow that you've seen the \"Hello World\" program, we'll explain how it works. \r\nOnce again, here is the code: [code format=\"java\" codeId=\"716\"][b]class[/b] MyClass {\r\n public static void [b]main[/b](String[ ] args) {\r\n System.out.println(\"Hello World\");\r\n }\r\n}[/code]\r\nIn Java, every line of code that can actually run needs to be inside a [b]class[/b].\r\nIn our example, we named the class [b]MyClass[/b]. You will learn more about classes in the upcoming modules.\r\n\r\nIn Java, each application has an entry point, or a starting point, which is a method called [b]main[/b]. Along with main, the keywords [b]public [/b]and [b]static [/b]will also be explained later. \r\n[note]As a summary:\r\n- Every program in Java must have a [b]class[/b].\r\n- Every Java program starts from the [b]main[/b] method.[/note]"
584 },
585 {
586 "id": 4200,
587 "number": 2,
588 "videoStart": 159,
589 "videoEnd": 238,
590 "linkedVideoID": null,
591 "type": 2,
592 "linkedQuizID": null,
593 "tip": null,
594 "hint": null,
595 "time": 0,
596 "answers": [
597 {
598 "id": 106628,
599 "text": "hello",
600 "isCorrect": false,
601 "properties": {
602 "prefix": "void ",
603 "postfix": "()"
604 }
605 }
606 ],
607 "question": "Fill in the blank to declare a method called \"hello()\".",
608 "textContent": "[h1]The main Method[/h1]\r\n\r\nTo run our program, the [b]main [/b]method must be identical to this signature:[code format=\"java\" ][b]public static void main(String[ ] args)[/b][/code]\r\n- [b]public[/b]: anyone can access it\r\n- [b]static[/b]: method can be run without creating an instance of the class containing the main method\r\n- [b]void[/b]: method doesn't return any value\r\n- [b]main[/b]: the name of the method\r\n\r\nFor example, the following code declares a method called [b]test[/b], which does not return anything and has no parameters:[code format=\"java\" ]void test()[/code]\r\n[note]The method's parameters are declared inside the parentheses that follow the name of the method. \r\nFor [b]main[/b], it's an array of strings called [b]args[/b]. We will use it in our next lesson, so don't worry if you don't understand it all now.[/note]"
609 },
610 {
611 "id": 4201,
612 "number": 3,
613 "videoStart": 238,
614 "videoEnd": 377.5,
615 "linkedVideoID": null,
616 "type": 1,
617 "linkedQuizID": null,
618 "tip": null,
619 "hint": null,
620 "time": 0,
621 "answers": [
622 {
623 "id": 95316,
624 "text": "System.printText()",
625 "isCorrect": false,
626 "properties": {}
627 },
628 {
629 "id": 95317,
630 "text": "System.out()",
631 "isCorrect": false,
632 "properties": {}
633 },
634 {
635 "id": 95318,
636 "text": "System.out.println()",
637 "isCorrect": true,
638 "properties": {}
639 },
640 {
641 "id": 95319,
642 "text": "out.writeText() ",
643 "isCorrect": false,
644 "properties": {}
645 }
646 ],
647 "question": "Which method prints text in a Java program?",
648 "textContent": "[h1]System.out.println()[/h1]\r\n\r\nNext is the body of the [b]main [/b]method, enclosed in curly braces: [code format=\"java\"]{\r\n System.out.println(\"Hello World!\");\r\n}[/code]\r\nThe [b]println [/b]method prints a line of text to the screen.\r\nThe [b]System [/b]class and its [b]out [/b]stream are used to access the [b]println [/b]method.\r\n[note]In classes, methods, and other flow-control structures code is always enclosed in curly braces { }.[/note]"
649 },
650 {
651 "id": 4202,
652 "number": 4,
653 "videoStart": 377,
654 "videoEnd": 418.5,
655 "linkedVideoID": null,
656 "type": 3,
657 "linkedQuizID": null,
658 "tip": null,
659 "hint": null,
660 "time": 0,
661 "answers": [
662 {
663 "id": 105648,
664 "text": "class",
665 "isCorrect": false,
666 "properties": {
667 "prefix": "",
668 "postfix": ""
669 }
670 },
671 {
672 "id": 105649,
673 "text": "main",
674 "isCorrect": false,
675 "properties": {
676 "prefix": "",
677 "postfix": ""
678 }
679 }
680 ],
681 "question": "Fill in the blanks to create a valid Java program.\r\n[!raw!]\r\n{0} Apples {\r\n public static void {1}(String[ ]args) {\r\n System.out.println(\"Hello, World!\");\r\n }\r\n}",
682 "textContent": "[h1]Semicolons in Java[/h1]\r\n\r\nYou can pass a different text as the parameter to the [b]println [/b]method to print it. [code format=\"java\" codeId=\"717\"]class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]System.out.println(\"I am learning Java\");[/b]\r\n }\r\n}[/code]\r\nIn Java, each code statement must end with a [b]semicolon[/b]. \r\n[note]Remember: do not use [b]semicolons [/b]after method and class declarations that follow with the body defined using the curly braces.[/note]"
683 }
684 ]
685 }
686 },
687 {
688 "lesson": {
689 "id": 2138,
690 "name": "Java Comments",
691 "type": 0,
692 "mode": 1,
693 "videoID": "bTbDkhFy3e4",
694 "tags": "comments",
695 "quizzes": [
696 {
697 "id": 4203,
698 "number": 1,
699 "videoStart": 12,
700 "videoEnd": 64.5,
701 "linkedVideoID": null,
702 "type": 1,
703 "linkedQuizID": null,
704 "tip": null,
705 "hint": null,
706 "time": 0,
707 "answers": [
708 {
709 "id": 95322,
710 "text": "** characters at the beginning of the line",
711 "isCorrect": false,
712 "properties": {}
713 },
714 {
715 "id": 95323,
716 "text": "*/ characters at the beginning of the line",
717 "isCorrect": false,
718 "properties": {}
719 },
720 {
721 "id": 95324,
722 "text": "// characters at the end of the line",
723 "isCorrect": false,
724 "properties": {}
725 },
726 {
727 "id": 95325,
728 "text": "// characters at the beginning of the line ",
729 "isCorrect": true,
730 "properties": {}
731 }
732 ],
733 "question": "Single-line comments are created using:",
734 "textContent": "[h1]Comments[/h1]\r\n\r\nThe purpose of including comments in your code is to explain what the code is doing.\r\nJava supports both single and multi-line comments. All characters that appear within a comment are ignored by the Java compiler.\r\n\r\nA [b]single-line[/b] comment starts with [b]two forward slashes [/b]and continues until it reaches the end of the line. \r\nFor example:[code format=\"java\"][b]// this is a single-line comment[/b]\r\nx = 5; [b]// a single-line comment after code[/b][/code]\r\n[note]Adding comments as you write code is a good practice, because they provide clarification and understanding when you need to refer back to it, as well as for others who might need to read it.[/note]"
735 },
736 {
737 "id": 4205,
738 "number": 2,
739 "videoStart": 65,
740 "videoEnd": 106.5,
741 "linkedVideoID": null,
742 "type": 3,
743 "linkedQuizID": null,
744 "tip": null,
745 "hint": null,
746 "time": 0,
747 "answers": [
748 {
749 "id": 95326,
750 "text": "/*",
751 "isCorrect": false,
752 "properties": {
753 "prefix": "",
754 "postfix": ""
755 }
756 },
757 {
758 "id": 95327,
759 "text": "*/",
760 "isCorrect": false,
761 "properties": {
762 "prefix": "",
763 "postfix": ""
764 }
765 }
766 ],
767 "question": "Make this text a multi-line comment.\r\n[!raw!]\r\n{0} some\r\n* comment text\r\n{1}",
768 "textContent": "[h1]Multi-Line Comments[/h1]\r\n\r\nJava also supports comments that span multiple lines.\r\nYou start this type of comment with a forward slash followed by an asterisk, and end it with an asterisk followed by a forward slash. \r\nFor example: [code format=\"java\"]/* This is also a\r\n comment spanning\r\n multiple lines */[/code]\r\nNote that Java does not support nested multi-line comments. \r\nHowever, you can nest single-line comments within multi-line comments. [code format=\"java\"]/* This is a single-line comment:\r\n\r\n // a single-line comment\r\n\r\n */[/code]"
769 },
770 {
771 "id": 4206,
772 "number": 3,
773 "videoStart": 107,
774 "videoEnd": 142.6,
775 "linkedVideoID": null,
776 "type": 1,
777 "linkedQuizID": null,
778 "tip": null,
779 "hint": null,
780 "time": 0,
781 "answers": [
782 {
783 "id": 95328,
784 "text": "// characters in the beginning of the line.",
785 "isCorrect": false,
786 "properties": {}
787 },
788 {
789 "id": 95329,
790 "text": "// and */ characters to wrap a comment.",
791 "isCorrect": false,
792 "properties": {}
793 },
794 {
795 "id": 95330,
796 "text": "/* and */ characters to wrap a comment.",
797 "isCorrect": false,
798 "properties": {}
799 },
800 {
801 "id": 95331,
802 "text": "/** and */ characters to wrap a comment.",
803 "isCorrect": true,
804 "properties": {}
805 }
806 ],
807 "question": "You can add a Java doc style comment by using:",
808 "textContent": "[h1]Documentation Comments[/h1]\r\n\r\n[b]Documentation comments[/b] are special comments that have the appearance of multi-line comments, with the difference being that they generate external documentation of your source code. These begin with a forward slash followed by two asterisks, and end with an asterisk followed by a forward slash. \r\nFor example:[code format=\"java\"]/** This is a documentation comment */\r\n\r\n/** This is also a\r\n documentation comment */[/code]\r\n[b]Javadoc [/b]is a tool which comes with JDK and it is used for generating Java code documentation in HTML format from Java source code which has required documentation in a predefined format.\r\n\r\nWhen a documentation comment begins with more than two asterisks, Javadoc assumes that you want to create a \"box\" around the comment in the source code. It simply ignores the extra asterisks.\r\nFor example: [code format=\"java\"]/**********************\r\n\r\nThis is the start of a method\r\n\r\n***********************/[/code]\r\n[note]This will retain just the text \"This is the start of a method\" for the documentation.[/note]"
809 }
810 ]
811 }
812 },
813 {
814 "lesson": {
815 "id": 2139,
816 "name": "Variables",
817 "type": 0,
818 "mode": 1,
819 "videoID": "C34yzarygX4",
820 "tags": "variables",
821 "quizzes": [
822 {
823 "id": 4207,
824 "number": 1,
825 "videoStart": 106,
826 "videoEnd": 176,
827 "linkedVideoID": null,
828 "type": 1,
829 "linkedQuizID": null,
830 "tip": null,
831 "hint": null,
832 "time": 0,
833 "answers": [
834 {
835 "id": 95332,
836 "text": "String",
837 "isCorrect": true,
838 "properties": {}
839 },
840 {
841 "id": 95333,
842 "text": "double",
843 "isCorrect": false,
844 "properties": {}
845 },
846 {
847 "id": 95334,
848 "text": "int",
849 "isCorrect": false,
850 "properties": {}
851 }
852 ],
853 "question": "Which variable type would you use for a city name?",
854 "textContent": "[h1]Variables[/h1]\r\n\r\n[b]Variables [/b]store data for processing.\r\nA variable is given a name (or [b]identifier[/b]), such as area, age, height, and the like. The name uniquely identifies each variable, assigning a value to the variable and retrieving the value stored.\r\n\r\nVariables have [b]types[/b]. Some examples:\r\n- [b]int[/b]: for integers (whole numbers) such as 123 and -456\r\n- [b]double[/b]: for floating-point or real numbers with optional decimal points and fractional parts in fixed or scientific notations, such as 3.1416, -55.66.\r\n- [b]String[/b]: for texts such as \"Hello\" or \"Good Morning!\". Text strings are enclosed within double quotes.\r\n\r\nYou can declare a variable of a type and assign it a value. Example:[code format=\"java\"]String name = \"David\";[/code]\r\nThis creates a variable called [b]name [/b]of type [b]String[/b], and assigns it the value \"David\".\r\n[note]It is important to note that a variable is associated with a type, and is only capable of storing values of that particular type. For example, an [b]int [/b]variable can store integer values, such as 123; but it cannot store real numbers, such as 12.34, or texts, such as \"Hello\".[/note]"
855 },
856 {
857 "id": 4208,
858 "number": 2,
859 "videoStart": 176,
860 "videoEnd": 232,
861 "linkedVideoID": null,
862 "type": 6,
863 "linkedQuizID": null,
864 "tip": null,
865 "hint": null,
866 "time": 0,
867 "answers": [
868 {
869 "id": 100217,
870 "text": "String",
871 "isCorrect": true,
872 "properties": {}
873 },
874 {
875 "id": 100218,
876 "text": "int",
877 "isCorrect": true,
878 "properties": {}
879 },
880 {
881 "id": 100219,
882 "text": "double",
883 "isCorrect": true,
884 "properties": {}
885 },
886 {
887 "id": 100220,
888 "text": "true",
889 "isCorrect": false,
890 "properties": {}
891 },
892 {
893 "id": 100221,
894 "text": "class",
895 "isCorrect": false,
896 "properties": {}
897 },
898 {
899 "id": 100222,
900 "text": "void",
901 "isCorrect": false,
902 "properties": {}
903 }
904 ],
905 "question": "Fill in the blanks to have a valid Java program.\r\n[!raw!]\r\nclass Apples {\r\n public static void main(String[ ]args) {\r\n {0} name = \"John\";\r\n {1} age = 24;\r\n {2} height = 189.87;\r\n }\r\n}",
906 "textContent": "[h1]Variables[/h1]\r\n\r\nExamples of variable declarations:[code format=\"java\" codeId=\"718\"]class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]String[/b] name =\"David\";\r\n [b]int[/b] age = 42;\r\n [b]double [/b]score =15.9;\r\n [b]char[/b] group = 'Z';\r\n }\r\n}[/code]\r\n[b]char [/b]stands for character and holds a single character.\r\n\r\nAnother type is the [b]Boolean [/b]type, which has only two possible values: [b]true [/b]and [b]false[/b].\r\nThis data type is used for simple flags that track true/false conditions.\r\n[b]For example:[/b] [code format=\"java\" ][b]boolean [/b]online = true;[/code]\r\n[note]You can use a comma-separated list to declare more than one variable of the specified type. Example: int a = 42, b = 11;[/note]"
907 }
908 ]
909 }
910 },
911 {
912 "lesson": {
913 "id": 2140,
914 "name": "Primitive Operators",
915 "type": 0,
916 "mode": 1,
917 "videoID": "8ZaTSedtf9M",
918 "tags": "operators",
919 "quizzes": [
920 {
921 "id": 4452,
922 "number": 1,
923 "videoStart": 61,
924 "videoEnd": 87,
925 "linkedVideoID": null,
926 "type": 3,
927 "linkedQuizID": null,
928 "tip": null,
929 "hint": null,
930 "time": 0,
931 "answers": [
932 {
933 "id": 95341,
934 "text": "int",
935 "isCorrect": false,
936 "properties": {
937 "prefix": "",
938 "postfix": ""
939 }
940 },
941 {
942 "id": 95342,
943 "text": "5",
944 "isCorrect": false,
945 "properties": {
946 "prefix": "",
947 "postfix": ""
948 }
949 }
950 ],
951 "question": "Fill in the blank to declare an integer variable and set its value to 5.\r\n[!raw!]\r\n{0} var = {1};",
952 "textContent": "[h1]The Math Operators[/h1]\r\n\r\nJava provides a rich set of operators to use in manipulating variables. A value used on either side of an operator is called an [b]operand[/b]. \r\nFor example, in the expression below, the numbers 6 and 3 are operands of the plus operator: [code format=\"java\"]int x = 6 + 3;[/code]\r\nJava arithmetic operators: \r\n+ [b]addition[/b]\r\n- [b]subtraction[/b]\r\n* [b]multiplication[/b]\r\n/ [b]division[/b]\r\n% [b]modulo[/b]\r\n[note]Arithmetic operators are used in mathematical expressions in the same way that they are used in algebraic equations.[/note]"
953 },
954 {
955 "id": 4209,
956 "number": 2,
957 "videoStart": 96,
958 "videoEnd": 134.5,
959 "linkedVideoID": null,
960 "type": 3,
961 "linkedQuizID": null,
962 "tip": null,
963 "hint": null,
964 "time": 0,
965 "answers": [
966 {
967 "id": 95343,
968 "text": "+",
969 "isCorrect": false,
970 "properties": {
971 "prefix": "",
972 "postfix": ""
973 }
974 },
975 {
976 "id": 95344,
977 "text": "y",
978 "isCorrect": false,
979 "properties": {
980 "prefix": "",
981 "postfix": ""
982 }
983 },
984 {
985 "id": 95345,
986 "text": "result",
987 "isCorrect": false,
988 "properties": {
989 "prefix": "",
990 "postfix": ""
991 }
992 }
993 ],
994 "question": "Fill in the blanks to print the sum of the two variables.\r\n[!raw!]\r\nint x = 2; int y = 4;\r\nint result = x {0} {1};\r\nSystem.out.println({2});",
995 "textContent": "[h1]Addition[/h1]\r\n\r\nThe + operator adds together two values, such as two constants, a constant and a variable, or a variable and a variable. Here are a few examples of addition: [code format=\"java\"]int sum1 = 50 + 10; \r\nint sum2 = sum1 + 66; \r\nint sum3 = sum2 + sum2;[/code]\r\n[h2]Subtraction[/h2]\r\nThe - operator subtracts one value from another.[code format=\"java\"]int sum1 = 1000 - 10;\r\nint sum2 = sum1 - 5;\r\nint sum3 = sum1 - sum2;[/code]"
996 },
997 {
998 "id": 4210,
999 "number": 3,
1000 "videoStart": 135,
1001 "videoEnd": 211,
1002 "linkedVideoID": null,
1003 "type": 2,
1004 "linkedQuizID": null,
1005 "tip": null,
1006 "hint": null,
1007 "time": 0,
1008 "answers": [
1009 {
1010 "id": 95346,
1011 "text": "3",
1012 "isCorrect": false,
1013 "properties": {
1014 "prefix": "",
1015 "postfix": ""
1016 }
1017 }
1018 ],
1019 "question": "What is the result of the following code?\r\nint x = 15; int y = 4;\r\nint result = x / y;\r\nSystem.out.println(result);",
1020 "textContent": "[h1]Multiplication[/h1]\r\n\r\nThe * operator multiplies two values.[code format=\"java\"]int sum1 = 1000 * 2;\r\nint sum2 = sum1 * 10;\r\nint sum3 = sum1 * sum2;[/code]\r\n[h2]Division[/h2]\r\nThe / operator divides one value by another.[code format=\"java\"]int sum1 = 1000 / 5;\r\nint sum2 = sum1 / 2;\r\nint sum3 = sum1 / sum2;[/code]\r\n[note]In the example above, the result of the division equation will be a whole number, as [b]int [/b]is used as the data type. You can use [b]double [/b]to retrieve a value with a decimal point.[/note]"
1021 },
1022 {
1023 "id": 4211,
1024 "number": 4,
1025 "videoStart": 211,
1026 "videoEnd": 266.7,
1027 "linkedVideoID": null,
1028 "type": 2,
1029 "linkedQuizID": null,
1030 "tip": null,
1031 "hint": null,
1032 "time": 0,
1033 "answers": [
1034 {
1035 "id": 99501,
1036 "text": "3",
1037 "isCorrect": false,
1038 "properties": {
1039 "prefix": "",
1040 "postfix": ""
1041 }
1042 }
1043 ],
1044 "question": "What value is stored in the result variable?\r\nint x = 8, y = 5;\r\nint result = x % y;",
1045 "textContent": "[h1]Modulo[/h1]\r\n\r\nThe [b]modulo [/b](or remainder) math operation performs an integer division of one value by another, and returns the remainder of that division. \r\nThe operator for the modulo operation is the percentage (%) character.\r\nExample:[code format=\"java\" codeId=\"719\"]int value = 23;\r\nint res = value % 6; // res is 5[/code]\r\n[note]Dividing 23 by 6 returns a quotient of 3, with a remainder of 5. Thus, the value of 5 is assigned to the [b]res [/b]variable.[/note]"
1046 }
1047 ]
1048 }
1049 },
1050 {
1051 "lesson": {
1052 "id": 2141,
1053 "name": "Increment & Decrement",
1054 "type": 0,
1055 "mode": 1,
1056 "videoID": "ydcTx6idTs0",
1057 "tags": "operators",
1058 "quizzes": [
1059 {
1060 "id": 4212,
1061 "number": 1,
1062 "videoStart": 4,
1063 "videoEnd": 83.5,
1064 "linkedVideoID": null,
1065 "type": 3,
1066 "linkedQuizID": null,
1067 "tip": null,
1068 "hint": null,
1069 "time": 0,
1070 "answers": [
1071 {
1072 "id": 99494,
1073 "text": "++",
1074 "isCorrect": false,
1075 "properties": {
1076 "prefix": "",
1077 "postfix": ""
1078 }
1079 }
1080 ],
1081 "question": "Fill in the blanks to print 11.\r\n[!raw!]\r\nint a = 10;\r\n{0}a;\r\nSystem.out.println(a);",
1082 "textContent": "[h1]Increment Operators[/h1]\r\n\r\n[b][/b]An [b]increment [/b]or [b]decrement [/b]operator provides a more convenient and compact way to increase or decrease the value of a variable by [b]one[/b]. \r\nFor instance, the statement [b]x=x+1;[/b] can be simplified to [b]++x;[/b] \r\nExample: [code format=\"java\" codeId=\"720\"]int test = 5;\r\n++test; // test is now 6[/code]\r\nThe [b]decrement [/b]operator (--) is used to decrease the value of a variable by one. [code format=\"java\" codeId=\"721\"]int test = 5;\r\n--test; // test is now 4[/code]"
1083 },
1084 {
1085 "id": 4213,
1086 "number": 2,
1087 "videoStart": 83.5,
1088 "videoEnd": 167.5,
1089 "linkedVideoID": null,
1090 "type": 2,
1091 "linkedQuizID": null,
1092 "tip": null,
1093 "hint": null,
1094 "time": 0,
1095 "answers": [
1096 {
1097 "id": 99495,
1098 "text": "14",
1099 "isCorrect": false,
1100 "properties": {
1101 "prefix": "",
1102 "postfix": ""
1103 }
1104 }
1105 ],
1106 "question": "What is the output of the following code?\r\nint x = 14; \r\nSystem.out.println(x++);",
1107 "textContent": "[h1]Prefix & Postfix[/h1]\r\n\r\nTwo forms, [b]prefix [/b]and [b]postfix[/b], may be used with both the increment and decrement operators.\r\nWith prefix form, the operator appears before the operand, while in postfix form, the operator appears after the operand. Below is an explanation of how the two forms work:\r\n[b]Prefix[/b]: Increments the variable's value and uses the new value in the expression. \r\nExample:[code format=\"java\" codeId=\"722\"]int x = 34;\r\nint y = [b]++x[/b]; // y is 35[/code]\r\nThe value of x is first incremented to 35, and is then assigned to y, so the values of both x and y are now 35.\r\n[b]Postfix[/b]: The variable's value is first used in the expression and is then increased. \r\nExample:[code format=\"java\" codeId=\"723\"]int x = 34;\r\nint y = [b]x++[/b]; // y is 34[/code]\r\nx is first assigned to y, and is then incremented by one. Therefore, x becomes 35, while y is assigned the value of 34.\r\n[note]The same applies to the [b]decrement [/b]operator.[/note]"
1108 },
1109 {
1110 "id": 4214,
1111 "number": 3,
1112 "videoStart": 168,
1113 "videoEnd": 297.5,
1114 "linkedVideoID": null,
1115 "type": 3,
1116 "linkedQuizID": null,
1117 "tip": null,
1118 "hint": null,
1119 "time": 0,
1120 "answers": [
1121 {
1122 "id": 99496,
1123 "text": "x",
1124 "isCorrect": false,
1125 "properties": {
1126 "prefix": "",
1127 "postfix": ""
1128 }
1129 },
1130 {
1131 "id": 99497,
1132 "text": "y",
1133 "isCorrect": false,
1134 "properties": {
1135 "prefix": "",
1136 "postfix": ""
1137 }
1138 }
1139 ],
1140 "question": "Fill in the missing parts in the following code to print 13.\r\n[!raw!]\r\nint x = 25; int y;\r\ny = {0} - 12;\r\nSystem.out.println({1});",
1141 "textContent": "[h1]Assignment Operators [/h1]\r\n\r\nYou are already familiar with the [b]assignment [/b]operator (=), which assigns a value to a variable. [code format=\"java\" ]int value = 5;[/code]\r\nThis assigned the value 5 to a variable called [b]value [/b]of type [b]int[/b].\r\n\r\nJava provides a number of assignment operators to make it easier to write code.\r\n[b]Addition and assignment (+=):[/b] [code format=\"java\" codeId=\"724\"]int num1 = 4;\r\nint num2 = 8;\r\n[b]num2 += num1[/b]; // num2 = num2 + num1;\r\n\r\n// num2 is 12 and num1 is 4[/code]\r\n[b]Subtraction and assignment (-=):[/b] [code format=\"java\" codeId=\"725\"]int num1 = 4;\r\nint num2 = 8;\r\n[b]num2 -= num1;[/b] // num2 = num2 - num1;\r\n\r\n// num2 is 4 and num1 is 4[/code]\r\n[note]Similarly, Java supports multiplication and assignment (*=), division and assignment (/=), and remainder and assignment (%=).[/note]"
1142 }
1143 ]
1144 }
1145 },
1146 {
1147 "lesson": {
1148 "id": 2142,
1149 "name": "Strings",
1150 "type": 0,
1151 "mode": 1,
1152 "videoID": "BGU7TS8NBO0",
1153 "tags": "strings",
1154 "quizzes": [
1155 {
1156 "id": 4216,
1157 "number": 1,
1158 "videoStart": 70,
1159 "videoEnd": 173.5,
1160 "linkedVideoID": null,
1161 "type": 6,
1162 "linkedQuizID": null,
1163 "tip": null,
1164 "hint": null,
1165 "time": 0,
1166 "answers": [
1167 {
1168 "id": 95353,
1169 "text": "String",
1170 "isCorrect": true,
1171 "properties": {}
1172 },
1173 {
1174 "id": 95354,
1175 "text": "var",
1176 "isCorrect": true,
1177 "properties": {}
1178 },
1179 {
1180 "id": 95355,
1181 "text": "char",
1182 "isCorrect": false,
1183 "properties": {}
1184 },
1185 {
1186 "id": 95356,
1187 "text": "print",
1188 "isCorrect": false,
1189 "properties": {}
1190 },
1191 {
1192 "id": 95357,
1193 "text": "Hello",
1194 "isCorrect": false,
1195 "properties": {}
1196 }
1197 ],
1198 "question": "Fill in the blanks to print \"Hello\".\r\n[!raw!]\r\n{0} var;\r\nvar = \"Hello\";\r\nSystem.out.println({1});",
1199 "textContent": "[h1]Strings[/h1]\r\n\r\nA [b]String [/b]is an object that represents a sequence of characters.\r\n For example, \"Hello\" is a string of 5 characters.\r\n\r\nFor example:[code format=\"java\"][b]String [/b]s = \"SoloLearn\"; [/code]"
1200 },
1201 {
1202 "id": 4215,
1203 "number": 2,
1204 "videoStart": 174,
1205 "videoEnd": 252,
1206 "linkedVideoID": null,
1207 "type": 1,
1208 "linkedQuizID": null,
1209 "tip": null,
1210 "hint": null,
1211 "time": 0,
1212 "answers": [
1213 {
1214 "id": 99498,
1215 "text": "'k' is a char",
1216 "isCorrect": true,
1217 "properties": {}
1218 },
1219 {
1220 "id": 99499,
1221 "text": "\"hello\" is a char",
1222 "isCorrect": false,
1223 "properties": {}
1224 },
1225 {
1226 "id": 99500,
1227 "text": "char is used to store numeric values",
1228 "isCorrect": false,
1229 "properties": {}
1230 }
1231 ],
1232 "question": "Which statement in regard to the char data type is true?",
1233 "textContent": "[h1]String Concatenation[/h1]\r\n\r\nThe + (plus) operator between strings adds them together to make a new string. This process is called [b]concatenation[/b].\r\nThe resulted string is the first string put together with the second string.\r\nFor example: [code format=\"java\" codeId=\"726\"][b]String[/b] firstName, lastName;\r\nfirstName = \"David\";\r\nlastName = \"Williams\";\r\n\r\nSystem.out.println(\"My name is \" + firstName +\" \"+lastName);\r\n \r\n// Prints: My name is David Williams[/code]\r\n[note]The [b]char [/b]data type represents a single character. [/note]"
1234 }
1235 ]
1236 }
1237 },
1238 {
1239 "lesson": {
1240 "id": 2220,
1241 "name": "Getting User Input",
1242 "type": 0,
1243 "mode": 1,
1244 "videoID": "5DdacOkrTgo",
1245 "tags": "input",
1246 "quizzes": [
1247 {
1248 "id": 4423,
1249 "number": 1,
1250 "videoStart": 7,
1251 "videoEnd": 287,
1252 "linkedVideoID": null,
1253 "type": 6,
1254 "linkedQuizID": null,
1255 "tip": null,
1256 "hint": null,
1257 "time": 0,
1258 "answers": [
1259 {
1260 "id": 104702,
1261 "text": "Scanner",
1262 "isCorrect": true,
1263 "properties": {}
1264 },
1265 {
1266 "id": 104703,
1267 "text": "nextLine",
1268 "isCorrect": true,
1269 "properties": {}
1270 },
1271 {
1272 "id": 104704,
1273 "text": "Input",
1274 "isCorrect": false,
1275 "properties": {}
1276 },
1277 {
1278 "id": 104705,
1279 "text": "getLine",
1280 "isCorrect": false,
1281 "properties": {}
1282 },
1283 {
1284 "id": 104706,
1285 "text": "nextGet",
1286 "isCorrect": false,
1287 "properties": {}
1288 }
1289 ],
1290 "question": "Fill in the blanks to get user input.\r\n[!raw!]\r\nimport java.util.Scanner;\r\nclass test {\r\n public static void main(String[ ] args) {\r\n {0} sc = new Scanner(System.in);\r\n String st = sc.{1}();\r\n }\r\n}",
1291 "textContent": "[h1]Getting User Input [/h1]\r\n\r\nWhile Java provides many different methods for getting user input, the [b]Scanner [/b]object is the most common, and perhaps the easiest to implement. Import the [b]Scanner [/b]class to use the [b]Scanner [/b]object, as seen here:[code format=\"java\" ][b]import [/b]java.util.Scanner; [/code]\r\nIn order to use the [b]Scanner [/b]class, create an instance of the class by using the following syntax:[code format=\"java\" ][b]Scanner [/b]myVar = new [b]Scanner[/b](System.in);[/code]\r\nYou can now read in different kinds of input data that the user enters. \r\nHere are some methods that are available through the Scanner class:\r\nRead a byte - nextByte()\r\nRead a short - nextShort()\r\nRead an int - nextInt()\r\nRead a long - nextLong()\r\nRead a float - nextFloat()\r\nRead a double - nextDouble()\r\nRead a boolean - nextBoolean()\r\nRead a complete line - nextLine()\r\nRead a word - next()\r\n\r\nExample of a program used to get user input: [code format=\"java\" codeId=\"935\"]import java.util.Scanner;\r\n\r\nclass MyClass {\r\n public static void main(String[ ] args) {\r\n Scanner myVar = new Scanner(System.in);\r\n System.out.println(myVar.nextLine()); \r\n }\r\n}[/code]\r\n[note]This will wait for the user to input something and print that input.\r\nThe code might seem complex, but you will understand it all in the upcoming lessons.[/note]"
1292 }
1293 ]
1294 }
1295 },
1296 {
1297 "lesson": {
1298 "id": 2207,
1299 "name": "Module 1 Quiz",
1300 "type": 1,
1301 "mode": 0,
1302 "videoID": null,
1303 "tags": null,
1304 "quizzes": [
1305 {
1306 "id": 4386,
1307 "number": 1,
1308 "videoStart": 0,
1309 "videoEnd": 0,
1310 "linkedVideoID": null,
1311 "type": 3,
1312 "linkedQuizID": null,
1313 "tip": null,
1314 "hint": null,
1315 "time": 0,
1316 "answers": [
1317 {
1318 "id": 29148,
1319 "text": "int",
1320 "isCorrect": false,
1321 "properties": {
1322 "prefix": "",
1323 "postfix": ""
1324 }
1325 },
1326 {
1327 "id": 29149,
1328 "text": "+",
1329 "isCorrect": false,
1330 "properties": {
1331 "prefix": "",
1332 "postfix": ""
1333 }
1334 },
1335 {
1336 "id": 29150,
1337 "text": "sum",
1338 "isCorrect": false,
1339 "properties": {
1340 "prefix": "",
1341 "postfix": ""
1342 }
1343 }
1344 ],
1345 "question": "Please type in a code to declare two variables of type int and print their sum.\r\n[!raw!]\r\nint x = 4;\r\n{0} y = 7;\r\nint sum = x {1} y;\r\nSystem.out.println({2});",
1346 "textContent": null
1347 },
1348 {
1349 "id": 4387,
1350 "number": 2,
1351 "videoStart": 0,
1352 "videoEnd": 0,
1353 "linkedVideoID": null,
1354 "type": 1,
1355 "linkedQuizID": null,
1356 "tip": null,
1357 "hint": null,
1358 "time": 0,
1359 "answers": [
1360 {
1361 "id": 29151,
1362 "text": "...there must be a method called \"main\".",
1363 "isCorrect": true,
1364 "properties": {}
1365 },
1366 {
1367 "id": 29152,
1368 "text": "...there must be at least two variables declared.",
1369 "isCorrect": false,
1370 "properties": {}
1371 },
1372 {
1373 "id": 29153,
1374 "text": "...all of the variables must be integers.",
1375 "isCorrect": false,
1376 "properties": {}
1377 }
1378 ],
1379 "question": "In every Java program...",
1380 "textContent": null
1381 },
1382 {
1383 "id": 4388,
1384 "number": 3,
1385 "videoStart": 0,
1386 "videoEnd": 0,
1387 "linkedVideoID": null,
1388 "type": 6,
1389 "linkedQuizID": null,
1390 "tip": null,
1391 "hint": null,
1392 "time": 0,
1393 "answers": [
1394 {
1395 "id": 29020,
1396 "text": "String",
1397 "isCorrect": true,
1398 "properties": {}
1399 },
1400 {
1401 "id": 29021,
1402 "text": "System",
1403 "isCorrect": true,
1404 "properties": {}
1405 },
1406 {
1407 "id": 29022,
1408 "text": "Java",
1409 "isCorrect": false,
1410 "properties": {}
1411 },
1412 {
1413 "id": 29023,
1414 "text": "name",
1415 "isCorrect": true,
1416 "properties": {}
1417 },
1418 {
1419 "id": 29024,
1420 "text": "int",
1421 "isCorrect": false,
1422 "properties": {}
1423 }
1424 ],
1425 "question": "Fill in the blanks to output the name:\r\n[!raw!]\r\n{0} name;\r\nname = \"David\";\r\n{1}.out.println({2});",
1426 "textContent": null
1427 }
1428 ]
1429 }
1430 },
1431 {
1432 "lesson": {
1433 "id": 2204,
1434 "name": "Nested if Statements",
1435 "type": 0,
1436 "mode": 1,
1437 "videoID": "Y4xFGCyt1ww",
1438 "tags": "if-statements",
1439 "quizzes": [
1440 {
1441 "id": 4382,
1442 "number": 1,
1443 "videoStart": 109,
1444 "videoEnd": 268,
1445 "linkedVideoID": null,
1446 "type": 3,
1447 "linkedQuizID": null,
1448 "tip": null,
1449 "hint": null,
1450 "time": 0,
1451 "answers": [
1452 {
1453 "id": 99507,
1454 "text": "if",
1455 "isCorrect": false,
1456 "properties": {
1457 "prefix": "",
1458 "postfix": ""
1459 }
1460 },
1461 {
1462 "id": 99508,
1463 "text": "out",
1464 "isCorrect": false,
1465 "properties": {
1466 "prefix": "",
1467 "postfix": ""
1468 }
1469 }
1470 ],
1471 "question": "Please fill in the missing parts of the nested if statement to print \"it works!\" to the screen.\r\n[!raw!]\r\nint x = 37;\r\nif (x > 22) {\r\n {0} (x > 31) {\r\n System.{1}.println(\"it works!\");\r\n }\r\n}",
1472 "textContent": "[h1]Nested if Statements[/h1]\r\n\r\nYou can use one [b]if-else[/b] statement inside another[b] if[/b] or [b]else [/b]statement.\r\n[b]For example:[/b] [code format=\"java\" codeId=\"729\"]int age = 25;\r\nif(age > 0) {\r\n if(age > 16) {\r\n System.out.println(\"Welcome!\");\r\n } else {\r\n System.out.println(\"Too Young\");\r\n }\r\n} else {\r\n System.out.println(\"Error\");\r\n}\r\n//Outputs \"Welcome!\"[/code]\r\n[note]You can nest as many [b]if-else[/b] statements as you want.[/note]"
1473 }
1474 ]
1475 }
1476 },
1477 {
1478 "lesson": {
1479 "id": 2205,
1480 "name": "else if Statement",
1481 "type": 0,
1482 "mode": 1,
1483 "videoID": "C0YRYVn_BeI",
1484 "tags": "if-statements",
1485 "quizzes": [
1486 {
1487 "id": 4383,
1488 "number": 1,
1489 "videoStart": 66,
1490 "videoEnd": 213,
1491 "linkedVideoID": null,
1492 "type": 1,
1493 "linkedQuizID": null,
1494 "tip": null,
1495 "hint": null,
1496 "time": 0,
1497 "answers": [
1498 {
1499 "id": 99509,
1500 "text": "None",
1501 "isCorrect": false,
1502 "properties": {}
1503 },
1504 {
1505 "id": 99510,
1506 "text": "Only two",
1507 "isCorrect": false,
1508 "properties": {}
1509 },
1510 {
1511 "id": 99511,
1512 "text": "As many as you want",
1513 "isCorrect": true,
1514 "properties": {}
1515 }
1516 ],
1517 "question": "An if statement can contain how many else if statements?",
1518 "textContent": "[h1]else if Statements [/h1]\r\n\r\nInstead of using nested [b]if-else[/b] statements, you can use the [b]else if[/b] statement to check multiple conditions.\r\n[b]For example:[/b] [code format=\"java\" codeId=\"730\"]int age = 25;\r\n\r\n[b]if[/b](age <= 0) {\r\n System.out.println(\"Error\");\r\n} [b]else if[/b](age <= 16) {\r\n System.out.println(\"Too Young\");\r\n} [b]else if[/b](age < 100) {\r\n System.out.println(\"Welcome!\");\r\n} [b]else [/b]{\r\n System.out.println(\"Really?\");\r\n}\r\n//Outputs \"Welcome!\"[/code]\r\nThe code will check the condition to evaluate to true and execute the statements inside that block.\r\n[note]You can include as many [b]else if[/b] statements as you need.[/note]"
1519 }
1520 ]
1521 }
1522 },
1523 {
1524 "lesson": {
1525 "id": 2144,
1526 "name": "Logical Statements",
1527 "type": 0,
1528 "mode": 1,
1529 "videoID": "PAaqgTr7Cx4",
1530 "tags": "operators",
1531 "quizzes": [
1532 {
1533 "id": 4219,
1534 "number": 1,
1535 "videoStart": 29.6,
1536 "videoEnd": 195.5,
1537 "linkedVideoID": null,
1538 "type": 3,
1539 "linkedQuizID": null,
1540 "tip": null,
1541 "hint": null,
1542 "time": 0,
1543 "answers": [
1544 {
1545 "id": 105818,
1546 "text": "&&",
1547 "isCorrect": false,
1548 "properties": {
1549 "prefix": "",
1550 "postfix": ""
1551 }
1552 }
1553 ],
1554 "question": "Fill in the blank to test both conditions in the following if statement.\r\n[!raw!]\r\nint age = 23;\r\nint money = 4000;\r\nif (age > 21 {0} money > 500) {\r\n System.out.println(\"Welcome\");\r\n}",
1555 "textContent": "[h1]Logical Operators[/h1]\r\n\r\nLogical operators are used to combine multiple conditions.\r\n\r\nLet's say you wanted your program to output \"Welcome!\" only when the variable [b]age [/b]is greater than 18 and the variable [b]money [/b]is greater than 500. \r\nOne way to accomplish this is to use nested [b]if [/b]statements:[code format=\"java\" codeId=\"731\"]if (age > 18) {\r\n if (money > 500) {\r\n System.out.println(\"Welcome!\");\r\n }\r\n}[/code]\r\nHowever, using the [b]AND [/b]logical operator ([b]&&[/b]) is a better way:[code format=\"java\" codeId=\"732\"]if (age > 18 [b]&&[/b] money > 500) {\r\n System.out.println(\"Welcome!\");\r\n}[/code]\r\n[note]If both operands of the AND operator are true, then the condition becomes true.[/note]"
1556 },
1557 {
1558 "id": 4220,
1559 "number": 2,
1560 "videoStart": 196,
1561 "videoEnd": 306,
1562 "linkedVideoID": null,
1563 "type": 2,
1564 "linkedQuizID": null,
1565 "tip": null,
1566 "hint": null,
1567 "time": 0,
1568 "answers": [
1569 {
1570 "id": 99514,
1571 "text": "11",
1572 "isCorrect": false,
1573 "properties": {
1574 "prefix": "",
1575 "postfix": ""
1576 }
1577 }
1578 ],
1579 "question": "What is the output of the following code?\r\nint a = 11; int b = 12;\r\nint c = 40;\r\nif (a > 100 || b > 3) {\r\n System.out.println(a); \r\n} else {\r\n System.out.println(c);\r\n}",
1580 "textContent": "[h1]The OR Operator[/h1]\r\n\r\nThe [b]OR [/b]operator (||) checks if any one of the conditions is true. \r\nThe condition becomes true, if any one of the operands evaluates to true.\r\n[b]For example:[/b] [code format=\"java\" codeId=\"733\"]int age = 25;\r\nint money = 100;\r\n\r\nif (age > 18 [b]||[/b] money > 500) {\r\n System.out.println(\"Welcome!\");\r\n}\r\n//Outputs \"Welcome!\"[/code]\r\nThe code above will print \"Welcome!\" if age is greater than 18 [b]or [/b]if money is greater than 500.\r\n\r\nThe [b]NOT [/b]([b]![/b]) logical operator is used to reverse the logical state of its operand. If a condition is true, the [b]NOT[/b] logical operator will make it false.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"735\"]int age = 25;\r\nif([b]!(age > 18)[/b]) {\r\n System.out.println(\"Too Young\");\r\n} else {\r\n System.out.println(\"Welcome\");\r\n}\r\n//Outputs \"Welcome\"[/code]\r\n[note]!(age > 18) reads as \"if age is NOT greater than 18\".[/note]"
1581 }
1582 ]
1583 }
1584 },
1585 {
1586 "lesson": {
1587 "id": 2145,
1588 "name": "The switch Statement",
1589 "type": 0,
1590 "mode": 1,
1591 "videoID": "RVRPmeccFT0",
1592 "tags": "switch",
1593 "quizzes": [
1594 {
1595 "id": 4221,
1596 "number": 1,
1597 "videoStart": 8,
1598 "videoEnd": 240,
1599 "linkedVideoID": null,
1600 "type": 3,
1601 "linkedQuizID": null,
1602 "tip": null,
1603 "hint": null,
1604 "time": 0,
1605 "answers": [
1606 {
1607 "id": 99515,
1608 "text": "switch",
1609 "isCorrect": false,
1610 "properties": {
1611 "prefix": "",
1612 "postfix": ""
1613 }
1614 },
1615 {
1616 "id": 99516,
1617 "text": "x",
1618 "isCorrect": false,
1619 "properties": {
1620 "prefix": "",
1621 "postfix": ""
1622 }
1623 },
1624 {
1625 "id": 99517,
1626 "text": "case",
1627 "isCorrect": false,
1628 "properties": {
1629 "prefix": "",
1630 "postfix": ""
1631 }
1632 }
1633 ],
1634 "question": "Fill in the blanks to test the variable's value using the switch statement.\r\n[!raw!]\r\nint x = 10;\r\n{0} ({1}) {\r\n case 10:\r\n System.out.println(\"A\");\r\n break;\r\n {2} 20:\r\n System.out.println(\"B\");\r\n break; \r\n}",
1635 "textContent": "[h1]The switch Statement[/h1]\r\n\r\nA [b]switch [/b]statement tests a variable for equality against a list of values. Each value is called a [b]case[/b], and the variable being switched on is checked for each case.\r\n[b]Syntax:[/b] [code format=\"java\" ][b]switch [/b](expression) {\r\n [b]case [/b]value1 :\r\n //Statements\r\n [b]break[/b]; //optional\r\n [b]case [/b]value2 :\r\n //Statements\r\n [b]break[/b]; //optional\r\n //You can have any number of case statements.\r\n [b]default [/b]: //Optional\r\n //Statements\r\n}[/code]\r\n- When the variable being switched on is equal to a [b]case[/b], the statements following that [b]case [/b]will execute until a [b]break [/b]statement is reached.\r\n- When a [b]break [/b]statement is reached, the [b]switch [/b]terminates, and the flow of control jumps to the next line after the [b]switch [/b]statement.\r\n- Not every [b]case [/b]needs to contain a [b]break[/b]. If no [b]break [/b]appears, the flow of control will fall through to subsequent cases until a [b]break [/b]is reached.\r\n\r\nThe example below tests [b]day [/b]against a set of values and prints a corresponding message. [code format=\"java\" codeId=\"736\"]int day = 3;\r\n\r\n[b]switch[/b](day) {\r\n [b]case [/b]1:\r\n System.out.println(\"Monday\");\r\n break;\r\n [b]case [/b]2:\r\n System.out.println(\"Tuesday\");\r\n break;\r\n [b]case [/b]3:\r\n System.out.println(\"Wednesday\");\r\n break;\r\n}\r\n// Outputs \"Wednesday\"[/code]\r\n[note]You can have any number of [b]case [/b]statements within a [b]switch[/b]. Each [b]case [/b]is followed by the comparison value and a colon.[/note]"
1636 },
1637 {
1638 "id": 4222,
1639 "number": 2,
1640 "videoStart": 240,
1641 "videoEnd": 384.5,
1642 "linkedVideoID": null,
1643 "type": 2,
1644 "linkedQuizID": null,
1645 "tip": null,
1646 "hint": null,
1647 "time": 0,
1648 "answers": [
1649 {
1650 "id": 106672,
1651 "text": "40",
1652 "isCorrect": false,
1653 "properties": {
1654 "prefix": "",
1655 "postfix": ""
1656 }
1657 }
1658 ],
1659 "question": "What is the output of the following code?\r\nint a = 11; int b = 12; int c = 40;\r\nswitch (a) {\r\n case 40:\r\n System.out.println(b);\r\n break;\r\n default:\r\n System.out.println(c);\r\n}",
1660 "textContent": "[h1]The default Statement[/h1]\r\n\r\nA switch statement can have an optional [b]default [/b]case. \r\nThe [b]default [/b]case can be used for performing a task when none of the cases is matched.\r\n \r\n[b]For example:[/b] [code format=\"java\" codeId=\"737\"]int day = 3;\r\n\r\nswitch(day) {\r\n case 6:\r\n System.out.println(\"Saturday\");\r\n break;\r\n case 7:\r\n System.out.println(\"Sunday\");\r\n break;\r\n [b] default[/b]:\r\n System.out.println(\"Weekday\");\r\n}\r\n// Outputs \"Weekday\"[/code]\r\n[note]No [b]break [/b]is needed in the default case, as it is always the last statement in the switch. [/note]"
1661 }
1662 ]
1663 }
1664 },
1665 {
1666 "lesson": {
1667 "id": 2146,
1668 "name": "While Loops",
1669 "type": 0,
1670 "mode": 1,
1671 "videoID": "8ZuWD2CBjgs",
1672 "tags": "loops",
1673 "quizzes": [
1674 {
1675 "id": 4224,
1676 "number": 1,
1677 "videoStart": 4,
1678 "videoEnd": 114,
1679 "linkedVideoID": null,
1680 "type": 8,
1681 "linkedQuizID": null,
1682 "tip": null,
1683 "hint": null,
1684 "time": 0,
1685 "answers": [
1686 {
1687 "id": 105823,
1688 "text": "int x = 12;",
1689 "isCorrect": false,
1690 "properties": {}
1691 },
1692 {
1693 "id": 105824,
1694 "text": "while (x < 100) {",
1695 "isCorrect": false,
1696 "properties": {}
1697 },
1698 {
1699 "id": 105825,
1700 "text": " System.out.println(\"Java rocks!\");",
1701 "isCorrect": false,
1702 "properties": {}
1703 },
1704 {
1705 "id": 105826,
1706 "text": "x++; }",
1707 "isCorrect": false,
1708 "properties": {}
1709 }
1710 ],
1711 "question": "Rearrange the code to produce a valid finite loop which prints a text to the screen in the loop.",
1712 "textContent": "[h1]while Loops[/h1]\r\n\r\nA [b]loop [/b]statement allows to repeatedly execute a statement or group of statements.\r\n\r\nA [b]while [/b]loop statement repeatedly executes a target statement as long as a given condition is true.\r\n\r\n[b]Example:[/b][code format=\"java\" codeId=\"738\"]int x = 3;\r\n\r\n[b]while[/b](x > 0) {\r\n System.out.println(x);\r\n x--;\r\n}\r\n/* \r\nOutputs\r\n 3\r\n 2\r\n 1\r\n*/[/code]\r\nThe [b]while [/b]loops check for the condition x > 0. If it evaluates to true, it executes the statements within its body. Then it checks for the statement again and repeats.\r\n[note]Notice the statement x--. This decrements x each time the loop runs, and makes the loop stop when x reaches 0. \r\nWithout the statement, the loop would run forever.[/note]"
1713 },
1714 {
1715 "id": 4225,
1716 "number": 2,
1717 "videoStart": 114,
1718 "videoEnd": 190,
1719 "linkedVideoID": null,
1720 "type": 2,
1721 "linkedQuizID": null,
1722 "tip": null,
1723 "hint": null,
1724 "time": 0,
1725 "answers": [
1726 {
1727 "id": 99527,
1728 "text": "5",
1729 "isCorrect": false,
1730 "properties": {
1731 "prefix": "",
1732 "postfix": ""
1733 }
1734 }
1735 ],
1736 "question": "How many times will the following loop work?\r\nint x = 0;\r\nint y = 5;\r\nwhile (x < y) {\r\n System.out.println(\"Hello\");\r\n x++;\t\r\n}",
1737 "textContent": "[h1]while Loops[/h1]\r\n\r\nWhen the expression is tested and the result is false, the loop body is skipped and the first statement after the while loop is executed.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"739\"]int x = 6;\r\n\r\n[b]while[/b]( x < 10 )\r\n{\r\n System.out.println(x);\r\n x++;\r\n}\r\nSystem.out.println(\"Loop ended\");\r\n\r\n/*\r\n6\r\n7\r\n8\r\n9\r\nLoop ended\r\n*/[/code]"
1738 }
1739 ]
1740 }
1741 },
1742 {
1743 "lesson": {
1744 "id": 2147,
1745 "name": "For Loops",
1746 "type": 0,
1747 "mode": 1,
1748 "videoID": "rjkYAs6gAkk",
1749 "tags": "loops",
1750 "quizzes": [
1751 {
1752 "id": 4226,
1753 "number": 1,
1754 "videoStart": 17,
1755 "videoEnd": 127,
1756 "linkedVideoID": null,
1757 "type": 6,
1758 "linkedQuizID": null,
1759 "tip": null,
1760 "hint": null,
1761 "time": 0,
1762 "answers": [
1763 {
1764 "id": 99528,
1765 "text": "for",
1766 "isCorrect": true,
1767 "properties": {}
1768 },
1769 {
1770 "id": 99529,
1771 "text": "i++",
1772 "isCorrect": true,
1773 "properties": {}
1774 },
1775 {
1776 "id": 99530,
1777 "text": "Great!",
1778 "isCorrect": true,
1779 "properties": {}
1780 },
1781 {
1782 "id": 99531,
1783 "text": "i",
1784 "isCorrect": false,
1785 "properties": {}
1786 },
1787 {
1788 "id": 99532,
1789 "text": "i--",
1790 "isCorrect": false,
1791 "properties": {}
1792 },
1793 {
1794 "id": 99533,
1795 "text": "i+1",
1796 "isCorrect": false,
1797 "properties": {}
1798 },
1799 {
1800 "id": 99534,
1801 "text": "10",
1802 "isCorrect": false,
1803 "properties": {}
1804 }
1805 ],
1806 "question": "Fill in the blanks to print \"Great!\" 10 times:\r\n[!raw!]\r\n{0} (int i = 0; i < 10; {1}) {\r\n System.out.println(\"{2}\");\r\n}",
1807 "textContent": "[h1]for Loops[/h1]\r\n\r\nAnother loop structure is the [b]for [/b]loop. A for loop allows you to efficiently write a loop that needs to execute a specific number of times.\r\n[b]Syntax:[/b] [code format=\"java\" ][b]for[/b] (initialization; condition; increment/decrement) {\r\n statement(s)\r\n}[/code]\r\n[b]Initialization[/b]: Expression executes only once during the beginning of loop\r\n[b]Condition[/b]: Is evaluated each time the loop iterates. The loop executes the statement repeatedly, until this condition returns false.\r\n[b]Increment/Decrement[/b]: Executes after each iteration of the loop.\r\n\r\nThe following example prints the numbers 1 through 5.[code format=\"java\" codeId=\"740\"]for(int x = 1; x <=5; x++) {\r\n System.out.println(x);\r\n}\r\n\r\n/* Outputs\r\n1\r\n2\r\n3\r\n4\r\n5\r\n*/[/code]\r\nThis initializes x to the value 1, and repeatedly prints the value of x, until the condition x<=5 becomes false. On each iteration, the statement x++ is executed, incrementing x by one.\r\n[note]Notice the semicolon (;) after initialization and condition in the syntax.[/note]"
1808 },
1809 {
1810 "id": 4227,
1811 "number": 2,
1812 "videoStart": 127,
1813 "videoEnd": 200,
1814 "linkedVideoID": null,
1815 "type": 2,
1816 "linkedQuizID": null,
1817 "tip": null,
1818 "hint": null,
1819 "time": 0,
1820 "answers": [
1821 {
1822 "id": 99535,
1823 "text": "2",
1824 "isCorrect": false,
1825 "properties": {
1826 "prefix": "",
1827 "postfix": ""
1828 }
1829 }
1830 ],
1831 "question": "How many times will the following loop run?\r\nfor (int i = 2; i < 10; i = i*i) {\r\n System.out.println(i);\r\n}",
1832 "textContent": "[h1]for Loops[/h1]\r\n\r\nYou can have any type of condition and any type of increment statements in the for loop.\r\nThe example below prints only the even values between 0 and 10: [code format=\"java\" codeId=\"741\"][b]for[/b](int x=0; x<=10; x=x+2) {\r\n System.out.println(x);\r\n}\r\n/*\r\n0\r\n2\r\n4\r\n6\r\n8\r\n10\r\n*/[/code]\r\n[note]A [b]for [/b]loop is best when the starting and ending numbers are known.[/note]"
1833 }
1834 ]
1835 }
1836 },
1837 {
1838 "lesson": {
1839 "id": 2206,
1840 "name": "do while Loops",
1841 "type": 0,
1842 "mode": 1,
1843 "videoID": "nfr52iR0Pyg",
1844 "tags": "loops",
1845 "quizzes": [
1846 {
1847 "id": 4384,
1848 "number": 1,
1849 "videoStart": 8,
1850 "videoEnd": 134.5,
1851 "linkedVideoID": null,
1852 "type": 1,
1853 "linkedQuizID": null,
1854 "tip": null,
1855 "hint": null,
1856 "time": 0,
1857 "answers": [
1858 {
1859 "id": 99536,
1860 "text": "A do while loop runs your code at least one time. ",
1861 "isCorrect": true,
1862 "properties": {}
1863 },
1864 {
1865 "id": 99537,
1866 "text": "A do while loop tests the condition before running the code.",
1867 "isCorrect": false,
1868 "properties": {}
1869 },
1870 {
1871 "id": 99538,
1872 "text": "A while loop runs the code before testing the condition.",
1873 "isCorrect": false,
1874 "properties": {}
1875 }
1876 ],
1877 "question": "How is a do while loop different from a while loop?",
1878 "textContent": "[h1]do...while Loops[/h1]\r\n\r\nA [b]do...while[/b] loop is similar to a [b]while [/b]loop, except that a [b]do...while[/b] loop is guaranteed to execute at least one time.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"742\"]int x = 1;\r\n[b]do [/b]{\r\n System.out.println(x);\r\n x++;\r\n} [b]while[/b](x < 5);\r\n\r\n/*\r\n1\r\n2\r\n3\r\n4\r\n*/[/code]\r\nNotice that the condition appears at the end of the loop, so the statements in the loop execute once before it is tested.\r\nEven with a false condition, the code will run once. Example:[code format=\"java\" codeId=\"743\"]int x = 1;\r\n[b]do [/b]{\r\n System.out.println(x);\r\n x++;\r\n} [b]while[/b](x < 0);\r\n\r\n//Outputs 1[/code]"
1879 },
1880 {
1881 "id": 4385,
1882 "number": 2,
1883 "videoStart": 135,
1884 "videoEnd": 174.5,
1885 "linkedVideoID": null,
1886 "type": 3,
1887 "linkedQuizID": null,
1888 "tip": null,
1889 "hint": null,
1890 "time": 0,
1891 "answers": [
1892 {
1893 "id": 99543,
1894 "text": "while",
1895 "isCorrect": false,
1896 "properties": {
1897 "prefix": "",
1898 "postfix": ""
1899 }
1900 },
1901 {
1902 "id": 99544,
1903 "text": "5",
1904 "isCorrect": false,
1905 "properties": {
1906 "prefix": "",
1907 "postfix": ""
1908 }
1909 }
1910 ],
1911 "question": "Fill in the blanks to print the values of the x variable 5 times.\r\n[!raw!]\r\nint x = 1;\r\ndo {\r\n System.out.println(x);\r\n x++;\r\n} \r\n{0} (x <= {1});",
1912 "textContent": "[h1]Loop Control Statements[/h1]\r\n\r\nThe [b]break [/b]and [b]continue [/b]statements change the loop's execution flow.\r\nThe [b]break [/b]statement terminates the loop and transfers execution to the statement immediately following the loop.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"744\"]int x = 1;\r\n\r\nwhile(x > 0) {\r\n System.out.println(x);\r\n if(x == 4) {\r\n [b]break;[/b]\r\n }\r\n x++;\r\n}\r\n\r\n/* Outputs\r\n1\r\n2\r\n3\r\n4\r\n*/[/code]\r\nThe [b]continue [/b]statement causes the loop to skip the remainder of its body and then immediately retest its condition prior to reiterating. In other words, it makes the loop skip to its next iteration.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"745\"]for(int x=10; x<=40; x=x+10) {\r\n if(x == 30) {\r\n [b]continue[/b];\r\n }\r\n System.out.println(x);\r\n}\r\n/* Outputs\r\n 10\r\n 20\r\n 40\r\n*/[/code]\r\n[note]As you can see, the above code skips the value of 30, as directed by the [b]continue [/b]statement.[/note]"
1913 }
1914 ]
1915 }
1916 },
1917 {
1918 "lesson": {
1919 "id": 2210,
1920 "name": "Module 2 Quiz",
1921 "type": 1,
1922 "mode": 0,
1923 "videoID": null,
1924 "tags": null,
1925 "quizzes": [
1926 {
1927 "id": 4389,
1928 "number": 1,
1929 "videoStart": 0,
1930 "videoEnd": 0,
1931 "linkedVideoID": null,
1932 "type": 3,
1933 "linkedQuizID": null,
1934 "tip": null,
1935 "hint": null,
1936 "time": 0,
1937 "answers": [
1938 {
1939 "id": 89349,
1940 "text": "7",
1941 "isCorrect": false,
1942 "properties": {
1943 "prefix": "",
1944 "postfix": ""
1945 }
1946 },
1947 {
1948 "id": 89350,
1949 "text": "x",
1950 "isCorrect": false,
1951 "properties": {
1952 "prefix": "",
1953 "postfix": ""
1954 }
1955 }
1956 ],
1957 "question": "Fill in the blanks to print \"in a loop\" 7 times, using the while loop.\r\n[!raw!]\r\nint x = 1;\r\nwhile (x <= {0}) {\r\n System.out.println(\"in a loop\");\r\n {1}++;\r\n}",
1958 "textContent": null
1959 },
1960 {
1961 "id": 4390,
1962 "number": 2,
1963 "videoStart": 0,
1964 "videoEnd": 0,
1965 "linkedVideoID": null,
1966 "type": 1,
1967 "linkedQuizID": null,
1968 "tip": null,
1969 "hint": null,
1970 "time": 0,
1971 "answers": [
1972 {
1973 "id": 27281,
1974 "text": "a && b is false if both a and b are true",
1975 "isCorrect": false,
1976 "properties": {}
1977 },
1978 {
1979 "id": 27282,
1980 "text": "(a || b ) && c is true if c is true and either a or b is true",
1981 "isCorrect": true,
1982 "properties": {}
1983 },
1984 {
1985 "id": 27283,
1986 "text": "a || b is true if either a or b is true",
1987 "isCorrect": true,
1988 "properties": {}
1989 },
1990 {
1991 "id": 27284,
1992 "text": "a && b is true if either a or b is true",
1993 "isCorrect": false,
1994 "properties": {}
1995 }
1996 ],
1997 "question": "Please select the correct statements about && and || operators.",
1998 "textContent": null
1999 },
2000 {
2001 "id": 4391,
2002 "number": 3,
2003 "videoStart": 0,
2004 "videoEnd": 0,
2005 "linkedVideoID": null,
2006 "type": 3,
2007 "linkedQuizID": null,
2008 "tip": null,
2009 "hint": null,
2010 "time": 0,
2011 "answers": [
2012 {
2013 "id": 92453,
2014 "text": "&&",
2015 "isCorrect": false,
2016 "properties": {
2017 "prefix": "",
2018 "postfix": ""
2019 }
2020 },
2021 {
2022 "id": 92454,
2023 "text": "72",
2024 "isCorrect": false,
2025 "properties": {
2026 "prefix": "",
2027 "postfix": ""
2028 }
2029 }
2030 ],
2031 "question": "Fill in the blanks to print \"You rock!\" if variable \"a\" is greater than 15, and variable \"b\" is less than or equal to 72.\r\n[!raw!]\r\nint a = 144;\r\nint b = 33;\r\nif (a > 15 {0} b <= {1}) {\r\n System.out.println(\"You rock!\");\r\n}",
2032 "textContent": null
2033 },
2034 {
2035 "id": 4392,
2036 "number": 4,
2037 "videoStart": 0,
2038 "videoEnd": 0,
2039 "linkedVideoID": null,
2040 "type": 3,
2041 "linkedQuizID": null,
2042 "tip": null,
2043 "hint": null,
2044 "time": 0,
2045 "answers": [
2046 {
2047 "id": 89353,
2048 "text": "for",
2049 "isCorrect": false,
2050 "properties": {
2051 "prefix": "",
2052 "postfix": ""
2053 }
2054 },
2055 {
2056 "id": 89354,
2057 "text": "x",
2058 "isCorrect": false,
2059 "properties": {
2060 "prefix": "",
2061 "postfix": ""
2062 }
2063 }
2064 ],
2065 "question": "Fill in the blanks to print \"in a loop\" 5 times using the for loop.\r\n[!raw!]\r\n{0} (int x = 0; {1} < 5; x++) {\r\n System.out.println(\"in a loop\");\r\n}",
2066 "textContent": null
2067 }
2068 ]
2069 }
2070 },
2071 {
2072 "lesson": {
2073 "id": 2209,
2074 "name": "Enhanced for Loop",
2075 "type": 0,
2076 "mode": 1,
2077 "videoID": "w41D0V-BnKQ",
2078 "tags": "arrays loops",
2079 "quizzes": [
2080 {
2081 "id": 4395,
2082 "number": 1,
2083 "videoStart": 11,
2084 "videoEnd": 182,
2085 "linkedVideoID": null,
2086 "type": 3,
2087 "linkedQuizID": null,
2088 "tip": null,
2089 "hint": null,
2090 "time": 0,
2091 "answers": [
2092 {
2093 "id": 99552,
2094 "text": ":",
2095 "isCorrect": false,
2096 "properties": {
2097 "prefix": "",
2098 "postfix": ""
2099 }
2100 },
2101 {
2102 "id": 99553,
2103 "text": "arr",
2104 "isCorrect": false,
2105 "properties": {
2106 "prefix": "",
2107 "postfix": ""
2108 }
2109 }
2110 ],
2111 "question": "Fill in the blanks to use the enhanced for loop for an array called \"arr\":\r\n[!raw!]\r\nint total = 0;\r\nfor(int x{0} {1}) {\r\n total += x;\r\n}",
2112 "textContent": "[h1]Enhanced for Loop[/h1]\r\n\r\nThe[b] enhanced for loop[/b] (sometimes called a \"for each\" loop) is used to traverse elements in arrays.\r\nThe advantages are that it eliminates the possibility of bugs and makes the code easier to read.\r\n[b]Example: [/b] [code format=\"java\" codeId=\"749\"]int[ ] primes = {2, 3, 5, 7};\r\n\r\n[b]for (int t: primes)[/b] {\r\n System.out.println(t); \r\n}\r\n\r\n/*\r\n2\r\n3\r\n5\r\n7\r\n*/[/code]\r\nThe[b] enhanced for loop[/b] declares a variable of a type compatible with the elements of the array being accessed. The variable will be available within the [b]for [/b]block, and its value will be the same as the current array element.\r\nSo, on each iteration of the loop, the variable [b]t [/b]will be equal to the corresponding element in the array.\r\n[note]Notice the [b]colon [/b]after the variable in the syntax.[/note]"
2113 }
2114 ]
2115 }
2116 },
2117 {
2118 "lesson": {
2119 "id": 2149,
2120 "name": "Multidimensional Arrays",
2121 "type": 0,
2122 "mode": 1,
2123 "videoID": "ctab5xPv-Vk",
2124 "tags": "arrays",
2125 "quizzes": [
2126 {
2127 "id": 4232,
2128 "number": 1,
2129 "videoStart": 8,
2130 "videoEnd": 125,
2131 "linkedVideoID": null,
2132 "type": 1,
2133 "linkedQuizID": null,
2134 "tip": null,
2135 "hint": null,
2136 "time": 0,
2137 "answers": [
2138 {
2139 "id": 99554,
2140 "text": "Johnson",
2141 "isCorrect": true,
2142 "properties": {}
2143 },
2144 {
2145 "id": 99555,
2146 "text": "John",
2147 "isCorrect": false,
2148 "properties": {}
2149 },
2150 {
2151 "id": 99556,
2152 "text": "Hey",
2153 "isCorrect": false,
2154 "properties": {}
2155 },
2156 {
2157 "id": 99557,
2158 "text": "Hello",
2159 "isCorrect": false,
2160 "properties": {}
2161 }
2162 ],
2163 "question": "What is the output of this code?\r\nString array[ ][ ] = { {\"Hey\", \"John\", \"Bye\"},\r\n{\"John\", \"Johnson\", \"Hello\"} }; \r\nSystem.out.println(array[1][1]);",
2164 "textContent": "[h1]Multidimensional Arrays[/h1]\r\n\r\n[b]Multidimensional [/b]arrays are array that contain other arrays. The two-dimensional array is the most basic multidimensional array. \r\nTo create multidimensional arrays, place each array within its own set of square brackets. Example of a two-dimensional array: [code format=\"java\" ][b]int[ ][ ][/b] sample = { {1, 2, 3}, {4, 5, 6} }; [/code]\r\nThis declares an array with two arrays as its elements.\r\nTo access an element in the two-dimensional array, provide two indexes, one for the array, and another for the element inside that array. \r\nThe following example accesses the first element in the second array of sample. [code format=\"java\" codeId=\"750\"]int x = sample[b][1][0][/b];\r\nSystem.out.println(x);\r\n\r\n// Outputs 4[/code]\r\n[note]The array's two indexes are called [b]row index[/b] and [b]column index[/b].[/note]"
2165 },
2166 {
2167 "id": 4233,
2168 "number": 2,
2169 "videoStart": 125,
2170 "videoEnd": 214.5,
2171 "linkedVideoID": null,
2172 "type": 2,
2173 "linkedQuizID": null,
2174 "tip": null,
2175 "hint": null,
2176 "time": 0,
2177 "answers": [
2178 {
2179 "id": 99558,
2180 "text": "8",
2181 "isCorrect": false,
2182 "properties": {
2183 "prefix": "",
2184 "postfix": ""
2185 }
2186 }
2187 ],
2188 "question": "What is the output of this code?\r\nint array[ ][ ] = {{3, 5, 8}, {7, 54, 1, 12, 4}}; \r\nSystem.out.println(array[0][2]);",
2189 "textContent": "[h1]Multidimensional Arrays[/h1]\r\n\r\nYou can get and set a multidimensional array's elements using the same pair of square brackets.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"751\"]int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} };\r\nmyArr[0][2] = 42;\r\nint x = myArr[1][0]; // 4[/code]\r\nThe above two-dimensional array contains three arrays. The first array has three elements, the second has a single element and the last of these has three elements. \r\n[note]In Java, you're not limited to just two-dimensional arrays. Arrays can be nested within arrays to as many levels as your program needs. All you need to declare an array with more than two dimensions, is to add as many sets of empty brackets as you need. However, these are harder to maintain.\r\nRemember, that all array members must be of the same type.[/note]"
2190 }
2191 ]
2192 }
2193 },
2194 {
2195 "lesson": {
2196 "id": 2150,
2197 "name": "Module 3 Quiz",
2198 "type": 1,
2199 "mode": 0,
2200 "videoID": null,
2201 "tags": null,
2202 "quizzes": [
2203 {
2204 "id": 4235,
2205 "number": 1,
2206 "videoStart": 0,
2207 "videoEnd": 0,
2208 "linkedVideoID": null,
2209 "type": 2,
2210 "linkedQuizID": null,
2211 "tip": null,
2212 "hint": null,
2213 "time": 0,
2214 "answers": [
2215 {
2216 "id": 97114,
2217 "text": "2",
2218 "isCorrect": false,
2219 "properties": {
2220 "prefix": "",
2221 "postfix": ""
2222 }
2223 }
2224 ],
2225 "question": "What is the output of this code?\r\nint arr[ ] = new int[3];\r\nfor (int i = 0; i < 3; i++) {\r\n arr[i] = i;\r\n} \r\nint res = arr[0] + arr[2];\r\nSystem.out.println(res);",
2226 "textContent": null
2227 },
2228 {
2229 "id": 4236,
2230 "number": 2,
2231 "videoStart": 0,
2232 "videoEnd": 0,
2233 "linkedVideoID": null,
2234 "type": 2,
2235 "linkedQuizID": null,
2236 "tip": null,
2237 "hint": null,
2238 "time": 0,
2239 "answers": [
2240 {
2241 "id": 97115,
2242 "text": "17",
2243 "isCorrect": false,
2244 "properties": {
2245 "prefix": "",
2246 "postfix": ""
2247 }
2248 }
2249 ],
2250 "question": "What is the output of this code?\t\t\r\nint result = 0;\r\nfor (int i = 0; i < 5; i++) {\r\n if (i == 3) { \r\n result += 10;\r\n } else {\r\n result += i;\r\n }\t\r\n}\r\nSystem.out.println(result);",
2251 "textContent": null
2252 },
2253 {
2254 "id": 5351,
2255 "number": 3,
2256 "videoStart": 0,
2257 "videoEnd": 0,
2258 "linkedVideoID": null,
2259 "type": 3,
2260 "linkedQuizID": null,
2261 "tip": null,
2262 "hint": null,
2263 "time": 0,
2264 "answers": [
2265 {
2266 "id": 89473,
2267 "text": "for",
2268 "isCorrect": false,
2269 "properties": {
2270 "prefix": "",
2271 "postfix": ""
2272 }
2273 },
2274 {
2275 "id": 89474,
2276 "text": ":",
2277 "isCorrect": false,
2278 "properties": {
2279 "prefix": "",
2280 "postfix": ""
2281 }
2282 },
2283 {
2284 "id": 89475,
2285 "text": "el",
2286 "isCorrect": false,
2287 "properties": {
2288 "prefix": "",
2289 "postfix": ""
2290 }
2291 }
2292 ],
2293 "question": "Fill in the blanks to calculate the sum of all elements in the array \"arr\" using an enhanced for loop:\r\n[!raw!]\r\nint res = 0;\r\n{0}(int el{1} arr) {\r\n res += {2};\r\n}",
2294 "textContent": null
2295 }
2296 ]
2297 }
2298 },
2299 {
2300 "lesson": {
2301 "id": 2155,
2302 "name": "Creating Classes & Objects",
2303 "type": 0,
2304 "mode": 1,
2305 "videoID": "XqTg2buXS5o",
2306 "tags": "classes objects",
2307 "quizzes": [
2308 {
2309 "id": 4249,
2310 "number": 1,
2311 "videoStart": 4,
2312 "videoEnd": 261,
2313 "linkedVideoID": null,
2314 "type": 3,
2315 "linkedQuizID": null,
2316 "tip": null,
2317 "hint": null,
2318 "time": 0,
2319 "answers": [
2320 {
2321 "id": 95429,
2322 "text": "class",
2323 "isCorrect": false,
2324 "properties": {
2325 "prefix": "",
2326 "postfix": ""
2327 }
2328 },
2329 {
2330 "id": 95430,
2331 "text": "test",
2332 "isCorrect": false,
2333 "properties": {
2334 "prefix": "",
2335 "postfix": ""
2336 }
2337 }
2338 ],
2339 "question": "Fill in the blanks to create a class with a single method called \"test\".\r\n[!raw!]\r\npublic {0} A {\r\n public void {1}() {\r\n System.out.println(''Hi'');\r\n } \r\n}",
2340 "textContent": "[h1]Creating Classes[/h1]\r\n\r\nIn order to create your own custom objects, you must first create the corresponding classes. This is accomplished by right clicking on the [b]src [/b]folder in Eclipse and selecting Create->New->Class. Give your class a name and click [b]Finish [/b]to add the new class to your project: [img id=\"2866\" width=\"100%\"]\r\nAs you can see, Eclipse has already added the initial code for the class.\r\nNow lets create a simple method in our new class.\r\n[b][u]Animal.java[/u][/b] [code format=\"java\"]public class Animal {\r\n void bark() {\r\n System.out.println(\"Woof-Woof\");\r\n }\r\n}[/code]\r\nWe declared a [b]bark()[/b] method in our [b]Animal [/b]class.\r\n[note]Now, in order to use the class and it's methods, we need to declare an [b]object [/b]of that class.[/note]"
2341 },
2342 {
2343 "id": 4250,
2344 "number": 2,
2345 "videoStart": 261,
2346 "videoEnd": 340,
2347 "linkedVideoID": null,
2348 "type": 6,
2349 "linkedQuizID": null,
2350 "tip": null,
2351 "hint": null,
2352 "time": 0,
2353 "answers": [
2354 {
2355 "id": 99567,
2356 "text": "class",
2357 "isCorrect": true,
2358 "properties": {}
2359 },
2360 {
2361 "id": 99568,
2362 "text": "A",
2363 "isCorrect": true,
2364 "properties": {}
2365 },
2366 {
2367 "id": 99569,
2368 "text": "new",
2369 "isCorrect": true,
2370 "properties": {}
2371 },
2372 {
2373 "id": 99570,
2374 "text": "test()",
2375 "isCorrect": true,
2376 "properties": {}
2377 },
2378 {
2379 "id": 99571,
2380 "text": "create",
2381 "isCorrect": false,
2382 "properties": {}
2383 },
2384 {
2385 "id": 99572,
2386 "text": "object",
2387 "isCorrect": false,
2388 "properties": {}
2389 },
2390 {
2391 "id": 99573,
2392 "text": "B",
2393 "isCorrect": false,
2394 "properties": {}
2395 }
2396 ],
2397 "question": "Fill in the blanks to create an object of the A class in the B class and call its \"test\" method.\r\n[!raw!]\r\npublic {0} A {\r\n public void test() {\r\n System.out.println(\"Hi\");\r\n }\t \r\n}\r\nclass B {\r\n public static void main(String args[ ]) {\r\n {1} obj = {2} A();\r\n obj.{3};\r\n }\r\n}",
2398 "textContent": "[h1]Creating Objects[/h1]\r\n\r\nLet's head over to our [b]main[/b] and create a new object of our class.\r\n[b][u]MyClass.java[/u][/b][code format=\"java\" codeId=\"757\"]class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]Animal dog = new Animal();[/b]\r\n [b]dog.bark();[/b]\r\n }\r\n}\r\n// Outputs \"Woof-Woof\"[/code]\r\nNow, [b]dog [/b]is an object of type [b]Animal[/b]. Thus we can call its [b]bark[/b]() method, using the name of the object and a [b]dot[/b].\r\nThe [b]dot [/b]notation is used to access the object's [b]attributes [/b]and [b]methods[/b].\r\n[note]You have just created your first object![/note]"
2399 }
2400 ]
2401 }
2402 },
2403 {
2404 "lesson": {
2405 "id": 2218,
2406 "name": "Class Attributes",
2407 "type": 0,
2408 "mode": 1,
2409 "videoID": "4xKihjI6HJ0",
2410 "tags": "classes",
2411 "quizzes": [
2412 {
2413 "id": 4419,
2414 "number": 1,
2415 "videoStart": 169,
2416 "videoEnd": 325,
2417 "linkedVideoID": null,
2418 "type": 6,
2419 "linkedQuizID": null,
2420 "tip": null,
2421 "hint": null,
2422 "time": 0,
2423 "answers": [
2424 {
2425 "id": 95438,
2426 "text": "class",
2427 "isCorrect": true,
2428 "properties": {}
2429 },
2430 {
2431 "id": 95439,
2432 "text": "int",
2433 "isCorrect": true,
2434 "properties": {}
2435 },
2436 {
2437 "id": 95440,
2438 "text": "double",
2439 "isCorrect": true,
2440 "properties": {}
2441 },
2442 {
2443 "id": 95441,
2444 "text": "String",
2445 "isCorrect": true,
2446 "properties": {}
2447 },
2448 {
2449 "id": 95442,
2450 "text": "define",
2451 "isCorrect": false,
2452 "properties": {}
2453 },
2454 {
2455 "id": 95443,
2456 "text": "attribute",
2457 "isCorrect": false,
2458 "properties": {}
2459 },
2460 {
2461 "id": 95444,
2462 "text": "void",
2463 "isCorrect": false,
2464 "properties": {}
2465 }
2466 ],
2467 "question": "Fill in the blanks to define a class with these attributes: age of type integer, height as a double, and name as a string.\r\n[!raw!]\r\n{0} Person {\r\n {1} age;\r\n {2} height;\r\n {3} name;\r\n}",
2468 "textContent": "[h1]Defining Attributes[/h1]\r\n\r\nA class has [b]attributes [/b]and [b]methods[/b]. The attributes are basically variables within a class.\r\nLet's create a class called [b]Vehicle[/b], with its corresponding attributes and methods. [code format=\"java\"]public class Vehicle {\r\n int maxSpeed;\r\n int wheels;\r\n String color;\r\n double fuelCapacity; \r\n\r\n void horn() {\r\n System.out.println(\"Beep!\");\r\n } \r\n}[/code]\r\n[b]maxSpeed[/b], [b]wheels[/b], [b]color[/b],[b] [/b]and [b]fuelCapacity [/b]are the attributes of our Vehicle class, and[b] horn()[/b] is the only method.\r\n[note]You can define as many attributes and methods as necessary.[/note]"
2469 },
2470 {
2471 "id": 4420,
2472 "number": 2,
2473 "videoStart": 419,
2474 "videoEnd": 615,
2475 "linkedVideoID": null,
2476 "type": 3,
2477 "linkedQuizID": null,
2478 "tip": null,
2479 "hint": null,
2480 "time": 0,
2481 "answers": [
2482 {
2483 "id": 99574,
2484 "text": "new",
2485 "isCorrect": false,
2486 "properties": {
2487 "prefix": "",
2488 "postfix": ""
2489 }
2490 },
2491 {
2492 "id": 99575,
2493 "text": "people",
2494 "isCorrect": false,
2495 "properties": {
2496 "prefix": "",
2497 "postfix": ""
2498 }
2499 },
2500 {
2501 "id": 99576,
2502 "text": "()",
2503 "isCorrect": false,
2504 "properties": {
2505 "prefix": "",
2506 "postfix": ""
2507 }
2508 }
2509 ],
2510 "question": "Fill in the blanks to create two objects from the class \"people\".\r\n[!raw!]\r\npeople obj1 = {0} people();\r\n{1} obj2 = new people{2};",
2511 "textContent": "[h1]Creating Objects[/h1]\r\n\r\nNext, we can create multiple objects of our [b]Vehicle [/b]class, and use the dot syntax to access their attributes and methods. [code format=\"java\" codeId=\"758\"]class MyClass {\r\n public static void main(String[ ] args) {\r\n Vehicle v1 = new Vehicle();\r\n Vehicle v2 = new Vehicle();\r\n v1.color = \"red\";\r\n v2.horn();\r\n }\r\n}[/code]"
2512 }
2513 ]
2514 }
2515 },
2516 {
2517 "lesson": {
2518 "id": 2156,
2519 "name": "Access Modifiers",
2520 "type": 0,
2521 "mode": 1,
2522 "videoID": "ePj64t65G40",
2523 "tags": "access-modifiers",
2524 "quizzes": [
2525 {
2526 "id": 4251,
2527 "number": 1,
2528 "videoStart": 15,
2529 "videoEnd": 261,
2530 "linkedVideoID": null,
2531 "type": 1,
2532 "linkedQuizID": null,
2533 "tip": null,
2534 "hint": null,
2535 "time": 0,
2536 "answers": [
2537 {
2538 "id": 95448,
2539 "text": "private",
2540 "isCorrect": true,
2541 "properties": {}
2542 },
2543 {
2544 "id": 95449,
2545 "text": "public",
2546 "isCorrect": true,
2547 "properties": {}
2548 },
2549 {
2550 "id": 95450,
2551 "text": "hidden",
2552 "isCorrect": false,
2553 "properties": {}
2554 },
2555 {
2556 "id": 95451,
2557 "text": "protected",
2558 "isCorrect": true,
2559 "properties": {}
2560 }
2561 ],
2562 "question": "Which of the following are valid access modifiers?",
2563 "textContent": "[h1]Access Modifiers[/h1]\r\n\r\nNow let's discuss the [b]public [/b]keyword in front of the main method.[code format=\"java\"][b]public [/b]static void main(String[ ] args)[/code]\r\n[b]public [/b]is an [b]access modifier[/b], meaning that it is used to set the level of access. You can use access modifiers for classes, attributes, and methods.\r\n\r\nFor classes, the available modifiers are public or default (left blank), as described below:\r\n[b]public[/b]: The class is accessible by any other class.\r\n[b]default[/b]: The class is accessible only by classes in the same package.\r\n\r\nThe following choices are available for attributes and methods:\r\n[b]default[/b]: A variable or method declared with no access control modifier is available to any other class in the same package.\r\n[b]public[/b]: Accessible from any other class.\r\n[b]protected[/b]: Provides the same access as the default access modifier, with the addition that subclasses can access protected methods and variables of the superclass (Subclasses and superclasses are covered in upcoming lessons).\r\n[b]private[/b]: Accessible only within the declared class itself.\r\n\r\n[b]Example: [/b][code format=\"java\"]public class Vehicle {\r\n [b]private [/b]int maxSpeed;\r\n [b]private [/b]int wheels;\r\n [b]private [/b]String color;\r\n [b]private [/b]double fuelCapacity;\r\n\r\n [b]public [/b]void horn() {\r\n System.out.println(\"Beep!\");\r\n }\r\n}[/code]\r\n[note]It's a best practice to keep the variables within a class private. The variables are accessible and modified using [b]Getters [/b]and [b]Setters[/b]. \r\nTap [b]Continue [/b]to learn about Getters and Setters.[/note]"
2564 }
2565 ]
2566 }
2567 },
2568 {
2569 "lesson": {
2570 "id": 2154,
2571 "name": "Getters and Setters",
2572 "type": 0,
2573 "mode": 1,
2574 "videoID": "wF18uVxjtvc",
2575 "tags": "classes",
2576 "quizzes": [
2577 {
2578 "id": 4247,
2579 "number": 1,
2580 "videoStart": 43,
2581 "videoEnd": 187,
2582 "linkedVideoID": null,
2583 "type": 6,
2584 "linkedQuizID": null,
2585 "tip": null,
2586 "hint": null,
2587 "time": 0,
2588 "answers": [
2589 {
2590 "id": 95452,
2591 "text": "int",
2592 "isCorrect": true,
2593 "properties": {}
2594 },
2595 {
2596 "id": 95453,
2597 "text": "x",
2598 "isCorrect": true,
2599 "properties": {}
2600 },
2601 {
2602 "id": 95454,
2603 "text": "void",
2604 "isCorrect": true,
2605 "properties": {}
2606 },
2607 {
2608 "id": 95455,
2609 "text": "String",
2610 "isCorrect": false,
2611 "properties": {}
2612 },
2613 {
2614 "id": 95456,
2615 "text": "double",
2616 "isCorrect": false,
2617 "properties": {}
2618 }
2619 ],
2620 "question": "Fill in the blanks to define the set and get methods.\r\n[!raw!]\r\nclass A {\r\n private int x;\t\t\t\r\n public {0} getX() {\r\n return {1};\r\n}\r\n public {2} setX(int x) {\r\n this.x = x;\r\n }\r\n}",
2621 "textContent": "[h1]Getters & Setters[/h1]\r\n\r\n[b]Getters [/b]and [b]Setters [/b]are used to effectively protect your data, particularly when creating classes. For each variable, the [b]get [/b]method returns its value, while the [b]set [/b]method sets the value.\r\n\r\n[b]Getters [/b]start with [b]get[/b], followed by the variable name, with the first letter of the variable name capitalized.\r\n[b]Setters [/b]start with [b]set[/b], followed by the variable name, with the first letter of the variable name capitalized.\r\n\r\n[b]Example:[/b] [code format=\"java\"]public class Vehicle {\r\n private String color;\r\n\r\n // Getter\r\n public String [b]getColor[/b]() {\r\n return color;\r\n }\r\n\r\n // Setter\r\n public void [b]setColor[/b](String c) {\r\n this.color = c;\r\n }\r\n}[/code]\r\nThe [b]getter [/b]method returns the value of the attribute.\r\nThe [b]setter [/b]method takes a parameter and assigns it to the attribute.\r\n[note]The keyword [b]this [/b]is used to refer to the current object. Basically, [b]this.color[/b] is the [b]color [/b]attribute of the current object.[/note]"
2622 },
2623 {
2624 "id": 4248,
2625 "number": 2,
2626 "videoStart": 187,
2627 "videoEnd": 265,
2628 "linkedVideoID": null,
2629 "type": 1,
2630 "linkedQuizID": null,
2631 "tip": null,
2632 "hint": null,
2633 "time": 0,
2634 "answers": [
2635 {
2636 "id": 99577,
2637 "text": "setAge",
2638 "isCorrect": true,
2639 "properties": {}
2640 },
2641 {
2642 "id": 99578,
2643 "text": "initAge",
2644 "isCorrect": false,
2645 "properties": {}
2646 },
2647 {
2648 "id": 99579,
2649 "text": "getAge",
2650 "isCorrect": false,
2651 "properties": {}
2652 },
2653 {
2654 "id": 99580,
2655 "text": "Age",
2656 "isCorrect": false,
2657 "properties": {}
2658 }
2659 ],
2660 "question": "What would the name of the setter method for the class variable named \"age\" be?",
2661 "textContent": "[h1]Getters & Setters[/h1]\r\n\r\nOnce our getter and setter have been defined, we can use it in our [b]main[/b]:[code format=\"java\" codeId=\"759\"]public static void main(String[ ] args) {\r\n Vehicle v1 = new Vehicle();\r\n v1.setColor(\"Red\");\r\n System.out.println(v1.getColor());\r\n}\r\n\r\n//Outputs \"Red\"[/code]\r\nGetters and setters allow us to have control over the values. You may, for example, validate the given value in the setter before actually setting the value.\r\n[note]Getters and setters are fundamental building blocks for [b]encapsulation[/b], which will be covered in the next module.[/note]"
2662 }
2663 ]
2664 }
2665 },
2666 {
2667 "lesson": {
2668 "id": 2157,
2669 "name": "Constructors",
2670 "type": 0,
2671 "mode": 1,
2672 "videoID": "tPFuVRbUTwA",
2673 "tags": "constructors",
2674 "quizzes": [
2675 {
2676 "id": 4254,
2677 "number": 1,
2678 "videoStart": 68,
2679 "videoEnd": 119,
2680 "linkedVideoID": null,
2681 "type": 6,
2682 "linkedQuizID": null,
2683 "tip": null,
2684 "hint": null,
2685 "time": 0,
2686 "answers": [
2687 {
2688 "id": 95469,
2689 "text": "Person",
2690 "isCorrect": true,
2691 "properties": {}
2692 },
2693 {
2694 "id": 95470,
2695 "text": "int",
2696 "isCorrect": true,
2697 "properties": {}
2698 },
2699 {
2700 "id": 95471,
2701 "text": "private",
2702 "isCorrect": false,
2703 "properties": {}
2704 },
2705 {
2706 "id": 95472,
2707 "text": "constructor",
2708 "isCorrect": false,
2709 "properties": {}
2710 }
2711 ],
2712 "question": "Fill in the blanks to create a valid constructor.\r\n[!raw!]\t\t\r\nclass Person {\r\n private int age;\r\n public {0}({1} myage) {\r\n age = myage;\r\n }\r\n}",
2713 "textContent": "[h1]Constructors[/h1]\r\n\r\n[b]Constructors [/b]are special methods invoked when an object is created and are used to initialize them. \r\nA constructor can be used to provide initial values for object attributes.\r\n\r\n- A constructor name must be same as its class name.\r\n- A constructor must have no explicit return type.\r\n\r\nExample of a constructor:[code format=\"java\"]public class Vehicle {\r\n private String color;\r\n [b]Vehicle() [/b]{\r\n color = \"Red\";\r\n }\r\n}[/code]\r\nThe [b]Vehicle[/b]() method is the constructor of our class, so whenever an object of that class is created, the color attribute will be set to \"Red\".\r\nA constructor can also take parameters to initialize attributes. [code format=\"java\"]public class Vehicle {\r\n private String color;\r\n [b]Vehicle(String c) [/b]{\r\n color = c;\r\n }\r\n}[/code]"
2714 },
2715 {
2716 "id": 4255,
2717 "number": 2,
2718 "videoStart": 119,
2719 "videoEnd": 186,
2720 "linkedVideoID": null,
2721 "type": 1,
2722 "linkedQuizID": null,
2723 "tip": null,
2724 "hint": null,
2725 "time": 0,
2726 "answers": [
2727 {
2728 "id": 95473,
2729 "text": "True",
2730 "isCorrect": true,
2731 "properties": {}
2732 },
2733 {
2734 "id": 95474,
2735 "text": "False",
2736 "isCorrect": false,
2737 "properties": {}
2738 }
2739 ],
2740 "question": "True or false: The constructor must have the same name as the class.",
2741 "textContent": "[h1]Using Constructors[/h1]\r\n\r\nThe constructor is called when you create an object using the [b]new [/b]keyword. \r\n[b]Example:[/b] [code format=\"java\"]public class MyClass {\r\n public static void main(String[ ] args) {\r\n Vehicle v = new [b]Vehicle(\"Blue\")[/b];\r\n }\r\n}[/code]\r\n[note]This will call the constructor, which will set the [b]color [/b]attribute to \"Blue\".[/note]"
2742 },
2743 {
2744 "id": 4256,
2745 "number": 3,
2746 "videoStart": 186,
2747 "videoEnd": 322,
2748 "linkedVideoID": null,
2749 "type": 3,
2750 "linkedQuizID": null,
2751 "tip": null,
2752 "hint": null,
2753 "time": 0,
2754 "answers": [
2755 {
2756 "id": 99581,
2757 "text": "class",
2758 "isCorrect": false,
2759 "properties": {
2760 "prefix": "",
2761 "postfix": ""
2762 }
2763 },
2764 {
2765 "id": 99582,
2766 "text": "int",
2767 "isCorrect": false,
2768 "properties": {
2769 "prefix": "",
2770 "postfix": ""
2771 }
2772 }
2773 ],
2774 "question": "Fill in the blanks.\r\n[!raw!]\r\n{0} A\r\n{\r\n private int x;\r\n public A({1} val) {\r\n x = val;\r\n }\r\n}",
2775 "textContent": "[h1]Constructors[/h1]\r\n\r\nA single class can have multiple constructors with different numbers of parameters.\r\nThe setter methods inside the constructors can be used to set the attribute values.\r\n\r\n[b]Example:[/b] [code format=\"java\" ]public class Vehicle {\r\n private String color;\r\n\r\n Vehicle() {\r\n this.setColor(\"Red\");\r\n }\r\n Vehicle(String c) {\r\n this.setColor(c);\r\n }\r\n\r\n // Setter\r\n public void setColor(String c) {\r\n this.color = c;\r\n }\r\n}[/code]\r\nThe class above has two constructors, one without any parameters setting the color attribute to a default value of \"Red\", and another constructor that accepts a parameter and assigns it to the attribute.\r\n\r\nNow, we can use the constructors to create objects of our class.[code format=\"java\" codeId=\"760\"]//color will be \"Red\"\r\nVehicle v1 = new Vehicle();\r\n\r\n//color will be \"Green\"\r\nVehicle v2 = new Vehicle(\"Green\"); [/code]\r\n[note]Java automatically provides a default constructor, so all classes have a constructor, whether one is specifically defined or not.[/note]"
2776 }
2777 ]
2778 }
2779 },
2780 {
2781 "lesson": {
2782 "id": 2158,
2783 "name": "Value & Reference Types",
2784 "type": 0,
2785 "mode": 1,
2786 "videoID": "eRfvgSvf-mM",
2787 "tags": "value-types reference-types",
2788 "quizzes": [
2789 {
2790 "id": 4257,
2791 "number": 1,
2792 "videoStart": 34,
2793 "videoEnd": 174,
2794 "linkedVideoID": null,
2795 "type": 2,
2796 "linkedQuizID": null,
2797 "tip": null,
2798 "hint": null,
2799 "time": 0,
2800 "answers": [
2801 {
2802 "id": 100248,
2803 "text": "4",
2804 "isCorrect": false,
2805 "properties": {
2806 "prefix": "",
2807 "postfix": ""
2808 }
2809 }
2810 ],
2811 "question": "What is the output of this code?\r\npublic static void main(String[ ] args) {\r\n int x = 4;\r\n square(x);\r\n System.out.println(x);\t\t\r\n}\r\nstatic void square(int x) {\r\n x = x*x;\r\n}",
2812 "textContent": "[h1]Value Types[/h1]\r\n\r\n[b]Value types[/b] are the basic types, and include byte, short, int, long, float, double, boolean, and char.\r\nThese data types store the values assigned to them in the corresponding memory locations.\r\nSo, when you pass them to a method, you basically operate on the variable's [b]value[/b], rather than on the variable itself.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"761\"]public class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]int x = 5;[/b]\r\n addOneTo([b]x[/b]);\r\n System.out.println([b]x[/b]); \r\n }\r\n static void addOneTo(int num) {\r\n num = num + 1;\r\n }\r\n}\r\n// Outputs \"[b]5[/b]\"[/code]\r\n[note]The method from the example above takes the [b]value [/b]of its parameter, which is why the original variable is not affected and 5 remains as its value.[/note]"
2813 },
2814 {
2815 "id": 4258,
2816 "number": 2,
2817 "videoStart": 174,
2818 "videoEnd": 401,
2819 "linkedVideoID": null,
2820 "type": 2,
2821 "linkedQuizID": null,
2822 "tip": null,
2823 "hint": null,
2824 "time": 0,
2825 "answers": [
2826 {
2827 "id": 100249,
2828 "text": "10",
2829 "isCorrect": false,
2830 "properties": {
2831 "prefix": "",
2832 "postfix": ""
2833 }
2834 }
2835 ],
2836 "question": "What is the output of this code?\r\npublic static void main(String[ ] args) {\r\n Person p = new Person();\r\n p.setAge(25);\r\n change(p);\r\n System.out.println(p.getAge());\r\n}\r\nstatic void change(Person p) {\r\n p.setAge(10);\r\n}",
2837 "textContent": "[h1]Reference Types\u000b[/h1]\r\n\r\n[b][/b]A [b]reference type[/b] stores a reference (or address) to the memory location where the corresponding data is stored.\r\nWhen you create an object using the constructor, you create a reference variable.\r\nFor example, consider having a [b]Person[/b] class defined: [code format=\"java\" codeId=\"762\"]public class MyClass {\r\n public static void main(String[ ] args) {\r\n Person j;\r\n j = new Person(\"John\");\r\n j.setAge(20);\r\n celebrateBirthday(j);\r\n System.out.println(j.getAge());\r\n }\r\n static void celebrateBirthday(Person p) {\r\n p.setAge(p.getAge() + 1);\r\n }\r\n}\r\n//Outputs \"[b]21[/b]\"[/code]\r\nThe method [b]celebrateBirthday [/b]takes a Person object as its parameter, and increments its attribute. \r\nBecause [b]j[/b] is a reference type, the method affects the object itself, and is able to change the actual value of its attribute.\r\n[note][b]Arrays [/b]and [b]Strings [/b]are also reference data types.[/note]"
2838 }
2839 ]
2840 }
2841 },
2842 {
2843 "lesson": {
2844 "id": 2219,
2845 "name": "The Math Class",
2846 "type": 0,
2847 "mode": 1,
2848 "videoID": "JzMdepMLW44",
2849 "tags": "math",
2850 "quizzes": [
2851 {
2852 "id": 4421,
2853 "number": 1,
2854 "videoStart": 30,
2855 "videoEnd": 234,
2856 "linkedVideoID": null,
2857 "type": 1,
2858 "linkedQuizID": null,
2859 "tip": null,
2860 "hint": null,
2861 "time": 0,
2862 "answers": [
2863 {
2864 "id": 99586,
2865 "text": "6",
2866 "isCorrect": true,
2867 "properties": {}
2868 },
2869 {
2870 "id": 99587,
2871 "text": "-6",
2872 "isCorrect": false,
2873 "properties": {}
2874 },
2875 {
2876 "id": 99588,
2877 "text": "3",
2878 "isCorrect": false,
2879 "properties": {}
2880 }
2881 ],
2882 "question": "What is the value of the following expression?\r\nMath.abs(Math.min(-6, 3));",
2883 "textContent": "[h1]The Math Class[/h1]\r\n\r\nThe [b]JDK [/b]defines a number of useful classes, one of them being the [b]Math [/b]class, which provides predefined methods for mathematical operations.\r\nYou do not need to create an object of the [b]Math [/b]class to use it. To access it, just type in [b]Math.[/b] and the corresponding method.\r\n\r\n[b]Math.abs()[/b] returns the absolute value of its parameter.[code format=\"java\" codeId=\"763\"]int a = Math.abs(10); // 10\r\nint b = Math.abs(-20); // 20[/code]\r\n[b]Math.ceil()[/b] rounds a floating point value up to the nearest integer value. The rounded value is returned as a [b]double[/b].[code format=\"java\" codeId=\"764\"]double c = Math.ceil(7.342); // 8.0[/code]\r\nSimilarly, [b]Math.floor()[/b] rounds a floating point value down to the nearest integer value. [code format=\"java\" codeId=\"765\"]double f = Math.floor(7.343); // 7.0[/code]\r\n[b]Math.max()[/b] returns the largest of its parameters.[code format=\"java\" codeId=\"766\"]int m = Math.max(10, 20); // 20[/code]\r\nConversely, [b]Math.min()[/b] returns the smallest parameter.[code format=\"java\" codeId=\"767\"]int m = Math.min(10, 20); // 10[/code]\r\n[b]Math.pow()[/b] takes two parameters and returns the first parameter raised to the power of the second parameter. [code format=\"java\" codeId=\"768\"]double p = Math.pow(2, 3); // 8.0[/code]\r\n[note]There are a number of other methods available in the Math class, including:\r\n[b]sqrt()[/b] for square root, [b]sin() for[/b] sine, [b]cos() for[/b] cosine, and others.[/note]"
2884 }
2885 ]
2886 }
2887 },
2888 {
2889 "lesson": {
2890 "id": 2159,
2891 "name": "Static",
2892 "type": 0,
2893 "mode": 1,
2894 "videoID": "gTk_F61_-9k",
2895 "tags": "static",
2896 "quizzes": [
2897 {
2898 "id": 4260,
2899 "number": 1,
2900 "videoStart": 0,
2901 "videoEnd": 165,
2902 "linkedVideoID": null,
2903 "type": 2,
2904 "linkedQuizID": null,
2905 "tip": null,
2906 "hint": null,
2907 "time": 0,
2908 "answers": [
2909 {
2910 "id": 99589,
2911 "text": "static",
2912 "isCorrect": false,
2913 "properties": {
2914 "prefix": "public ",
2915 "postfix": " int x=0;"
2916 }
2917 }
2918 ],
2919 "question": "Fill in the blank to declare a static variable.",
2920 "textContent": "[h1]Static[/h1]\r\n\r\nWhen you declare a variable or a method as [b]static[/b], it belongs to the class, rather than to a specific instance. This means that only one instance of a [b]static [/b]member exists, even if you create multiple objects of the class, or if you don't create any. It will be shared by all objects.\r\n[b]Example:[/b][code format=\"java\" ]public class Counter {\r\n public [b]static [/b]int COUNT=0;\r\n Counter() {\r\n COUNT++;\r\n }\r\n}[/code]\r\nThe [b]COUNT [/b]variable will be shared by all objects of that class.\r\nNow, we can create objects of our Counter class in [b]main[/b], and access the static variable. [code format=\"java\" codeId=\"769\"]public class MyClass {\r\n public static void main(String[ ] args) {\r\n Counter c1 = new Counter();\r\n Counter c2 = new Counter();\r\n System.out.println([b]Counter.COUNT[/b]);\r\n }\r\n}\r\n//Outputs \"2\"[/code]\r\nThe output is 2, because the [b]COUNT [/b]variable is static and gets incremented by one each time a new object of the Counter class is created. In the code above, we created 2 objects.\r\nYou can also access the static variable using any object of that class, such as [b]c1.COUNT[/b].\r\n[note]It’s a common practice to use upper case when naming a static variable, although not mandatory.[/note]"
2921 },
2922 {
2923 "id": 4262,
2924 "number": 2,
2925 "videoStart": 165,
2926 "videoEnd": 272,
2927 "linkedVideoID": null,
2928 "type": 2,
2929 "linkedQuizID": null,
2930 "tip": null,
2931 "hint": null,
2932 "time": 0,
2933 "answers": [
2934 {
2935 "id": 100250,
2936 "text": "2",
2937 "isCorrect": false,
2938 "properties": {
2939 "prefix": "",
2940 "postfix": ""
2941 }
2942 }
2943 ],
2944 "question": "What output results from this code?\r\nclass Person {\r\npublic static int pCount;\t\r\npublic static void main(String[ ] args) {\t\t\t\r\n Person.pCount = 1; \r\n Person.pCount++;\r\n System.out.println(Person.pCount);\t\t\r\n }\r\n}",
2945 "textContent": "[h1]Static [/h1]\r\n\r\nThe same concept applies to [b]static [/b]methods.[code format=\"java\" ]public class Vehicle {\r\n public [b]static [/b]void horn() {\r\n System.out.println(\"Beep\");\r\n }\r\n}[/code]\r\nAny Vehicle object can call the [b]horn [/b]method.[code format=\"java\" codeId=\"770\"]public class MyClass {\r\n public static void main(String[ ] args) {\r\n Vehicle v1 = new Vehicle();\r\n v1.horn();\r\n }\r\n}[/code]\r\nAnother example of static methods are those of the [b]Math [/b]class, which is why you can call them without creating a [b]Math [/b]object.\r\n[note]Also, the [b]main[/b] method must always be [b]static[/b].[/note]"
2946 }
2947 ]
2948 }
2949 },
2950 {
2951 "lesson": {
2952 "id": 2160,
2953 "name": "Final",
2954 "type": 0,
2955 "mode": 1,
2956 "videoID": "Suxdg95FV1w",
2957 "tags": "final",
2958 "quizzes": [
2959 {
2960 "id": 4263,
2961 "number": 1,
2962 "videoStart": 64,
2963 "videoEnd": 165,
2964 "linkedVideoID": null,
2965 "type": 2,
2966 "linkedQuizID": null,
2967 "tip": null,
2968 "hint": null,
2969 "time": 0,
2970 "answers": [
2971 {
2972 "id": 105985,
2973 "text": "final",
2974 "isCorrect": false,
2975 "properties": {
2976 "prefix": "",
2977 "postfix": ""
2978 }
2979 }
2980 ],
2981 "question": "What keyword makes a variable a constant?",
2982 "textContent": "[h1]final[/h1]\r\n\r\nUse the [b]final [/b]keyword to mark a variable constant, so that it can be assigned only once.\r\n[b]Example:[/b][code format=\"java\" codeId=\"771\"]class MyClass {\r\n public static [b]final [/b]double PI = 3.14; \r\n public static void main(String[ ] args) {\r\n System.out.println(PI);\r\n }\r\n}[/code]\r\n[b]PI [/b]is now a constant. Any attempt to assign it a value will cause an error.\r\n[note]Methods and classes can also be marked [b]final[/b]. This serves to restrict methods so that they can't be overridden and classes so that they can't be made subclasses. \r\nThese concepts will be covered in the next module.[/note]"
2983 }
2984 ]
2985 }
2986 },
2987 {
2988 "lesson": {
2989 "id": 2161,
2990 "name": "Packages",
2991 "type": 0,
2992 "mode": 1,
2993 "videoID": "l5SviD48vOQ",
2994 "tags": "packages",
2995 "quizzes": [
2996 {
2997 "id": 4267,
2998 "number": 1,
2999 "videoStart": 10,
3000 "videoEnd": 183,
3001 "linkedVideoID": null,
3002 "type": 1,
3003 "linkedQuizID": null,
3004 "tip": null,
3005 "hint": null,
3006 "time": 0,
3007 "answers": [
3008 {
3009 "id": 100254,
3010 "text": "one",
3011 "isCorrect": false,
3012 "properties": {}
3013 },
3014 {
3015 "id": 100255,
3016 "text": "none",
3017 "isCorrect": false,
3018 "properties": {}
3019 },
3020 {
3021 "id": 100256,
3022 "text": "as many as you need",
3023 "isCorrect": true,
3024 "properties": {}
3025 }
3026 ],
3027 "question": "How many packages can be contained in a Java program?",
3028 "textContent": "[h1]Packages[/h1]\r\n\r\n[b]Packages [/b]are used to avoid name conflicts and to control access to classes.\r\nA [b]package [/b]can be defined as a group made up of similar types of classes, along with sub-packages. \r\nCreating a package in Java is quite easy. Simply right click on your [b]src [/b]directory and click New->Package. Give your package a name and click [b]Finish[/b]. \r\nYou will notice that the new package appears in the project directory. Now you can move and create classes inside that package. We have moved our [b]Vehicle[/b], [b]Counter [/b]and [b]Animal [/b]classes to the package [b]samples[/b]. [img id=\"2868\" width=\"50%\"]\r\nWhen you move/create a class in your package, the following code will appear at the top of the list of files.[code format=\"java\" ][b]package [/b]samples;[/code]\r\nThis indicates the package to which the class belongs.\r\nNow, we need to import the classes that are inside a package in our main to be able to use them.\r\nThe following example shows how to use the [b]Vehicle [/b]class of the [b]samples [/b]package. [code format=\"java\" ][b]import samples.Vehicle;[/b]\r\n\r\nclass MyClass {\r\n public static void main(String[ ] args) {\r\n Vehicle v1 = new Vehicle();\r\n v1.horn();\r\n }\r\n}[/code]\r\nTwo major results occur when a class is placed in a package. First, the name of the package becomes a part of the name of the class.\r\nSecond, the name of the package must match the directory structure where the corresponding class file resides.\r\n[note]Use a wildcard to import all classes in a package.\r\nFor example, [b]import samples.* [/b]will import all classes in the samples package.[/note]"
3029 }
3030 ]
3031 }
3032 },
3033 {
3034 "lesson": {
3035 "id": 2235,
3036 "name": "Module 4 Quiz",
3037 "type": 1,
3038 "mode": 0,
3039 "videoID": null,
3040 "tags": null,
3041 "quizzes": [
3042 {
3043 "id": 4453,
3044 "number": 1,
3045 "videoStart": 0,
3046 "videoEnd": 0,
3047 "linkedVideoID": null,
3048 "type": 2,
3049 "linkedQuizID": null,
3050 "tip": null,
3051 "hint": null,
3052 "time": 0,
3053 "answers": [
3054 {
3055 "id": 28938,
3056 "text": "void",
3057 "isCorrect": false,
3058 "properties": {
3059 "prefix": "public ",
3060 "postfix": " calc()"
3061 }
3062 }
3063 ],
3064 "question": "Fill in the blank to define a method that does not return a value.",
3065 "textContent": null
3066 },
3067 {
3068 "id": 4454,
3069 "number": 2,
3070 "videoStart": 0,
3071 "videoEnd": 0,
3072 "linkedVideoID": null,
3073 "type": 1,
3074 "linkedQuizID": null,
3075 "tip": null,
3076 "hint": null,
3077 "time": 0,
3078 "answers": [
3079 {
3080 "id": 105995,
3081 "text": "private",
3082 "isCorrect": false,
3083 "properties": {}
3084 },
3085 {
3086 "id": 105996,
3087 "text": "public",
3088 "isCorrect": true,
3089 "properties": {}
3090 },
3091 {
3092 "id": 105997,
3093 "text": "default",
3094 "isCorrect": false,
3095 "properties": {}
3096 },
3097 {
3098 "id": 105998,
3099 "text": "static",
3100 "isCorrect": false,
3101 "properties": {}
3102 }
3103 ],
3104 "question": "Which access modifier explicitly says that a method or variable of an object can be accessed by code from outside of the class of that object?",
3105 "textContent": null
3106 },
3107 {
3108 "id": 4455,
3109 "number": 3,
3110 "videoStart": 0,
3111 "videoEnd": 0,
3112 "linkedVideoID": null,
3113 "type": 8,
3114 "linkedQuizID": null,
3115 "tip": null,
3116 "hint": null,
3117 "time": 0,
3118 "answers": [
3119 {
3120 "id": 28948,
3121 "text": "public int max(int a, int b) {",
3122 "isCorrect": false,
3123 "properties": {}
3124 },
3125 {
3126 "id": 28949,
3127 "text": " if (a > b) {",
3128 "isCorrect": false,
3129 "properties": {}
3130 },
3131 {
3132 "id": 28950,
3133 "text": " return a; }",
3134 "isCorrect": false,
3135 "properties": {}
3136 },
3137 {
3138 "id": 28951,
3139 "text": "return b;",
3140 "isCorrect": false,
3141 "properties": {}
3142 },
3143 {
3144 "id": 28952,
3145 "text": "}",
3146 "isCorrect": false,
3147 "properties": {}
3148 }
3149 ],
3150 "question": "Rearrange the code to declare a method returning the greater of the two arguments.",
3151 "textContent": null
3152 },
3153 {
3154 "id": 4456,
3155 "number": 4,
3156 "videoStart": 0,
3157 "videoEnd": 0,
3158 "linkedVideoID": null,
3159 "type": 3,
3160 "linkedQuizID": null,
3161 "tip": null,
3162 "hint": null,
3163 "time": 0,
3164 "answers": [
3165 {
3166 "id": 29253,
3167 "text": "int",
3168 "isCorrect": false,
3169 "properties": {
3170 "prefix": "",
3171 "postfix": ""
3172 }
3173 },
3174 {
3175 "id": 29254,
3176 "text": "{",
3177 "isCorrect": false,
3178 "properties": {
3179 "prefix": "",
3180 "postfix": ""
3181 }
3182 },
3183 {
3184 "id": 29255,
3185 "text": "}",
3186 "isCorrect": false,
3187 "properties": {
3188 "prefix": "",
3189 "postfix": ""
3190 }
3191 }
3192 ],
3193 "question": "Fill in the blanks to declare a method that takes one argument of type int.\r\n[!raw!]\r\npublic int myFunc({0} x) {1}\r\n return x*10;\r\n{2}",
3194 "textContent": null
3195 },
3196 {
3197 "id": 4457,
3198 "number": 5,
3199 "videoStart": 0,
3200 "videoEnd": 0,
3201 "linkedVideoID": null,
3202 "type": 3,
3203 "linkedQuizID": null,
3204 "tip": null,
3205 "hint": null,
3206 "time": 0,
3207 "answers": [
3208 {
3209 "id": 29256,
3210 "text": ")",
3211 "isCorrect": false,
3212 "properties": {
3213 "prefix": "",
3214 "postfix": ""
3215 }
3216 },
3217 {
3218 "id": 29257,
3219 "text": "n2",
3220 "isCorrect": false,
3221 "properties": {
3222 "prefix": "",
3223 "postfix": ""
3224 }
3225 },
3226 {
3227 "id": 29258,
3228 "text": "else",
3229 "isCorrect": false,
3230 "properties": {
3231 "prefix": "",
3232 "postfix": ""
3233 }
3234 },
3235 {
3236 "id": 29259,
3237 "text": "return",
3238 "isCorrect": false,
3239 "properties": {
3240 "prefix": "",
3241 "postfix": ""
3242 }
3243 }
3244 ],
3245 "question": "Fill in the blanks to create a method that returns the minimum of the two parameters.\r\n[!raw!]\r\npublic int minFunc(int n1, int n2{0} {\r\n int min;\r\n if (n1 > n2)\r\n min = {1};\r\n {2}\r\n min = n1;\r\n\r\n {3} min; \r\n}",
3246 "textContent": null
3247 },
3248 {
3249 "id": 4458,
3250 "number": 6,
3251 "videoStart": 0,
3252 "videoEnd": 0,
3253 "linkedVideoID": null,
3254 "type": 3,
3255 "linkedQuizID": null,
3256 "tip": null,
3257 "hint": null,
3258 "time": 0,
3259 "answers": [
3260 {
3261 "id": 29260,
3262 "text": "class",
3263 "isCorrect": false,
3264 "properties": {
3265 "prefix": "",
3266 "postfix": ""
3267 }
3268 },
3269 {
3270 "id": 29261,
3271 "text": "{",
3272 "isCorrect": false,
3273 "properties": {
3274 "prefix": "",
3275 "postfix": ""
3276 }
3277 },
3278 {
3279 "id": 29262,
3280 "text": "void",
3281 "isCorrect": false,
3282 "properties": {
3283 "prefix": "",
3284 "postfix": ""
3285 }
3286 },
3287 {
3288 "id": 29263,
3289 "text": "()",
3290 "isCorrect": false,
3291 "properties": {
3292 "prefix": "",
3293 "postfix": ""
3294 }
3295 }
3296 ],
3297 "question": "Fill in the blanks to create a class with a method called \"myFunc\" that takes no parameters, returns void, and prints \"Hi\" to the screen.\r\n[!raw!]\r\npublic {0} myClass {1}\r\n public {2} myFunc{3} {\r\n System.out.println(''Hi'');\r\n }\r\n}",
3298 "textContent": null
3299 }
3300 ]
3301 }
3302 },
3303 {
3304 "lesson": {
3305 "id": 2166,
3306 "name": "Abstract Classes",
3307 "type": 0,
3308 "mode": 1,
3309 "videoID": "AU07jJc_qMQ",
3310 "tags": "abstract-classes",
3311 "quizzes": [
3312 {
3313 "id": 4277,
3314 "number": 1,
3315 "videoStart": 14,
3316 "videoEnd": 197,
3317 "linkedVideoID": null,
3318 "type": 1,
3319 "linkedQuizID": null,
3320 "tip": null,
3321 "hint": null,
3322 "time": 0,
3323 "answers": [
3324 {
3325 "id": 92749,
3326 "text": "True",
3327 "isCorrect": true,
3328 "properties": {}
3329 },
3330 {
3331 "id": 92750,
3332 "text": "False",
3333 "isCorrect": false,
3334 "properties": {}
3335 }
3336 ],
3337 "question": "A class containing an abstract method is an abstract class.",
3338 "textContent": "[h1]Abstraction[/h1]\r\n\r\nData [b]abstraction [/b]provides the outside world with only essential information, in a process of representing essential features without including implementation details.\r\nA good real-world example is a [i]book[/i]. When you hear the term book, you don't know the exact specifics, such as the page count, the color, or the size, but you understand the idea, or abstraction, of a book.\r\nThe concept of [b]abstraction [/b]is that we focus on essential qualities, rather than the specific characteristics of one particular example.\r\n\r\nIn Java, abstraction is achieved using [b]abstract classes[/b] and [b]interfaces[/b].\r\nAn abstract class is defined using the [b]abstract [/b]keyword.\r\n- If a class is declared abstract it cannot be instantiated (you cannot create objects of that type).\r\n- To use an abstract class, you have to inherit it from another class.\r\n- Any class that contains an abstract method should be defined as abstract.\r\n[note]An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon): [b]abstract void walk();[/b][/note]"
3339 },
3340 {
3341 "id": 4279,
3342 "number": 2,
3343 "videoStart": 197,
3344 "videoEnd": 420,
3345 "linkedVideoID": null,
3346 "type": 3,
3347 "linkedQuizID": null,
3348 "tip": null,
3349 "hint": null,
3350 "time": 0,
3351 "answers": [
3352 {
3353 "id": 101843,
3354 "text": "abstract",
3355 "isCorrect": false,
3356 "properties": {
3357 "prefix": "",
3358 "postfix": ""
3359 }
3360 },
3361 {
3362 "id": 101844,
3363 "text": "extends",
3364 "isCorrect": false,
3365 "properties": {
3366 "prefix": "",
3367 "postfix": ""
3368 }
3369 },
3370 {
3371 "id": 101845,
3372 "text": "int",
3373 "isCorrect": false,
3374 "properties": {
3375 "prefix": "",
3376 "postfix": ""
3377 }
3378 }
3379 ],
3380 "question": "Fill in the blanks to create an abstract class with an abstract method and inherit from it.\r\n[!raw!]\r\nabstract class Animal {\r\n public int age;\r\n public {0} int printAge();\r\n}\r\nclass Dog {1} Animal {\r\n public {2} printAge() {\r\n return age;\r\n }\t\r\n}",
3381 "textContent": "[h1]Abstract Class[/h1]\r\n\r\nFor example, we can define our Animal class as abstract: [code format=\"java\" ][b]abstract [/b]class Animal {\r\n int legs = 0;\r\n [b]abstract [/b]void makeSound();\r\n}[/code]\r\nThe makeSound method is also abstract, as it has no implementation in the superclass.\r\nWe can inherit from the Animal class and define the makeSound() method for the subclass:[code format=\"java\" codeId=\"777\"]class Cat extends Animal {\r\n public void makeSound() {\r\n System.out.println(\"Meow\");\r\n }\r\n}[/code]\r\n[note]Every Animal makes a sound, but each has a different way to do it. That's why we define an abstract class Animal, and leave the implementation of how they make sounds to the subclasses. \r\nThis is used when there is no meaningful definition for the method in the superclass.[/note]"
3382 }
3383 ]
3384 }
3385 },
3386 {
3387 "lesson": {
3388 "id": 2167,
3389 "name": "Interfaces",
3390 "type": 0,
3391 "mode": 1,
3392 "videoID": "AU07jJc_qMQ",
3393 "tags": "interfaces",
3394 "quizzes": [
3395 {
3396 "id": 4280,
3397 "number": 1,
3398 "videoStart": 425,
3399 "videoEnd": 632,
3400 "linkedVideoID": null,
3401 "type": 1,
3402 "linkedQuizID": null,
3403 "tip": null,
3404 "hint": null,
3405 "time": 0,
3406 "answers": [
3407 {
3408 "id": 95522,
3409 "text": "only one",
3410 "isCorrect": true,
3411 "properties": {}
3412 },
3413 {
3414 "id": 95523,
3415 "text": "none",
3416 "isCorrect": false,
3417 "properties": {}
3418 },
3419 {
3420 "id": 95524,
3421 "text": "multiple",
3422 "isCorrect": false,
3423 "properties": {}
3424 },
3425 {
3426 "id": 95525,
3427 "text": "only two",
3428 "isCorrect": false,
3429 "properties": {}
3430 }
3431 ],
3432 "question": "In Java, how many superclasses can your inherited subclass have?",
3433 "textContent": "[h1]Interfaces[/h1]\r\n\r\nAn [b]interface [/b]is a completely abstract class that contains only abstract methods.\r\nSome specifications for interfaces:\r\n- Defined using the [b]interface [/b]keyword.\r\n- May contain only static final variables.\r\n- Cannot contain a constructor because interfaces cannot be instantiated.\r\n- Interfaces can extend other interfaces.\r\n- A class can implement any number of interfaces.\r\n\r\nAn example of a simple interface:[code format=\"java\"][b]interface [/b]Animal {\r\n public void eat();\r\n public void makeSound();\r\n}[/code]\r\nInterfaces have the following properties:\r\n- An interface is implicitly abstract. You do not need to use the abstract keyword while declaring an interface.\r\n- Each method in an interface is also implicitly abstract, so the abstract keyword is not needed.\r\n- Methods in an interface are implicitly public.\r\n[note]A class can inherit from just [b]one [/b]superclass, but can implement [b]multiple [/b]interfaces![/note]"
3434 },
3435 {
3436 "id": 4281,
3437 "number": 2,
3438 "videoStart": 631.5,
3439 "videoEnd": 744,
3440 "linkedVideoID": null,
3441 "type": 6,
3442 "linkedQuizID": null,
3443 "tip": null,
3444 "hint": null,
3445 "time": 0,
3446 "answers": [
3447 {
3448 "id": 99615,
3449 "text": "class",
3450 "isCorrect": true,
3451 "properties": {}
3452 },
3453 {
3454 "id": 99616,
3455 "text": "Animal",
3456 "isCorrect": true,
3457 "properties": {}
3458 },
3459 {
3460 "id": 99617,
3461 "text": "void",
3462 "isCorrect": true,
3463 "properties": {}
3464 },
3465 {
3466 "id": 99618,
3467 "text": "return",
3468 "isCorrect": false,
3469 "properties": {}
3470 },
3471 {
3472 "id": 99619,
3473 "text": "abstract",
3474 "isCorrect": false,
3475 "properties": {}
3476 },
3477 {
3478 "id": 99620,
3479 "text": "Cat",
3480 "isCorrect": false,
3481 "properties": {}
3482 }
3483 ],
3484 "question": "Fill in the blanks to implement an interface.\r\n[!raw!]\r\ninterface Animal {\r\n public void eat();\r\n}\r\n{0} Cat implements {1} {\r\n public {2} eat() {\r\n System.out.println(\"Cat eats\");\r\n }\r\n}",
3485 "textContent": "[h1]Interfaces[/h1]\r\n\r\nUse the [b]implements [/b]keyword to use an interface with your class.[code format=\"java\" codeId=\"778\"]interface Animal {\r\n public void eat();\r\n public void makeSound();\r\n}\r\n\r\nclass Cat [b]implements [/b]Animal {\r\n public void makeSound() {\r\n System.out.println(\"Meow\");\r\n }\r\n public void eat() {\r\n System.out.println(\"omnomnom\");\r\n }\r\n}[/code]\r\n[note]When you implement an interface, you need to override all of its methods.[/note]"
3486 }
3487 ]
3488 }
3489 },
3490 {
3491 "lesson": {
3492 "id": 2168,
3493 "name": "Casting",
3494 "type": 0,
3495 "mode": 1,
3496 "videoID": "qJ5Dc8eLyqA",
3497 "tags": "casting",
3498 "quizzes": [
3499 {
3500 "id": 4282,
3501 "number": 1,
3502 "videoStart": 36,
3503 "videoEnd": 179,
3504 "linkedVideoID": null,
3505 "type": 2,
3506 "linkedQuizID": null,
3507 "tip": null,
3508 "hint": null,
3509 "time": 0,
3510 "answers": [
3511 {
3512 "id": 100264,
3513 "text": "3",
3514 "isCorrect": false,
3515 "properties": {
3516 "prefix": "",
3517 "postfix": ""
3518 }
3519 }
3520 ],
3521 "question": "What is the output of this code?\r\npublic static void main(String[ ] args) {\t\r\n double x = 1.5;\r\n double y = 2.65;\r\n sum((int)x, (int)y);\r\n}\r\nstatic void sum(int x, int y) {\r\n System.out.println(x + y);\r\n}",
3522 "textContent": "[h1]Type Casting[/h1]\r\n\r\nAssigning a value of one type to a variable of another type is known as [b]Type Casting[/b].\r\n\r\nTo cast a value to a specific type, place the type in parentheses and position it in front of the value.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"779\"]int a = [b](int)[/b] 3.14;\r\nSystem.out.println(a);\r\n//Outputs 3[/code]\r\nThe code above is casting the value 3.14 to an integer, with 3 as the resulting value.\r\n[b]Another example:[/b] [code format=\"java\" codeId=\"780\"]double a = 42.571;\r\nint b = [b](int) [/b]a;\r\nSystem.out.println(b);\r\n//Outputs 42[/code]\r\n[note]Java supports automatic type casting of integers to floating points, since there is no loss of precision.\r\nOn the other hand, type casting is mandatory when assigning floating point values to integer variables.[/note]"
3523 }
3524 ]
3525 }
3526 },
3527 {
3528 "lesson": {
3529 "id": 2169,
3530 "name": "Downcasting",
3531 "type": 0,
3532 "mode": 1,
3533 "videoID": "9UylOdopV6k",
3534 "tags": "casting",
3535 "quizzes": [
3536 {
3537 "id": 4285,
3538 "number": 1,
3539 "videoStart": 0,
3540 "videoEnd": 175,
3541 "linkedVideoID": null,
3542 "type": 1,
3543 "linkedQuizID": null,
3544 "tip": null,
3545 "hint": null,
3546 "time": 0,
3547 "answers": [
3548 {
3549 "id": 100265,
3550 "text": "B",
3551 "isCorrect": true,
3552 "properties": {}
3553 },
3554 {
3555 "id": 100266,
3556 "text": "A",
3557 "isCorrect": false,
3558 "properties": {}
3559 },
3560 {
3561 "id": 100267,
3562 "text": "nothing",
3563 "isCorrect": false,
3564 "properties": {}
3565 }
3566 ],
3567 "question": "What is the output of this code?\r\nclass A {\r\n public void print() {\r\n System.out.println(\"A\");\r\n }\r\n}\r\nclass B extends A {\r\n public void print() {\r\n System.out.println(\"B\");\r\n }\r\n public static void main(String[ ] args) {\r\n A object = new B();\r\n B b = (B) object;\r\n b.print();\r\n }\r\n}",
3568 "textContent": "[h1]Type Casting[/h1]\r\n\r\nFor classes, there are two types of casting.\r\n\r\n[h2]Upcasting[/h2]\r\nYou can cast an instance of a subclass to its superclass.\r\nConsider the following example, assuming that Cat is a subclass of Animal. [code format=\"java\" ]Animal a = new Cat();[/code]\r\nJava automatically upcasted the Cat type variable to the Animal type.\r\n\r\n[h2]Downcasting[/h2]\r\nCasting an object of a superclass to its subclass is called [b]downcasting[/b].\r\nExample: [code format=\"java\" ]Animal a = new Animal();\r\n([b](Cat)[/b]a).makeSound();[/code]\r\nThis will try to cast the variable a to the [b]Cat [/b]type and call its makeSound() method.\r\n[note]Why is upcasting automatic, downcasting manual? Well, upcasting can never fail. But if you have a group of different Animals and want to downcast them all to a Cat, then there's a chance that some of these Animals are actually Dogs, so the process fails.[/note]"
3569 }
3570 ]
3571 }
3572 },
3573 {
3574 "lesson": {
3575 "id": 2172,
3576 "name": "Anonymous Classes",
3577 "type": 0,
3578 "mode": 1,
3579 "videoID": "ihAzMaUFjgY",
3580 "tags": "anonymous-classes",
3581 "quizzes": [
3582 {
3583 "id": 4294,
3584 "number": 1,
3585 "videoStart": 26,
3586 "videoEnd": 215,
3587 "linkedVideoID": null,
3588 "type": 3,
3589 "linkedQuizID": null,
3590 "tip": null,
3591 "hint": null,
3592 "time": 0,
3593 "answers": [
3594 {
3595 "id": 99628,
3596 "text": "new",
3597 "isCorrect": false,
3598 "properties": {
3599 "prefix": "",
3600 "postfix": ""
3601 }
3602 },
3603 {
3604 "id": 99629,
3605 "text": "@",
3606 "isCorrect": false,
3607 "properties": {
3608 "prefix": "",
3609 "postfix": ""
3610 }
3611 },
3612 {
3613 "id": 99630,
3614 "text": "start",
3615 "isCorrect": false,
3616 "properties": {
3617 "prefix": "",
3618 "postfix": ""
3619 }
3620 }
3621 ],
3622 "question": "Fill in the blanks to override the start method of the Machine class.\r\n[!raw!]\r\nMachine m = {0} Machine() {\r\n {1}Override public void {2}() {\r\n System.out.println(\"Hi\");\r\n }\r\n}",
3623 "textContent": "[h1]Anonymous Classes[/h1]\r\n\r\n[b]Anonymous classes[/b] are a way to extend the existing classes on the fly.\r\nFor example, consider having a class Machine: [code format=\"java\" ]class Machine {\r\n public void start() {\r\n System.out.println(\"Starting...\");\r\n }\r\n}[/code]\r\nWhen creating the Machine object, we can change the start method on the fly.[code format=\"java\" codeId=\"782\"]public static void main(String[ ] args) {\r\n Machine m = new Machine() {\r\n @Override public void start() {\r\n System.out.println(\"Wooooo\");\r\n }\r\n };\r\n m.start();\r\n}\r\n//Outputs \"Wooooo\";[/code]\r\nAfter the constructor call, we have opened the curly braces and have overridden the [b]start [/b]method's implementation on the fly. \r\n[note]The [b]@Override[/b] annotation is used to make your code easier to understand, because it makes it more obvious when methods are overridden.[/note]"
3624 },
3625 {
3626 "id": 4295,
3627 "number": 2,
3628 "videoStart": 216,
3629 "videoEnd": 277,
3630 "linkedVideoID": null,
3631 "type": 6,
3632 "linkedQuizID": null,
3633 "tip": null,
3634 "hint": null,
3635 "time": 0,
3636 "answers": [
3637 {
3638 "id": 105194,
3639 "text": "A",
3640 "isCorrect": true,
3641 "properties": {}
3642 },
3643 {
3644 "id": 105195,
3645 "text": "new",
3646 "isCorrect": true,
3647 "properties": {}
3648 },
3649 {
3650 "id": 105196,
3651 "text": "print",
3652 "isCorrect": true,
3653 "properties": {}
3654 },
3655 {
3656 "id": 105197,
3657 "text": "\"Hello\"",
3658 "isCorrect": true,
3659 "properties": {}
3660 },
3661 {
3662 "id": 105198,
3663 "text": "String",
3664 "isCorrect": false,
3665 "properties": {}
3666 },
3667 {
3668 "id": 105199,
3669 "text": "extends",
3670 "isCorrect": false,
3671 "properties": {}
3672 },
3673 {
3674 "id": 105200,
3675 "text": "B",
3676 "isCorrect": false,
3677 "properties": {}
3678 }
3679 ],
3680 "question": "Fill in the blanks to print \"Hello\".\r\n[!raw!]\r\nclass A {\r\n public void print() {\r\n System.out.println(\"A\");\r\n }\t\t\r\n}\r\nclass B {\t\t\t\t\r\n public static void main(String[ ] args) {\t\r\n {0} object = {1} A() {\r\n @Override public void {2}() {\r\n System.out.println({3});\r\n }\r\n };\r\n object.print();\r\n }\t\t\r\n}",
3681 "textContent": "[h1]Anonymous Classes[/h1]\r\n\r\nThe modification is applicable only to the current object, and not the class itself. So if we create another object of that class, the start method's implementation will be the one defined in the class.[code format=\"java\" codeId=\"783\"]class Machine {\r\n public void start() {\r\n System.out.println(\"Starting...\");\r\n }\r\n} \r\npublic static void main(String[ ] args) {\r\n Machine m1 = new Machine() {\r\n @Override public void start() {\r\n System.out.println(\"Wooooo\");\r\n }\r\n };\r\n Machine m2 = new Machine();\r\n m2.start();\r\n }\r\n//Outputs \"Starting...\"[/code]"
3682 }
3683 ]
3684 }
3685 },
3686 {
3687 "lesson": {
3688 "id": 2173,
3689 "name": "Inner Classes",
3690 "type": 0,
3691 "mode": 1,
3692 "videoID": "DZWlO1jCVas",
3693 "tags": "inner-classes",
3694 "quizzes": [
3695 {
3696 "id": 4296,
3697 "number": 1,
3698 "videoStart": 155,
3699 "videoEnd": 308,
3700 "linkedVideoID": null,
3701 "type": 8,
3702 "linkedQuizID": null,
3703 "tip": null,
3704 "hint": null,
3705 "time": 0,
3706 "answers": [
3707 {
3708 "id": 99638,
3709 "text": "public class Person {",
3710 "isCorrect": false,
3711 "properties": {}
3712 },
3713 {
3714 "id": 99639,
3715 "text": " class Hand {",
3716 "isCorrect": false,
3717 "properties": {}
3718 },
3719 {
3720 "id": 99640,
3721 "text": " public void shake() {",
3722 "isCorrect": false,
3723 "properties": {}
3724 },
3725 {
3726 "id": 99641,
3727 "text": " System.out.println(\"Hi\"); }",
3728 "isCorrect": false,
3729 "properties": {}
3730 },
3731 {
3732 "id": 99642,
3733 "text": " } }",
3734 "isCorrect": false,
3735 "properties": {}
3736 }
3737 ],
3738 "question": "Rearrange the code to have an inner class Hand, which has a method called \"shake\" that prints \"Hi\".",
3739 "textContent": "[h1]Inner Classes[/h1]\r\n\r\nJava supports [b]nesting [/b]classes; a class can be a member of another class.\r\nCreating an inner class is quite simple. Just write a class within a class. Unlike a class, an inner class can be private. Once you declare an inner class private, it cannot be accessed from an object outside the class.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"784\"]class Robot {\r\n int id;\r\n Robot(int i) {\r\n id = i;\r\n Brain b = new Brain();\r\n b.think();\r\n }\r\n\r\n [b] private class Brain {\r\n public void think() {\r\n System.out.println(id + \" is thinking\");\r\n }\r\n }\r\n[/b]\r\n}[/code]\r\n[note]The class [b]Robot [/b]has an inner class [b]Brain[/b]. The inner class can access all of the member variables and methods of its outer class, but it cannot be accessed from any outside class.[/note]"
3740 }
3741 ]
3742 }
3743 },
3744 {
3745 "lesson": {
3746 "id": 2178,
3747 "name": "The equals() method",
3748 "type": 0,
3749 "mode": 1,
3750 "videoID": "kk4e1kjzb7Q",
3751 "tags": "equals",
3752 "quizzes": [
3753 {
3754 "id": 4308,
3755 "number": 1,
3756 "videoStart": 108,
3757 "videoEnd": 228,
3758 "linkedVideoID": null,
3759 "type": 1,
3760 "linkedQuizID": null,
3761 "tip": null,
3762 "hint": null,
3763 "time": 0,
3764 "answers": [
3765 {
3766 "id": 106617,
3767 "text": "true",
3768 "isCorrect": false,
3769 "properties": {}
3770 },
3771 {
3772 "id": 106618,
3773 "text": "false",
3774 "isCorrect": true,
3775 "properties": {}
3776 },
3777 {
3778 "id": 106619,
3779 "text": "undefined",
3780 "isCorrect": false,
3781 "properties": {}
3782 }
3783 ],
3784 "question": "What is the output of this code?\r\nclass A {\r\n private int x;\t\r\n public static void main(String[ ] args) {\r\n A a = new A();\r\n a.x = 5;\r\n A b = new A();\r\n b.x = 5;\r\n System.out.println(a == b);\t\t\t\r\n }\r\n}",
3785 "textContent": "[h1]Comparing Objects[/h1]\r\n\r\nRemember that when you create objects, the variables store references to the objects.\r\nSo, when you compare objects using the equality testing operator ([b]==[/b]), it actually compares the references and not the object values.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"785\"]class Animal {\r\n String name;\r\n Animal(String n) {\r\n name = n;\r\n }\r\n}\r\n\r\nclass MyClass {\r\n public static void main(String[ ] args) {\r\n Animal a1 = new Animal(\"Robby\");\r\n Animal a2 = new Animal(\"Robby\");\r\n System.out.println([b]a1 == a2[/b]);\r\n }\r\n}\r\n//Outputs [b]false[/b][/code]\r\n[note]Despite having two objects with the same name, the equality testing returns false, because we have two different objects (two different references or memory locations).[/note]"
3786 },
3787 {
3788 "id": 4309,
3789 "number": 2,
3790 "videoStart": 228,
3791 "videoEnd": 454,
3792 "linkedVideoID": null,
3793 "type": 6,
3794 "linkedQuizID": null,
3795 "tip": null,
3796 "hint": null,
3797 "time": 0,
3798 "answers": [
3799 {
3800 "id": 100278,
3801 "text": "boolean",
3802 "isCorrect": true,
3803 "properties": {}
3804 },
3805 {
3806 "id": 100279,
3807 "text": "return",
3808 "isCorrect": true,
3809 "properties": {}
3810 },
3811 {
3812 "id": 100280,
3813 "text": "A",
3814 "isCorrect": true,
3815 "properties": {}
3816 },
3817 {
3818 "id": 100281,
3819 "text": "equals",
3820 "isCorrect": true,
3821 "properties": {}
3822 },
3823 {
3824 "id": 100282,
3825 "text": "b",
3826 "isCorrect": false,
3827 "properties": {}
3828 },
3829 {
3830 "id": 100283,
3831 "text": "new",
3832 "isCorrect": false,
3833 "properties": {}
3834 },
3835 {
3836 "id": 100284,
3837 "text": "x",
3838 "isCorrect": false,
3839 "properties": {}
3840 }
3841 ],
3842 "question": "Fill in the blanks to check whether the two objects of type A are semantically equal.\r\n[!raw!]\r\nclass A {\r\n private int x;\r\n public {0} equals(Object o) {\r\n {1} ((A)o).x == this.x;\r\n }\t\r\n public static void main(String[ ] args) {\r\n A a = new A();\r\n a.x = 9;\r\n A b = new {2}();\r\n b.x = 5;\r\n System.out.println(a.{3}(b));\r\n }\r\n}",
3843 "textContent": "[h1][b]equals()[/b][/h1]\r\n\r\nEach object has a predefined [b]equals[/b]() method that is used for semantical equality testing.\r\nBut, to make it work for our classes, we need to override it and check the conditions we need.\r\nThere is a simple and fast way of generating the equals() method, other than writing it manually.\r\nJust right click in your class, go to [b]Source[/b]->[b]Generate hashCode() and equals()...[/b] [img id=\"2439\" width=\"100%\"]\r\nThis will automatically create the necessary methods. [code format=\"java\" ]class Animal {\r\n String name;\r\n Animal(String n) {\r\n name = n;\r\n }\r\n @Override\r\n public int hashCode() {\r\n final int prime = 31;\r\n int result = 1;\r\n result = prime * result + ((name == null) ? 0 : name.hashCode());\r\n return result;\r\n }\r\n @Override\r\n public boolean [b]equals[/b](Object obj) {\r\n if (this == obj)\r\n return true;\r\n if (obj == null)\r\n return false;\r\n if (getClass() != obj.getClass())\r\n return false;\r\n Animal other = (Animal) obj;\r\n if (name == null) {\r\n if (other.name != null)\r\n return false;\r\n } else if (!name.equals(other.name))\r\n return false;\r\n return true;\r\n }\r\n}[/code]\r\nThe automatically generated hashCode() method is used to determine where to store the object internally. Whenever you implement [b]equals[/b], you MUST also implement [b]hashCode[/b].\r\nWe can run the test again, using the [b]equals [/b]method:[code format=\"java\" codeId=\"786\"]public static void main(String[ ] args) {\r\n Animal a1 = new Animal(\"Robby\");\r\n Animal a2 = new Animal(\"Robby\");\r\n System.out.println(a1.equals(a2));\r\n}\r\n//Outputs [b]true[/b][/code]\r\n[note]You can use the same menu to generate other useful methods, such as [b]getters [/b]and [b]setters [/b]for your class attributes.[/note]"
3844 }
3845 ]
3846 }
3847 },
3848 {
3849 "lesson": {
3850 "id": 2174,
3851 "name": "Enums",
3852 "type": 0,
3853 "mode": 1,
3854 "videoID": "A0GHaVRlYAQ",
3855 "tags": "enums",
3856 "quizzes": [
3857 {
3858 "id": 4448,
3859 "number": 1,
3860 "videoStart": 14,
3861 "videoEnd": 199,
3862 "linkedVideoID": null,
3863 "type": 1,
3864 "linkedQuizID": null,
3865 "tip": null,
3866 "hint": null,
3867 "time": 0,
3868 "answers": [
3869 {
3870 "id": 95571,
3871 "text": "classes",
3872 "isCorrect": false,
3873 "properties": {}
3874 },
3875 {
3876 "id": 95572,
3877 "text": "members of a fixed set",
3878 "isCorrect": true,
3879 "properties": {}
3880 },
3881 {
3882 "id": 95573,
3883 "text": "interfaces",
3884 "isCorrect": false,
3885 "properties": {}
3886 },
3887 {
3888 "id": 95574,
3889 "text": "integers",
3890 "isCorrect": false,
3891 "properties": {}
3892 }
3893 ],
3894 "question": "Enums are used to declare variables that represent...",
3895 "textContent": "[h1]Enums[/h1]\r\n\r\nAn Enum is a special type used to define collections of constants. \r\nHere is a simple Enum example: [code format=\"java\"][b]enum [/b]Rank {\r\n SOLDIER,\r\n SERGEANT,\r\n CAPTAIN\r\n}[/code]\r\nNote that the values are [b]comma-separated.[/b]\r\nYou can refer to the constants in the enum above with the [b]dot [/b]syntax. [code format=\"java\"]Rank a = Rank[b].SOLDIER[/b];[/code]\r\n[note]Basically, Enums define variables that represent members of a fixed set.[/note]"
3896 },
3897 {
3898 "id": 4299,
3899 "number": 2,
3900 "videoStart": 199,
3901 "videoEnd": 337,
3902 "linkedVideoID": null,
3903 "type": 6,
3904 "linkedQuizID": null,
3905 "tip": null,
3906 "hint": null,
3907 "time": 0,
3908 "answers": [
3909 {
3910 "id": 99665,
3911 "text": "enum",
3912 "isCorrect": true,
3913 "properties": {}
3914 },
3915 {
3916 "id": 99666,
3917 "text": "BLUE",
3918 "isCorrect": true,
3919 "properties": {}
3920 },
3921 {
3922 "id": 99667,
3923 "text": "RED",
3924 "isCorrect": false,
3925 "properties": {}
3926 },
3927 {
3928 "id": 99668,
3929 "text": "GREEN",
3930 "isCorrect": false,
3931 "properties": {}
3932 },
3933 {
3934 "id": 99669,
3935 "text": "static",
3936 "isCorrect": false,
3937 "properties": {}
3938 },
3939 {
3940 "id": 99670,
3941 "text": "class",
3942 "isCorrect": false,
3943 "properties": {}
3944 }
3945 ],
3946 "question": "Fill in the blanks to create an Enum called \"Color\", with the values RED, BLUE, GREEN.\r\n[!raw!]\r\npublic {0} Color {\r\n RED, {1}, GREEN;\r\n}",
3947 "textContent": "[h1]Enums[/h1]\r\n\r\nAfter declaring an Enum, we can check for the corresponding values with, for example, a [b]switch [/b]statement.[code format=\"java\" codeId=\"787\"]Rank a = Rank.SOLDIER;\r\n\r\nswitch(a) {\r\n case SOLDIER:\r\n System.out.println(\"Soldier says hi!\");\r\n break;\r\n case SERGEANT:\r\n System.out.println(\"Sergeant says Hello!\");\r\n break;\r\n case CAPTAIN:\r\n System.out.println(\"Captain says Welcome!\");\r\n break;\r\n}\r\n//Outputs \"Soldier says hi!\"[/code]"
3948 },
3949 {
3950 "id": 4300,
3951 "number": 3,
3952 "videoStart": 337,
3953 "videoEnd": 450.5,
3954 "linkedVideoID": null,
3955 "type": 2,
3956 "linkedQuizID": null,
3957 "tip": null,
3958 "hint": null,
3959 "time": 0,
3960 "answers": [
3961 {
3962 "id": 100285,
3963 "text": "0",
3964 "isCorrect": false,
3965 "properties": {
3966 "prefix": "",
3967 "postfix": ""
3968 }
3969 }
3970 ],
3971 "question": "What is the output of this code?\r\nenum Color {\r\n RED, BLUE, GREEN;\r\n}\r\nclass PrintColor {\r\n public static void main(String[ ] args) {\r\n Color color = Color.RED; \r\n switch(color) {\r\n case BLUE:\r\n System.out.println(\"1\");\r\n break;\r\n case GREEN:\r\n System.out.println(\"2\");\r\n break;\r\n default:\r\n System.out.println(\"0\");\r\n break;\t\t \r\n }\r\n}\r\n}",
3972 "textContent": "[h1]Enums[/h1]\r\n\r\nYou should always use Enums when a variable (especially a method parameter) can only take one out of a small set of possible values.\r\nIf you use Enums instead of integers (or String codes), you increase compile-time checking and avoid errors from passing in invalid constants, and you document which values are legal to use.\r\n[note]Some sample Enum uses include month names, days of the week, deck of cards, etc.[/note]"
3973 }
3974 ]
3975 }
3976 },
3977 {
3978 "lesson": {
3979 "id": 2170,
3980 "name": "Using the Java API",
3981 "type": 0,
3982 "mode": 1,
3983 "videoID": "Ji9Za_HnfVs",
3984 "tags": "api",
3985 "quizzes": [
3986 {
3987 "id": 4287,
3988 "number": 1,
3989 "videoStart": 25,
3990 "videoEnd": 233,
3991 "linkedVideoID": null,
3992 "type": 3,
3993 "linkedQuizID": null,
3994 "tip": null,
3995 "hint": null,
3996 "time": 0,
3997 "answers": [
3998 {
3999 "id": 99971,
4000 "text": "import",
4001 "isCorrect": false,
4002 "properties": {
4003 "prefix": "",
4004 "postfix": ""
4005 }
4006 },
4007 {
4008 "id": 99972,
4009 "text": "*",
4010 "isCorrect": false,
4011 "properties": {
4012 "prefix": "",
4013 "postfix": ""
4014 }
4015 }
4016 ],
4017 "question": "Fill in the blank to import all types in the package awt.\r\n[!raw!]\r\n{0} java.awt.{1};",
4018 "textContent": "[h1]Java API[/h1]\r\n\r\nThe Java API is a collection of classes and interfaces that have been written for you to use.\r\nThe Java API Documentation with all of the available APIs can be located on the Oracle website at \r\n[b]http://docs.oracle.com/javase/7/docs/api/[/b]\r\nOnce you locate the package you want to use, you need to import it into your code.\r\nThe package can be imported using the import keyword.\r\n[b]For example:[/b] [code format=\"java\" ]import java.awt.*;[/code]\r\nThe [b]awt [/b]package contains all of the classes for creating user interfaces and for painting graphics and images.\r\n[note]The wildcard character (*) is used to import all of the classes in the package.[/note]"
4019 }
4020 ]
4021 }
4022 },
4023 {
4024 "lesson": {
4025 "id": 2171,
4026 "name": "Module 5 Quiz",
4027 "type": 1,
4028 "mode": 0,
4029 "videoID": null,
4030 "tags": null,
4031 "quizzes": [
4032 {
4033 "id": 4291,
4034 "number": 1,
4035 "videoStart": 0,
4036 "videoEnd": 0,
4037 "linkedVideoID": null,
4038 "type": 2,
4039 "linkedQuizID": null,
4040 "tip": null,
4041 "hint": null,
4042 "time": 0,
4043 "answers": [
4044 {
4045 "id": 100289,
4046 "text": "c",
4047 "isCorrect": false,
4048 "properties": {
4049 "prefix": "",
4050 "postfix": ""
4051 }
4052 }
4053 ],
4054 "question": "What is the output of this code?\r\nclass A {\r\n private void print() {\r\n System.out.println(''a'');\r\n }\r\n private void print(String str) {\r\n System.out.println(''b'');\r\n }\r\n private void print(int x) {\r\n System.out.println(''c'');\r\n }\t\t\r\n public static void main(String[ ] args) {\t\r\n A object = new A();\r\n object.print(12);\t\r\n }\t\r\n}",
4055 "textContent": null
4056 },
4057 {
4058 "id": 4425,
4059 "number": 2,
4060 "videoStart": 0,
4061 "videoEnd": 0,
4062 "linkedVideoID": null,
4063 "type": 3,
4064 "linkedQuizID": null,
4065 "tip": null,
4066 "hint": null,
4067 "time": 0,
4068 "answers": [
4069 {
4070 "id": 29349,
4071 "text": "class",
4072 "isCorrect": false,
4073 "properties": {
4074 "prefix": "",
4075 "postfix": ""
4076 }
4077 },
4078 {
4079 "id": 29350,
4080 "text": "extends",
4081 "isCorrect": false,
4082 "properties": {
4083 "prefix": "",
4084 "postfix": ""
4085 }
4086 }
4087 ],
4088 "question": "Fill in the blanks to define a new class Falcon, based on the superclass Bird.\r\n[!raw!]\r\n{0} Falcon {1} Bird {\r\n }",
4089 "textContent": null
4090 },
4091 {
4092 "id": 4426,
4093 "number": 3,
4094 "videoStart": 0,
4095 "videoEnd": 0,
4096 "linkedVideoID": null,
4097 "type": 1,
4098 "linkedQuizID": null,
4099 "tip": null,
4100 "hint": null,
4101 "time": 0,
4102 "answers": [
4103 {
4104 "id": 29351,
4105 "text": "References",
4106 "isCorrect": true,
4107 "properties": {}
4108 },
4109 {
4110 "id": 29352,
4111 "text": "Objects",
4112 "isCorrect": false,
4113 "properties": {}
4114 },
4115 {
4116 "id": 29353,
4117 "text": "Classes",
4118 "isCorrect": false,
4119 "properties": {}
4120 },
4121 {
4122 "id": 29354,
4123 "text": "Strings",
4124 "isCorrect": false,
4125 "properties": {}
4126 }
4127 ],
4128 "question": "Object variables store...",
4129 "textContent": null
4130 },
4131 {
4132 "id": 4427,
4133 "number": 4,
4134 "videoStart": 0,
4135 "videoEnd": 0,
4136 "linkedVideoID": null,
4137 "type": 1,
4138 "linkedQuizID": null,
4139 "tip": null,
4140 "hint": null,
4141 "time": 0,
4142 "answers": [
4143 {
4144 "id": 91994,
4145 "text": "Encapsulation",
4146 "isCorrect": true,
4147 "properties": {}
4148 },
4149 {
4150 "id": 91995,
4151 "text": "Polymorphism",
4152 "isCorrect": false,
4153 "properties": {}
4154 },
4155 {
4156 "id": 91996,
4157 "text": "Data Mining",
4158 "isCorrect": false,
4159 "properties": {}
4160 },
4161 {
4162 "id": 91997,
4163 "text": "Inheritance",
4164 "isCorrect": false,
4165 "properties": {}
4166 }
4167 ],
4168 "question": "What term is used for hiding the details of an object from the other parts of a program?",
4169 "textContent": null
4170 },
4171 {
4172 "id": 4430,
4173 "number": 5,
4174 "videoStart": 0,
4175 "videoEnd": 0,
4176 "linkedVideoID": null,
4177 "type": 1,
4178 "linkedQuizID": null,
4179 "tip": null,
4180 "hint": null,
4181 "time": 0,
4182 "answers": [
4183 {
4184 "id": 29359,
4185 "text": "The run() method defined in BMW will be called.",
4186 "isCorrect": true,
4187 "properties": {}
4188 },
4189 {
4190 "id": 29360,
4191 "text": "The run() method defined in Car will be called.",
4192 "isCorrect": false,
4193 "properties": {}
4194 },
4195 {
4196 "id": 29361,
4197 "text": "The compiler will complain that run() has been defined twice.",
4198 "isCorrect": false,
4199 "properties": {}
4200 }
4201 ],
4202 "question": "A class Car and its subclass BMW each have a method run(), which was written by the developer as part of the class definition. If CarObj refers to an object of type BMW, what will CarObj.run(); do?",
4203 "textContent": null
4204 },
4205 {
4206 "id": 4431,
4207 "number": 6,
4208 "videoStart": 0,
4209 "videoEnd": 0,
4210 "linkedVideoID": null,
4211 "type": 1,
4212 "linkedQuizID": null,
4213 "tip": null,
4214 "hint": null,
4215 "time": 0,
4216 "answers": [
4217 {
4218 "id": 90934,
4219 "text": "Card",
4220 "isCorrect": true,
4221 "properties": {}
4222 },
4223 {
4224 "id": 90935,
4225 "text": "Birthday",
4226 "isCorrect": false,
4227 "properties": {}
4228 },
4229 {
4230 "id": 90936,
4231 "text": "Holiday",
4232 "isCorrect": false,
4233 "properties": {}
4234 },
4235 {
4236 "id": 90937,
4237 "text": "Valentine",
4238 "isCorrect": false,
4239 "properties": {}
4240 }
4241 ],
4242 "question": "Valentine, Holiday, and Birthday inherit from the class Card. In order for the following code to be correct, what type must the reference variable card be?\r\ncard = new Valentine( \"A\", 14 ) ;\r\ncard.greeting();\r\n\r\ncard = new Holiday( \"B\" ) ;\r\ncard.greeting();\r\n\r\ncard = new Birthday( \"C\", 12 ) ;\r\ncard.greeting();",
4243 "textContent": null
4244 }
4245 ]
4246 }
4247 },
4248 {
4249 "lesson": {
4250 "id": 2180,
4251 "name": "LinkedLists",
4252 "type": 0,
4253 "mode": 1,
4254 "videoID": "1cCByj85yQc",
4255 "tags": "linkedlist",
4256 "quizzes": [
4257 {
4258 "id": 4313,
4259 "number": 1,
4260 "videoStart": 71,
4261 "videoEnd": 146,
4262 "linkedVideoID": null,
4263 "type": 6,
4264 "linkedQuizID": null,
4265 "tip": null,
4266 "hint": null,
4267 "time": 0,
4268 "answers": [
4269 {
4270 "id": 99699,
4271 "text": "LinkedList",
4272 "isCorrect": true,
4273 "properties": {}
4274 },
4275 {
4276 "id": 99700,
4277 "text": "<String>",
4278 "isCorrect": true,
4279 "properties": {}
4280 },
4281 {
4282 "id": 99701,
4283 "text": "\"Hey\"",
4284 "isCorrect": true,
4285 "properties": {}
4286 },
4287 {
4288 "id": 99702,
4289 "text": "0",
4290 "isCorrect": true,
4291 "properties": {}
4292 },
4293 {
4294 "id": 99703,
4295 "text": "ArrayList",
4296 "isCorrect": false,
4297 "properties": {}
4298 },
4299 {
4300 "id": 99704,
4301 "text": "1",
4302 "isCorrect": false,
4303 "properties": {}
4304 },
4305 {
4306 "id": 99705,
4307 "text": "\"Bye\"",
4308 "isCorrect": false,
4309 "properties": {}
4310 }
4311 ],
4312 "question": "Fill in the blanks to create a LinkedList, add \"Hey\", and print it.\r\n[!raw!]\r\n{0}<String> list = \r\n new LinkedList{1}();\r\nlist.add({2});\r\nSystem.out.println(list.get({3}));",
4313 "textContent": "[h1]LinkedList[/h1]\r\n\r\nThe [b]LinkedList [/b]is very similar in syntax to the [b]ArrayList[/b].\r\nYou can easily change an ArrayList to a LinkedList by changing the object type. [code format=\"java\" codeId=\"794\"]import java.util.[b]LinkedList[/b];\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]LinkedList[/b]<String> c = new [b]LinkedList[/b]<String>();\r\n c.add(\"Red\");\r\n c.add(\"Blue\");\r\n c.add(\"Green\");\r\n c.add(\"Orange\");\r\n c.remove(\"Green\");\r\n System.out.println(c);\r\n }\r\n}\r\n// Outputs [Red, Blue, Orange][/code]\r\n[note]You cannot specify an initial capacity for the [b]LinkedList[/b].[/note]"
4314 },
4315 {
4316 "id": 4314,
4317 "number": 2,
4318 "videoStart": 146,
4319 "videoEnd": 223,
4320 "linkedVideoID": null,
4321 "type": 1,
4322 "linkedQuizID": null,
4323 "tip": null,
4324 "hint": null,
4325 "time": 0,
4326 "answers": [
4327 {
4328 "id": 106123,
4329 "text": "LinkedList",
4330 "isCorrect": true,
4331 "properties": {}
4332 },
4333 {
4334 "id": 106124,
4335 "text": "ArrayList",
4336 "isCorrect": false,
4337 "properties": {}
4338 }
4339 ],
4340 "question": "For a program with large numbers of inserts and deletes, it is better to use the...",
4341 "textContent": "[h1]LinkedList vs. ArrayList[/h1]\r\n\r\nThe most notable difference between the [b]LinkedList [/b]and the [b]ArrayList [/b]is in the way they store objects.\r\nThe ArrayList is better for [b]storing [/b]and [b]accessing [/b]data, as it is very similar to a normal array.\r\nThe LinkedList is better for [b]manipulating [/b]data, such as making numerous inserts and deletes.\r\n\r\nIn addition to storing the object, the LinkedList stores the memory address (or link) of the element that follows it. It's called a LinkedList because each element contains a link to the neighboring element. [img id=\"2443\" width=\"100%\"]\r\nYou can use the enhanced for loop to iterate over its elements. [code format=\"java\" codeId=\"795\"]LinkedList<String> c = new LinkedList<String>();\r\nc.add(\"Red\");\r\nc.add(\"Blue\");\r\nc.add(\"Green\");\r\nc.add(\"Orange\");\r\nc.remove(\"Green\");\r\n\r\nfor(String s: c) {\r\n System.out.println(s);\r\n}\r\n/* Output:\r\nRed\r\nBlue\r\nOrange\r\n */[/code]\r\n[note]Summary:\r\n- Use an [b]ArrayList [/b]when you need rapid access to your data. \r\n- Use a [b]LinkedList [/b]when you need to make a large number of inserts and/or deletes.[/note]"
4342 }
4343 ]
4344 }
4345 },
4346 {
4347 "lesson": {
4348 "id": 2181,
4349 "name": "HashMap",
4350 "type": 0,
4351 "mode": 1,
4352 "videoID": "-JOSjIan2g0",
4353 "tags": "hashmap",
4354 "quizzes": [
4355 {
4356 "id": 4315,
4357 "number": 1,
4358 "videoStart": 27,
4359 "videoEnd": 263,
4360 "linkedVideoID": null,
4361 "type": 1,
4362 "linkedQuizID": null,
4363 "tip": null,
4364 "hint": null,
4365 "time": 0,
4366 "answers": [
4367 {
4368 "id": 100306,
4369 "text": "Second",
4370 "isCorrect": true,
4371 "properties": {}
4372 },
4373 {
4374 "id": 100307,
4375 "text": "First",
4376 "isCorrect": false,
4377 "properties": {}
4378 },
4379 {
4380 "id": 100308,
4381 "text": "Third",
4382 "isCorrect": false,
4383 "properties": {}
4384 },
4385 {
4386 "id": 100309,
4387 "text": "Nothing",
4388 "isCorrect": false,
4389 "properties": {}
4390 }
4391 ],
4392 "question": "What is the output of this code?\r\nimport java.util.HashMap;\r\nclass A {\t\r\n public static void main(String[ ] args) {\r\n HashMap<String, String> m = new HashMap<String, String>();\r\n m.put(\"A\", \"First\");\r\n m.put(\"B\", \"Second\");\r\n m.put(\"C\", \"Third\");\r\n System.out.println(m.get(\"B\"));\r\n }\r\n}",
4393 "textContent": "[h1]HashMap[/h1]\r\n\r\nArrays and Lists store elements as ordered collections, with each element given an integer index.\r\n[b]HashMap [/b]is used for storing data collections as key and value pairs. One object is used as a key (index) to another object (the value). \r\nThe [b]put[/b], [b]remove[/b], and [b]get [/b]methods are used to add, delete, and access values in the HashMap.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"796\"][b]import java.util.HashMap;[/b]\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]HashMap[/b]<String, Integer> points = new [b]HashMap[/b]<String, Integer>();\r\n points.[b]put[/b](\"Amy\", 154);\r\n points.[b]put[/b](\"Dave\", 42);\r\n points.[b]put[/b](\"Rob\", 733);\r\n System.out.println(points.[b]get[/b](\"Dave\")); \r\n }\r\n}\r\n// Outputs 42[/code]\r\nWe have created a HashMap with Strings as its keys and Integers as its values.\r\n[note]Use the [b]get [/b]method and the corresponding key to access the HashMap elements.[/note]"
4394 },
4395 {
4396 "id": 4316,
4397 "number": 2,
4398 "videoStart": 263,
4399 "videoEnd": 335,
4400 "linkedVideoID": null,
4401 "type": 3,
4402 "linkedQuizID": null,
4403 "tip": null,
4404 "hint": null,
4405 "time": 0,
4406 "answers": [
4407 {
4408 "id": 93378,
4409 "text": "new",
4410 "isCorrect": false,
4411 "properties": {
4412 "prefix": "",
4413 "postfix": ""
4414 }
4415 },
4416 {
4417 "id": 93379,
4418 "text": "put",
4419 "isCorrect": false,
4420 "properties": {
4421 "prefix": "",
4422 "postfix": ""
4423 }
4424 },
4425 {
4426 "id": 93380,
4427 "text": "get",
4428 "isCorrect": false,
4429 "properties": {
4430 "prefix": "",
4431 "postfix": ""
4432 }
4433 }
4434 ],
4435 "question": "Fill in the blanks to declare a HashMap, add two items, and print one of them.\r\n[!raw!]\r\nHashMap<String, String> m = \r\n {0} HashMap<String, String>();\r\nm.put(\"A\", \"First\");\r\nm.{1}(\"B\", \"Second\");\r\nSystem.out.println(m.{2}(\"B\"));",
4436 "textContent": "[h1]HashMap[/h1]\r\n\r\nA [b]HashMap [/b]cannot contain duplicate keys. Adding a new item with a key that already exists overwrites the old element.\r\nThe HashMap class provides [b]containsKey [/b]and [b]containsValue [/b]methods that determine the presence of a specified key or value.\r\nIf you try to get a value that is not present your map, it returns the value of [b]null[/b]. \r\n[note][b]null [/b]is a special type that represents the absence of a value.[/note]"
4437 }
4438 ]
4439 }
4440 },
4441 {
4442 "lesson": {
4443 "id": 2182,
4444 "name": "Sets",
4445 "type": 0,
4446 "mode": 1,
4447 "videoID": "fZgO3R3V_jw",
4448 "tags": "sets",
4449 "quizzes": [
4450 {
4451 "id": 4318,
4452 "number": 1,
4453 "videoStart": 77,
4454 "videoEnd": 135,
4455 "linkedVideoID": null,
4456 "type": 2,
4457 "linkedQuizID": null,
4458 "tip": null,
4459 "hint": null,
4460 "time": 0,
4461 "answers": [
4462 {
4463 "id": 106125,
4464 "text": "3",
4465 "isCorrect": false,
4466 "properties": {
4467 "prefix": "",
4468 "postfix": ""
4469 }
4470 }
4471 ],
4472 "question": "What is the output of this code?\r\nimport java.util.HashSet;\r\nclass A {\r\n public static void main(String[ ] args) {\r\n HashSet<String> set = new HashSet<String>();\r\n set.add(\"A\");\r\n set.add(\"B\");\t\r\n set.add(\"C\");\r\n System.out.println(set.size());\r\n }\r\n}",
4473 "textContent": "[h1]Sets[/h1]\r\n\r\nA [b]Set [/b]is a collection that cannot contain duplicate elements. It models the mathematical set abstraction.\r\nOne of the implementations of the Set is the [b]HashSet [/b]class.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"797\"][b]import java.util.HashSet;[/b]\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n [b]HashSet[/b]<String> set = new [b]HashSet[/b]<String>();\r\n set.add(\"A\");\r\n set.add(\"B\");\r\n set.add(\"C\");\r\n System.out.println(set);\r\n }\r\n}\r\n// Output: [A, B, C][/code]\r\n[note]You can use the [b]size[/b]() method to get the number of elements in the HashSet.[/note]"
4474 },
4475 {
4476 "id": 4319,
4477 "number": 2,
4478 "videoStart": 151,
4479 "videoEnd": 264,
4480 "linkedVideoID": null,
4481 "type": 1,
4482 "linkedQuizID": null,
4483 "tip": null,
4484 "hint": null,
4485 "time": 0,
4486 "answers": [
4487 {
4488 "id": 106126,
4489 "text": "Set contains only unique values.",
4490 "isCorrect": true,
4491 "properties": {}
4492 },
4493 {
4494 "id": 106127,
4495 "text": "HashSet does not retain order.",
4496 "isCorrect": true,
4497 "properties": {}
4498 },
4499 {
4500 "id": 106128,
4501 "text": "LinkedHashSet does not retain order.",
4502 "isCorrect": false,
4503 "properties": {}
4504 },
4505 {
4506 "id": 106129,
4507 "text": "Set can contain duplicate values.",
4508 "isCorrect": false,
4509 "properties": {}
4510 }
4511 ],
4512 "question": "Which two of the following statements are true?",
4513 "textContent": "[h1]LinkedHashSet[/h1]\r\n\r\nThe HashSet class does not automatically retain the order of the elements as they're added. To order the elements, use a [b]LinkedHashSet[/b], which maintains a linked list of the set's elements in the order in which they were inserted.\r\n\r\n[b]What is hashing?[/b]\r\nA hash table stores information through a mechanism called hashing, in which a key's informational content is used to determine a unique value called a hash code.\r\nSo, basically, each element in the HashSet is associated with its unique hash code. \r\n[note]You've learned about the various collection types that are available in Java, including [b]Lists[/b], [b]Maps[/b], and [b]Sets[/b]. The choice of which one to use is specific to the data you need to store and manipulate.[/note]"
4514 }
4515 ]
4516 }
4517 },
4518 {
4519 "lesson": {
4520 "id": 2183,
4521 "name": "Sorting Lists",
4522 "type": 0,
4523 "mode": 1,
4524 "videoID": "QYvUmIYgsiA",
4525 "tags": "lists",
4526 "quizzes": [
4527 {
4528 "id": 4320,
4529 "number": 1,
4530 "videoStart": 37,
4531 "videoEnd": 161.5,
4532 "linkedVideoID": null,
4533 "type": 2,
4534 "linkedQuizID": null,
4535 "tip": null,
4536 "hint": null,
4537 "time": 0,
4538 "answers": [
4539 {
4540 "id": 99719,
4541 "text": "a",
4542 "isCorrect": false,
4543 "properties": {
4544 "prefix": "",
4545 "postfix": ""
4546 }
4547 }
4548 ],
4549 "question": "What is the output of this code?\r\nList<String> list = new ArrayList<String>();\r\nlist.add(\"b\");\r\nlist.add(\"a\");\r\nlist.add(\"c\");\r\nCollections.sort(list);\r\nSystem.out.println(list.get(0));",
4550 "textContent": "[h1]Sorting Lists[/h1]\r\n\r\nFor the manipulation of data in different collection types, the Java API provides a [b]Collections [/b]class, which is included in the java.util package. \r\nOne of the most popular [b]Collections [/b]class methods is [b]sort[/b](), which sorts the elements of your collection type. The methods in the [b]Collections [/b]class are [b]static[/b], so you don't need a Collections object to call them.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"798\"]public class MyClass {\r\n public static void main(String[ ] args) {\r\n ArrayList<String> animals = new ArrayList<String>();\r\n animals.add(\"tiger\");\r\n animals.add(\"cat\");\r\n animals.add(\"snake\");\r\n animals.add(\"dog\");\r\n \r\n[b] Collections.sort(animals);[/b]\r\n \r\n System.out.println(animals);\r\n }\r\n}\r\n/* Outputs:\r\n[cat, dog, snake, tiger]\r\n*/[/code]\r\n[note]As you can see, the elements have been sorted alphabetically.[/note]"
4551 },
4552 {
4553 "id": 4321,
4554 "number": 2,
4555 "videoStart": 161.5,
4556 "videoEnd": 256,
4557 "linkedVideoID": null,
4558 "type": 3,
4559 "linkedQuizID": null,
4560 "tip": null,
4561 "hint": null,
4562 "time": 0,
4563 "answers": [
4564 {
4565 "id": 99720,
4566 "text": "add",
4567 "isCorrect": false,
4568 "properties": {
4569 "prefix": "",
4570 "postfix": ""
4571 }
4572 },
4573 {
4574 "id": 99721,
4575 "text": "list",
4576 "isCorrect": false,
4577 "properties": {
4578 "prefix": "",
4579 "postfix": ""
4580 }
4581 },
4582 {
4583 "id": 99722,
4584 "text": "sort",
4585 "isCorrect": false,
4586 "properties": {
4587 "prefix": "",
4588 "postfix": ""
4589 }
4590 },
4591 {
4592 "id": 99723,
4593 "text": "1",
4594 "isCorrect": false,
4595 "properties": {
4596 "prefix": "",
4597 "postfix": ""
4598 }
4599 }
4600 ],
4601 "question": "Fill in the blanks to add three items to the list, sort it, and print 2.\r\n[!raw!]\r\nList<Integer> list = new ArrayList<Integer>();\r\nlist.{0}(4);\r\nlist.add(2);\r\n{1}.add(1);\r\nCollections.{2}(list);\r\nSystem.out.println(list.get({3}));",
4602 "textContent": "[h1]Sorting Lists[/h1]\r\n\r\nYou can call the [b]sort[/b]() methods on different types of Lists, such as Integers.[code format=\"java\" codeId=\"799\"]import java.util.ArrayList;\r\nimport java.util.Collections;\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n ArrayList<Integer> nums = new ArrayList<Integer>();\r\n nums.add(3);\r\n nums.add(36);\r\n nums.add(73);\r\n nums.add(40);\r\n nums.add(1);\r\n\r\n [b]Collections.sort(nums);[/b]\r\n System.out.println(nums);\r\n }\r\n}\r\n/* Outputs:\r\n[1, 3, 36, 40, 73]\r\n*/[/code]\r\n[note]Other useful methods in the [b]Collections [/b]class:\r\n[b]max[/b](Collection c): Returns the maximum element in c as determined by natural ordering.\r\n[b]min[/b](Collection c): Returns the minimum element in c as determined by natural ordering.\r\n[b]reverse[/b](List list): Reverses the sequence in list.\r\n[b]shuffle[/b](List list): Shuffles (i.e., randomizes) the elements in list.[/note]"
4603 }
4604 ]
4605 }
4606 },
4607 {
4608 "lesson": {
4609 "id": 2184,
4610 "name": "Iterators",
4611 "type": 0,
4612 "mode": 1,
4613 "videoID": "o9ZYhHdZJNY",
4614 "tags": "iterators",
4615 "quizzes": [
4616 {
4617 "id": 4322,
4618 "number": 1,
4619 "videoStart": 21,
4620 "videoEnd": 320,
4621 "linkedVideoID": null,
4622 "type": 2,
4623 "linkedQuizID": null,
4624 "tip": null,
4625 "hint": null,
4626 "time": 0,
4627 "answers": [
4628 {
4629 "id": 99724,
4630 "text": "20",
4631 "isCorrect": false,
4632 "properties": {
4633 "prefix": "",
4634 "postfix": ""
4635 }
4636 }
4637 ],
4638 "question": "What is the output of this code?\r\nList<Integer> list = new ArrayList<Integer>();\r\nlist.add(10);\r\nlist.add(20);\r\nlist.add(30);\r\nIterator<Integer> it = list.iterator();\r\nit.next();\r\nSystem.out.println(it.next());",
4639 "textContent": "[h1]Iterators\r\n[/h1]\r\nAn [b]Iterator [/b]is an object that enables to cycle through a collection, obtain or remove elements. \r\nBefore you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an [b]iterator[/b]() method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time.\r\n\r\nThe Iterator class provides the following methods:\r\n[b]hasNext[/b](): Returns true if there is at least one more element; otherwise, it returns false.\r\n[b]next[/b](): Returns the next object and advances the iterator.\r\n[b]remove[/b](): Removes the last object that was returned by next from the collection.\r\n\r\nThe Iterator class must be imported from the[b] java.util[/b] package.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"800\"][b]import java.util.Iterator;[/b]\r\nimport java.util.LinkedList;\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n LinkedList<String> animals = new LinkedList<String>();\r\n animals.add(\"fox\");\r\n animals.add(\"cat\");\r\n animals.add(\"dog\");\r\n animals.add(\"rabbit\");\r\n\r\n [b]Iterator<String> it = animals.iterator();[/b]\r\n String value = [b]it.next();[/b]\r\n System.out.println(value);\r\n}\r\n}\r\n//Outputs \"fox\"[/code]\r\n[note][b]it.next()[/b] returns the first element in the list and then moves the iterator on to the next element.\r\nEach time you call [b]it.next()[/b], the iterator moves to the next element of the list.[/note]"
4640 },
4641 {
4642 "id": 4323,
4643 "number": 2,
4644 "videoStart": 320,
4645 "videoEnd": 358,
4646 "linkedVideoID": null,
4647 "type": 6,
4648 "linkedQuizID": null,
4649 "tip": null,
4650 "hint": null,
4651 "time": 0,
4652 "answers": [
4653 {
4654 "id": 99725,
4655 "text": "Iterator",
4656 "isCorrect": true,
4657 "properties": {}
4658 },
4659 {
4660 "id": 99726,
4661 "text": "Integer",
4662 "isCorrect": true,
4663 "properties": {}
4664 },
4665 {
4666 "id": 99727,
4667 "text": "iterator",
4668 "isCorrect": true,
4669 "properties": {}
4670 },
4671 {
4672 "id": 99728,
4673 "text": "hasNext",
4674 "isCorrect": true,
4675 "properties": {}
4676 },
4677 {
4678 "id": 99729,
4679 "text": "next",
4680 "isCorrect": true,
4681 "properties": {}
4682 }
4683 ],
4684 "question": "Fill in the blanks to iterate and print all of the items in the list of Integers.\r\n[!raw!]\r\n{0}<{1}> it = list.{2}();\r\nwhile (it.{3}()) {\r\n System.out.println(it.{4}());\t\r\n}",
4685 "textContent": "[h1]Iterators[/h1]\r\n\r\n[b][/b]Typically, [b]iterators [/b]are used in loops. At each iteration of the loop, you can access the corresponding list element.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"801\"]import java.util.Iterator;\r\nimport java.util.LinkedList;\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n LinkedList<String> animals = new LinkedList<String>();\r\n animals.add(\"fox\");\r\n animals.add(\"cat\");\r\n animals.add(\"dog\");\r\n animals.add(\"rabbit\");\r\n \r\n Iterator<String> it = animals.iterator();\r\n [b] while(it.hasNext()) {\r\n String value = it.next();\r\n System.out.println(value); \r\n }[/b]\r\n }\r\n}\r\n/*\r\nfox\r\ncat\r\ndog\r\nrabbit\r\n*/[/code]\r\n[note]Here, the [b]while [/b]loop determines whether the iterator has additional elements, prints the value of the element, and advances the iterator to the next.[/note]"
4686 }
4687 ]
4688 }
4689 },
4690 {
4691 "lesson": {
4692 "id": 2186,
4693 "name": "Working with Files",
4694 "type": 0,
4695 "mode": 1,
4696 "videoID": "7fC9nL3_AQQ",
4697 "tags": "files",
4698 "quizzes": [
4699 {
4700 "id": 4326,
4701 "number": 1,
4702 "videoStart": 24,
4703 "videoEnd": 353,
4704 "linkedVideoID": null,
4705 "type": 3,
4706 "linkedQuizID": null,
4707 "tip": null,
4708 "hint": null,
4709 "time": 0,
4710 "answers": [
4711 {
4712 "id": 95642,
4713 "text": "new",
4714 "isCorrect": false,
4715 "properties": {
4716 "prefix": "",
4717 "postfix": ""
4718 }
4719 },
4720 {
4721 "id": 95643,
4722 "text": "exists",
4723 "isCorrect": false,
4724 "properties": {
4725 "prefix": "",
4726 "postfix": ""
4727 }
4728 }
4729 ],
4730 "question": "Fill in the blanks to determine whether the file exists.\r\n[!raw!]\r\nclass A {\r\n public static void main(String args[ ]) {\r\n File file = {0} File(\"a.txt\");\r\n if(file.{1}()) {\r\n System.out.println(\"Yes\");\r\n }\r\n}\r\n}",
4731 "textContent": "[h1]Working with Files[/h1]\r\n\r\nThe [b]java.io[/b] package includes a [b]File [/b]class that allows you to work with files.\r\nTo start, create a [b]File [/b]object and specify the path of the file in the constructor. [code format=\"java\"][b]import java.io.File;[/b]\r\n...\r\n[b]File [/b]file = new [b]File[/b](\"C:\\\\data\\\\input-file.txt\");[/code]\r\nWith the [b]exists[/b]() method, you can determine whether a file exists.[code format=\"java\"]import java.io.File;\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n File x = new File(\"C:\\\\sololearn\\\\test.txt\");\r\n if(x.[b]exists[/b]()) {\r\n System.out.println(x.getName() + \"exists!\");\r\n }\r\n else { \r\n System.out.println(\"The file does not exist\");\r\n }\r\n }\r\n}[/code]\r\nThe code above prints a message stating whether or not the file exists at the specified path.\r\n[note]The [b]getName[/b]() method returns the name of the file.\r\nNote that we used double backslashes in the path, as one backslash should be escaped in the path String.[/note]"
4732 }
4733 ]
4734 }
4735 },
4736 {
4737 "lesson": {
4738 "id": 2187,
4739 "name": "Reading a File",
4740 "type": 0,
4741 "mode": 1,
4742 "videoID": "3RNYUKxAgmw",
4743 "tags": "files",
4744 "quizzes": [
4745 {
4746 "id": 4328,
4747 "number": 1,
4748 "videoStart": 5,
4749 "videoEnd": 106,
4750 "linkedVideoID": null,
4751 "type": 1,
4752 "linkedQuizID": null,
4753 "tip": null,
4754 "hint": null,
4755 "time": 0,
4756 "answers": [
4757 {
4758 "id": 95648,
4759 "text": "ArrayList",
4760 "isCorrect": false,
4761 "properties": {}
4762 },
4763 {
4764 "id": 95649,
4765 "text": "HashMap",
4766 "isCorrect": false,
4767 "properties": {}
4768 },
4769 {
4770 "id": 95650,
4771 "text": "Scanner",
4772 "isCorrect": true,
4773 "properties": {}
4774 },
4775 {
4776 "id": 95651,
4777 "text": "Set",
4778 "isCorrect": false,
4779 "properties": {}
4780 }
4781 ],
4782 "question": "Which class can be used for reading files?",
4783 "textContent": "[h1]Reading a File[/h1]\r\n\r\nFiles are useful for storing and retrieving data, and there are a number of ways to read from a files.\r\n One of the simplest ways is to use the [b]Scanner [/b]class from the [b]java.util[/b] package.\r\nThe constructor of the [b]Scanner [/b]class can take a [b]File [/b]object as input.\r\nTo read the contents of a text file at the path \"C:\\\\sololearn\\\\test.txt\", we would need to create a File object with the corresponding path and pass it to the Scanner object.[code format=\"java\"]try {\r\n [b]File [/b]x = new [b]File[/b](\"C:\\\\sololearn\\\\test.txt\");\r\n [b]Scanner [/b]sc = new [b]Scanner[/b](x); \r\n}\r\n catch (FileNotFoundException e) {\r\n\r\n}[/code]\r\n[note]We surrounded the code with a try/catch block, because there's a chance that the file may not exist.[/note]"
4784 },
4785 {
4786 "id": 4329,
4787 "number": 2,
4788 "videoStart": 106,
4789 "videoEnd": 380,
4790 "linkedVideoID": null,
4791 "type": 6,
4792 "linkedQuizID": null,
4793 "tip": null,
4794 "hint": null,
4795 "time": 0,
4796 "answers": [
4797 {
4798 "id": 95652,
4799 "text": "Scanner",
4800 "isCorrect": true,
4801 "properties": {}
4802 },
4803 {
4804 "id": 95653,
4805 "text": "sc",
4806 "isCorrect": true,
4807 "properties": {}
4808 },
4809 {
4810 "id": 95654,
4811 "text": "next",
4812 "isCorrect": true,
4813 "properties": {}
4814 },
4815 {
4816 "id": 95655,
4817 "text": "close",
4818 "isCorrect": true,
4819 "properties": {}
4820 },
4821 {
4822 "id": 95656,
4823 "text": "File",
4824 "isCorrect": false,
4825 "properties": {}
4826 },
4827 {
4828 "id": 95657,
4829 "text": "new",
4830 "isCorrect": false,
4831 "properties": {}
4832 }
4833 ],
4834 "question": "Fill in the blanks to read and print the content of the file a.txt, and then close it.\r\n[!raw!]\r\ntry {\r\n File f = new File(\"a.txt\");\r\n Scanner sc = new {0}(f);\r\n while (sc.hasNext()) {\r\n String a = {1}.next();\r\n String b = sc.{2}();\r\n System.out.println(a + \" \" + b);\r\n } \r\n sc.{3}();\r\n} \r\ncatch (Exception e) {\r\n System.out.println(\"Error\");\r\n}",
4835 "textContent": "[h1]Reading a File[/h1]\r\n\r\nThe [b]Scanner [/b]class inherits from the [b]Iterator[/b], so it behaves like one.\r\nWe can use the Scanner object's [b]next[/b]() method to read the file's contents. [code format=\"java\"]try {\r\n File x = new File(\"C:\\\\sololearn\\\\test.txt\");\r\n Scanner sc = new Scanner(x);\r\n [b] while(sc.hasNext()) {\r\n System.out.println(sc.next());\r\n }\r\n[/b] sc.close();\r\n} catch (FileNotFoundException e) {\r\n System.out.println(\"Error\");\r\n}[/code]\r\nThe file's contents are output word by word, because the [b]next[/b]() method returns each word separately.\r\n[note]It is always good practice to close a file when finished working with it. One way to do this is to use the Scanner's [b]close[/b]() method.[/note]"
4836 }
4837 ]
4838 }
4839 },
4840 {
4841 "lesson": {
4842 "id": 2188,
4843 "name": "Creating & Writing Files",
4844 "type": 0,
4845 "mode": 1,
4846 "videoID": "Bws9aQuAcdg",
4847 "tags": "files",
4848 "quizzes": [
4849 {
4850 "id": 4330,
4851 "number": 1,
4852 "videoStart": 26,
4853 "videoEnd": 154,
4854 "linkedVideoID": null,
4855 "type": 1,
4856 "linkedQuizID": null,
4857 "tip": null,
4858 "hint": null,
4859 "time": 0,
4860 "answers": [
4861 {
4862 "id": 95658,
4863 "text": "ArrayList",
4864 "isCorrect": false,
4865 "properties": {}
4866 },
4867 {
4868 "id": 95659,
4869 "text": "Formatter",
4870 "isCorrect": true,
4871 "properties": {}
4872 },
4873 {
4874 "id": 95660,
4875 "text": "Scanner",
4876 "isCorrect": false,
4877 "properties": {}
4878 },
4879 {
4880 "id": 95661,
4881 "text": "Set",
4882 "isCorrect": false,
4883 "properties": {}
4884 }
4885 ],
4886 "question": "Which class is used to write content to files?",
4887 "textContent": "[h1]Creating Files[/h1]\r\n\r\n[b]Formatter[/b], another useful class in the java.util package, is used to create content and write it to files.\r\n[b]Example:[/b][code format=\"java\"][b]import java.util.Formatter;[/b]\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n try {\r\n [b]Formatter [/b]f = new [b]Formatter[/b](\"C:\\\\sololearn\\\\test.txt\");\r\n } catch (Exception e) {\r\n System.out.println(\"Error\");\r\n }\r\n }\r\n}[/code]\r\nThis creates an empty file at the specified path. If the file already exists, this will overwrite it.\r\n[note]Again, you need to surround the code with a [b]try/catch[/b] block, as the operation can fail.[/note]"
4888 },
4889 {
4890 "id": 4331,
4891 "number": 2,
4892 "videoStart": 154,
4893 "videoEnd": 407,
4894 "linkedVideoID": null,
4895 "type": 8,
4896 "linkedQuizID": null,
4897 "tip": null,
4898 "hint": null,
4899 "time": 0,
4900 "answers": [
4901 {
4902 "id": 99734,
4903 "text": "Formatter f = new Formatter(\"a.txt\");",
4904 "isCorrect": true,
4905 "properties": {}
4906 },
4907 {
4908 "id": 99735,
4909 "text": "f.format(\"%s\", \"Hi \");",
4910 "isCorrect": true,
4911 "properties": {}
4912 },
4913 {
4914 "id": 99736,
4915 "text": "f.format(\"%s\", \"there\");",
4916 "isCorrect": true,
4917 "properties": {}
4918 },
4919 {
4920 "id": 99737,
4921 "text": "f.close();",
4922 "isCorrect": true,
4923 "properties": {}
4924 }
4925 ],
4926 "question": "Rearrange the code to write \"Hi there\" to the file.",
4927 "textContent": "[h1]Writing to Files[/h1]\r\n\r\nOnce the file is created, you can write content to it using the same Formatter object's [b]format[/b]() method.\r\n[b]Example:[/b] [code format=\"java\" codeId=\"802\"]import java.util.Formatter;\r\n\r\npublic class MyClass {\r\n public static void main(String[ ] args) {\r\n try {\r\n Formatter f = new Formatter(\"C:\\\\sololearn\\\\test.txt\");\r\n [b]f.format(\"%s %s %s\", \"1\",\"John\", \"Smith \\r\\n\");\r\n f.format(\"%s %s %s\", \"2\",\"Amy\", \"Brown\");[/b]\r\n f.close(); \r\n } catch (Exception e) {\r\n System.out.println(\"Error\");\r\n }\r\n }\r\n}[/code]\r\nThe [b]format[/b]() method formats its parameters according to its first parameter. \r\n%s mean a string and get's replaced by the first parameter after the format. The second %s get's replaced by the next one, and so on. So, the format [b]%s %s %s[/b] denotes three strings that are separated with spaces.\r\nNote:[b] \\r\\n[/b] is the newline symbol in Windows.\r\nThe code above creates a file with the following content:[code format=\"java\" ]1 John Smith \r\n2 Amy Brown[/code]\r\n[note]Don't forget to [b]close [/b]the file once you're finished writing to it![/note]"
4928 }
4929 ]
4930 }
4931 },
4932 {
4933 "lesson": {
4934 "id": 2189,
4935 "name": "Module 6 Quiz",
4936 "type": 1,
4937 "mode": 0,
4938 "videoID": null,
4939 "tags": null,
4940 "quizzes": [
4941 {
4942 "id": 4449,
4943 "number": 1,
4944 "videoStart": 0,
4945 "videoEnd": 0,
4946 "linkedVideoID": null,
4947 "type": 3,
4948 "linkedQuizID": null,
4949 "tip": null,
4950 "hint": null,
4951 "time": 0,
4952 "answers": [
4953 {
4954 "id": 91918,
4955 "text": "int",
4956 "isCorrect": false,
4957 "properties": {
4958 "prefix": "",
4959 "postfix": ""
4960 }
4961 },
4962 {
4963 "id": 91919,
4964 "text": "try",
4965 "isCorrect": false,
4966 "properties": {
4967 "prefix": "",
4968 "postfix": ""
4969 }
4970 },
4971 {
4972 "id": 91920,
4973 "text": "/",
4974 "isCorrect": false,
4975 "properties": {
4976 "prefix": "",
4977 "postfix": ""
4978 }
4979 },
4980 {
4981 "id": 91921,
4982 "text": "catch",
4983 "isCorrect": false,
4984 "properties": {
4985 "prefix": "",
4986 "postfix": ""
4987 }
4988 }
4989 ],
4990 "question": "Fill in the blanks to declare a function that takes two integers as arguments and prints their division. Handle the possible exception.\r\n[!raw!]\r\nvoid myFunc(int a, {0} b) {\r\n {1} {\r\n System.out.println(a{2}b);\r\n }\r\n {3}(Exception e) {\r\n System.out.println(\"Error\");\r\n }\r\n}",
4991 "textContent": null
4992 },
4993 {
4994 "id": 4332,
4995 "number": 2,
4996 "videoStart": 0,
4997 "videoEnd": 0,
4998 "linkedVideoID": null,
4999 "type": 3,
5000 "linkedQuizID": null,
5001 "tip": null,
5002 "hint": null,
5003 "time": 0,
5004 "answers": [
5005 {
5006 "id": 93203,
5007 "text": "throws",
5008 "isCorrect": false,
5009 "properties": {
5010 "prefix": "",
5011 "postfix": ""
5012 }
5013 },
5014 {
5015 "id": 93204,
5016 "text": "if",
5017 "isCorrect": false,
5018 "properties": {
5019 "prefix": "",
5020 "postfix": ""
5021 }
5022 },
5023 {
5024 "id": 93205,
5025 "text": "0",
5026 "isCorrect": false,
5027 "properties": {
5028 "prefix": "",
5029 "postfix": ""
5030 }
5031 },
5032 {
5033 "id": 93206,
5034 "text": "new",
5035 "isCorrect": false,
5036 "properties": {
5037 "prefix": "",
5038 "postfix": ""
5039 }
5040 }
5041 ],
5042 "question": "Fill in the blanks to define a function ''myFunc'', which throws an exception if its parameter is less than 0.\r\n[!raw!]\r\nvoid myFunc(int arg)\r\n {0} IllegalArgumentException\r\n{\r\n {1} (arg < {2})\r\n throw {3} IllegalArgumentException();\r\n}",
5043 "textContent": null
5044 },
5045 {
5046 "id": 4333,
5047 "number": 3,
5048 "videoStart": 0,
5049 "videoEnd": 0,
5050 "linkedVideoID": null,
5051 "type": 2,
5052 "linkedQuizID": null,
5053 "tip": null,
5054 "hint": null,
5055 "time": 0,
5056 "answers": [
5057 {
5058 "id": 100311,
5059 "text": "2",
5060 "isCorrect": false,
5061 "properties": {
5062 "prefix": "",
5063 "postfix": ""
5064 }
5065 }
5066 ],
5067 "question": "How many lines of output will this code produce?\r\nclass B implements Runnable {\r\n public void run() {\r\n System.out.println(\"B\");\t\r\n }\r\n}\r\nclass A extends Thread {\r\n public void run() {\r\n System.out.println(\"A\");\r\n Thread t = new Thread(new B());\r\n t.start();\r\n }\r\npublic static void main(String[ ] args) {\r\n A object = new A();\r\n object.start();\r\n }\r\n}",
5068 "textContent": null
5069 },
5070 {
5071 "id": 4334,
5072 "number": 4,
5073 "videoStart": 0,
5074 "videoEnd": 0,
5075 "linkedVideoID": null,
5076 "type": 1,
5077 "linkedQuizID": null,
5078 "tip": null,
5079 "hint": null,
5080 "time": 0,
5081 "answers": [
5082 {
5083 "id": 106133,
5084 "text": "implement Runnable",
5085 "isCorrect": true,
5086 "properties": {}
5087 },
5088 {
5089 "id": 106134,
5090 "text": "extend the Thread class",
5091 "isCorrect": true,
5092 "properties": {}
5093 },
5094 {
5095 "id": 106135,
5096 "text": "handle exceptions",
5097 "isCorrect": false,
5098 "properties": {}
5099 },
5100 {
5101 "id": 106136,
5102 "text": "name your class \"Thread\"",
5103 "isCorrect": false,
5104 "properties": {}
5105 }
5106 ],
5107 "question": "Which two options allow you to create new threads?",
5108 "textContent": null
5109 },
5110 {
5111 "id": 4335,
5112 "number": 5,
5113 "videoStart": 0,
5114 "videoEnd": 0,
5115 "linkedVideoID": null,
5116 "type": 2,
5117 "linkedQuizID": null,
5118 "tip": null,
5119 "hint": null,
5120 "time": 0,
5121 "answers": [
5122 {
5123 "id": 29451,
5124 "text": "15",
5125 "isCorrect": false,
5126 "properties": {
5127 "prefix": "",
5128 "postfix": ""
5129 }
5130 }
5131 ],
5132 "question": "What is the output of this code?\r\nArrayList<Integer> list = new ArrayList<Integer>();\r\nfor (int i = 0; i < 6; i++) {\r\n\tlist.add(i);\r\n}\r\nint x = 0;\r\nIterator<Integer> it = list.iterator();\r\nwhile (it.hasNext()) {\r\n\tx+= it.next();\t\r\n}\r\nSystem.out.println(x);",
5133 "textContent": null
5134 },
5135 {
5136 "id": 4450,
5137 "number": 6,
5138 "videoStart": 0,
5139 "videoEnd": 0,
5140 "linkedVideoID": null,
5141 "type": 2,
5142 "linkedQuizID": null,
5143 "tip": null,
5144 "hint": null,
5145 "time": 0,
5146 "answers": [
5147 {
5148 "id": 100312,
5149 "text": "12",
5150 "isCorrect": false,
5151 "properties": {
5152 "prefix": "",
5153 "postfix": ""
5154 }
5155 }
5156 ],
5157 "question": "What is the output of the following code?\r\nint f=1, i=2;\r\nwhile(++i<5)\r\n f*=i;\r\nSystem.out.println(f);",
5158 "textContent": null
5159 }
5160 ]
5161 }
5162 }
5163]