Skip to content

Commit d0235e3

Browse files
committed
Added summary and reading questions in chapter 3
1 parent a9487c3 commit d0235e3

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

‎source/ch_3_firstjavaprogram.ptx‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,113 @@ Hello World!
329329
>>>
330330
</code>
331331
</program>
332+
<section xml:id="lets_look_java_program_summary">
333+
<title>Summary &amp; Reading Questions</title>
334+
<p><ol label="1">
335+
<li>
336+
<p>Java programs must be compiled before execution, unlike Python which is interpreted directly.</p>
337+
</li>
338+
<li>
339+
<p>Every Java program must define a <c>class</c>, and all code must be inside that class.</p>
340+
</li>
341+
<li>
342+
<p>Each Java program must include a <c>public static void main(String[] args)</c> method as the entry point.</p>
343+
</li>
344+
<li>
345+
<p>Java enforces that every variable and method must have a clearly defined type, including <c>void</c> for methods that return nothing.</p>
346+
</li>
347+
<li>
348+
<p>Statements in Java must end with a semicolon (<c>;</c>), and whitespace is not syntactically meaningful.</p>
349+
</li>
350+
<li>
351+
<p>Java uses dot notation to access class members, such as <c>System.out.println</c> for output.</p>
352+
</li>
353+
<li>
354+
<p>The <c>static</c> keyword indicates that a method belongs to the class itself, rather than to an instance of the class.</p>
355+
</li>
356+
</ol></p>
357+
<reading-questions xml:id="rqs-hello-java">
358+
<exercise label="hello-java-1">
359+
<statement>
360+
<p>Which of the following must be true of every Java program?</p>
361+
</statement>
362+
<choices>
363+
<choice>
364+
<statement><p>It must contain a method called <c>main()</c> with no parameters.</p></statement>
365+
<feedback><p>No. The main method must include a specific parameter: <c>String[] args</c>.</p></feedback>
366+
</choice>
367+
<choice correct="yes">
368+
<statement><p>It must include a <c>public static void main(String[] args)</c> method inside a class.</p></statement>
369+
<feedback><p>Correct! This is the required entry point for all Java applications.</p></feedback>
370+
</choice>
371+
<choice>
372+
<statement><p>It must be saved with a <c>.exe</c> extension.</p></statement>
373+
<feedback><p>No. Java source files use the <c>.java</c> extension and compile to <c>.class</c>.</p></feedback>
374+
</choice>
375+
<choice>
376+
<statement><p>It must be run using the Python interpreter.</p></statement>
377+
<feedback><p>No. Java uses its own compiler and Java Virtual Machine (JVM).</p></feedback>
378+
</choice>
379+
</choices>
380+
</exercise>
381+
<exercise label="hello-java-2">
382+
<statement>
383+
<p>What is the purpose of the <c>javac</c> command?</p>
384+
</statement>
385+
<choices>
386+
<choice correct="yes">
387+
<statement><p>To compile Java source code into bytecode</p></statement>
388+
<feedback><p>Exactly! <c>javac</c> compiles <c>.java</c> files into <c>.class</c> files.</p></feedback>
389+
</choice>
390+
<choice>
391+
<statement><p>To run a Python program</p></statement>
392+
<feedback><p>No. Python programs are run with the <c>python</c> or <c>python3</c> command.</p></feedback>
393+
</choice>
394+
<choice>
395+
<statement><p>To debug Java programs</p></statement>
396+
<feedback><p>No. <c>javac</c> only compiles code. Debugging is a separate process.</p></feedback>
397+
</choice>
398+
<choice>
399+
<statement><p>To edit Java source files</p></statement>
400+
<feedback><p>No. You use a text editor or IDE to edit Java files.</p></feedback>
401+
</choice>
402+
</choices>
403+
</exercise>
404+
<exercise label="hello-java-3">
405+
<statement>
406+
<p>What symbol does Java use to indicate the end of a statement?</p>
407+
</statement>
408+
<choices>
409+
<choice>
410+
<statement><p><c>#</c></p>
411+
</statement>
412+
<feedback>
413+
<p>No. <c>#</c> is used for comments in Python, not for statement termination.</p>
414+
</feedback>
415+
</choice>
416+
<choice correct="yes">
417+
<statement><p><c>;</c></p>
418+
</statement>
419+
<feedback>
420+
<p>Correct! Java uses semicolons to mark the end of a statement.</p>
421+
</feedback>
422+
</choice>
423+
<choice>
424+
<statement><p><c>.</c></p>
425+
</statement>
426+
<feedback>
427+
<p>No. <c>.</c> is used for dot notation, not to end a statement.</p>
428+
</feedback>
429+
</choice>
430+
<choice>
431+
<statement><p><c>}</c></p>
432+
</statement>
433+
<feedback>
434+
<p>No. <c>}</c> is used to close code blocks.</p>
435+
</feedback>
436+
</choice>
437+
</choices>
438+
</exercise>
439+
</reading-questions>
440+
</section>
332441
</chapter>

0 commit comments

Comments
 (0)