Skip to content

Commit 3b67541

Browse files
committed
added references inside the paraggraog
1 parent f337694 commit 3b67541

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

source/ch2_firstjavaprogram.ptx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,15 @@
163163
<p>
164164
Now, we have a full class definition and have utilized its methods. Class definitions in Java will be covered thoroughly in chapter 6. For now, it is important to know that Python programs can be written without using classes at all. Java, on the other hand, requires all code to reside in a class. This will be discussed in the next section.
165165
</p>
166-
167-
168-
166+
169167
</section>
168+
170169
<section xml:id="sec-lets-look-at-a-java-program">
171170
<title>Lets look at a Java Program</title>
172171
<p>
173172
A time-honored tradition in Computer Science is to write a program called &#x201C;Hello World.&#x201D; The &#x201C;Hello World&#x201D; program is simple and easy.
174173
There are no logic errors to make, so getting it to run relies only on understanding the syntax.
175-
To be clear, lets look at a &#x201C;complicated&#x201D; version of hello world for Python:
174+
To be clear, lets look at a &#x201C;complicated&#x201D; version of hello world for Python in <xref ref="python-hello-world" text="type-global"/>.
176175
</p>
177176

178177
<listing xml:id="python-hello-world">
@@ -185,7 +184,7 @@
185184
</listing>
186185

187186
<p>
188-
Remember that we can define this program right at the Python command line and then run it:
187+
Remember that we can define this program right at the Python command line and then run it as per <xref ref="python-hello-world-run" text="type-global"/>.
189188
</p>
190189

191190
<listing xml:id="python-hello-world-run">
@@ -214,13 +213,13 @@ public class Hello {
214213
</listing>
215214

216215
<p>
217-
What we see is that at the core there are a few similarities, such as a main and the string &#x201C;Hello World&#x201D;. However, there is a lot more stuff around the edges that make it harder to see the core of the program. Do not worry! An important skill for a computer scientist is to learn what to ignore and what to look at carefully. You will soon find that there are some elements of Java that will fade into the background as you become used to seeing them.
216+
Based on <xref ref="java-world" text="type-global"/>, what we see in the code is that at the core there are a few similarities, such as a main and the string &#x201C;Hello World&#x201D;. However, there is a lot more stuff around the edges that make it harder to see the core of the program. Do not worry! An important skill for a computer scientist is to learn what to ignore and what to look at carefully. You will soon find that there are some elements of Java that will fade into the background as you become used to seeing them.
218217
</p>
219218

220219
<p>
221220
<idx>interpreter</idx>
222221
<idx>compile</idx>
223-
The first question you probably have about this little program is &#x201C;How do I run it?&#x201D; Running a Java program is not as simple as running a Python program. The first thing you need to do with a Java program is compile it. The first big difference between Java and Python is that Python is an interpreted language. We could run our Python programs in the Python <term>interpreter</term> and we were quite happy to do that. Java makes running programs a two step process. First we must type the hello world program into a file and save that file using the name <c>Hello.java</c> The file name must be the same as the public class you define in the file. Once we have saved the file we <term>compile</term> it from the command line as follows:
222+
The first question you probably have about this little program is &#x201C;How do I run it?&#x201D; Running a Java program is not as simple as running a Python program. The first thing you need to do with a Java program is compile it. The first big difference between Java and Python is that Python is an interpreted language. We could run our Python programs in the Python <term>interpreter</term> and we were quite happy to do that. Java makes running programs a two step process. First we must type the hello world program into a file and save that file using the name <c>Hello.java</c> The file name must be the same as the public class you define in the file. Once we have saved the file we <term>compile</term> it from the command line as <xref ref="java-javac" text="type-global"/>.
224223
</p>
225224

226225

@@ -242,7 +241,7 @@ $ ls -l Hello.*
242241
</p>
243242

244243
<p>
245-
Now that we have compiled our java source code we can run the compiled code using the <c>java</c> command.
244+
Now that we have compiled our java source code we can run the compiled code using the <c>java</c> command as per <xref ref="java-run-hello" text="type-global"/>.
246245
</p>
247246

248247

@@ -462,7 +461,7 @@ System.out.println("Hello World!");
462461
Java statements can spread across many lines, but the compiler knows it has reached the end of a statement when it encounters a <c>;</c>.
463462
In Python, it is not required (or recommend) to use semicolons in this way, but whitespace is meaningful.
464463
In contrast, in Java semicolons are <term>required</term> to end statements, but whitespace is not considered meaningful.
465-
This is a very important difference to remember! In Java, the following statements are all legal and equivalent.
464+
This is a very important difference to remember! In Java, the statements in <xref ref="java-messy-code" text="type-global"/> are all legal and equivalent.
466465
I would not encourage you to write your code like this, but you should know that it is legal.
467466
</p>
468467

@@ -491,7 +490,7 @@ System.
491490
</p>
492491

493492
<p>
494-
If we wanted to translate the Java back to Python we would have something like the following class definition.
493+
If we wanted to translate the Java back to Python we would have something like <xref ref="python-hello-world" text="type-global"/> class definition.
495494
</p>
496495

497496
<listing xml:id="java-staticmethod">

0 commit comments

Comments
 (0)