Skip to content

Commit 7f2c75a

Browse files
authored
Update firstjavaprogram.rst
1 parent 5f92bdd commit 7f2c75a

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

‎_sources/Java4Python/firstjavaprogram.rst‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Lets look at a Java Program
22
---------------------------
33

4-
A time honored tradition in Computer Science is to write a program
4+
A time-honored tradition in Computer Science is to write a program
55
called “hello world.” The “hello world” program is simple and easy.
66
There are no logic errors to make, so getting it to run relies only on
7-
understanding the syntax. To be clear lets look a a “complicated”
7+
understanding the syntax. To be clear, lets look at a “complicated”
88
version of hello world for Python:
99

1010
::
@@ -39,7 +39,7 @@ Now lets look at the same program written in Java:
3939
}
4040

4141
What we see is that at the core there are a few similarities, such as a
42-
main and the string “Hello World” However there is a lot more stuff
42+
main and the string “Hello World” However, there is a lot more stuff
4343
around the edges that make it harder to see the core of the program. Do
4444
not worry! An important skill for a computer scientist is to learn what
4545
to ignore and what to look at carefully. You will soon find that there
@@ -97,10 +97,10 @@ the Python interpreter interprets your Python. However since byte code
9797
is much closer to the native language of the computer it can run faster.
9898

9999
When the compiler does the translation it can find many different kinds
100-
of errors. For example if you make a typo the compiler will find the
100+
of errors. For example, if you make a typo, the compiler will find the
101101
typo and point it out to you before you ever run the program. We will
102102
look at some examples of compiler errors shortly. Chances are you will
103-
create some on your own very soon too.
103+
create some on your own very soon, too.
104104

105105
Now that we have run our hello world program, lets go back and look at
106106
it carefully to see what we can learn about the Java language. This
@@ -117,13 +117,13 @@ Lets take the hello world example a line at a time to see how these
117117
rules are applied. On line 1 we see that we are declaring a class called
118118
Hello. As rule 1 says all Java code resides inside a class. Unlike
119119
Python where a program can simply be a bunch of statements in a file,
120-
Java programs must be inside a class. So, we define a class, ``Hello``
121-
is not a very useful class it has no instance variables, and only one
122-
method. You will also notice the curly brace ``{`` In Java blocks of
120+
Java programs must be inside a class. So, we define a class ``Hello``,
121+
which is not a very useful class because it has no instance variables, and only one
122+
method. You will also notice the curly brace ``{``. In Java, blocks of
123123
code are identified by pairs of curly braces. The block starts with a
124124
``{`` and ends with a ``}``. You will notice that I indented my code
125125
that followed the left brace, but in Java this is only done by
126-
convention it is not enforced.
126+
convention, it is not enforced.
127127

128128
On the next line we start our method definition. The name of this method
129129
is:
@@ -158,17 +158,17 @@ The next word, **static** tells Java that this is a method that is part
158158
of the class, but is not a method for any one instance of the class. The
159159
kind of methods we typically wrote in Python required an instance in
160160
order for the method to be called. With a static method, the object to
161-
the left of the . is a class, not an instance of the class. For example
161+
the left of the ``.`` is a class, not an instance of the class. For example,
162162
the way that we would call the ``main`` method directly is:
163-
``Hello.main(parameter1)``. For now you can think of static methods the
163+
``Hello.main(parameter1)``. For now, you can think of static methods the
164164
same way you think of methods in Python modules that don’t require an
165165
instance, for example the math module contains many methods: sin, cos,
166166
etc. You probably evaluated these methods using the names
167167
``math.cos(90)`` or ``math.sin(60)``.
168168

169169
The next word, ``void`` tells the Java compiler that the method ``main``
170170
will not return a value. This is roughly analogous to omitting the
171-
return statement in a Python method. In other words the method will run
171+
return statement in a Python method. In other words, the method will run
172172
to completion and exit but will not return a value that you can use in
173173
an assignment statement. As we look at other examples we will see that
174174
every Java function must tell the compiler what kind of an object it
@@ -180,13 +180,13 @@ Next we have the proper name for the method: ``main``. The rules for
180180
names in Java are similar to the rules in Python. Names can include
181181
letters, numbers, and the ``_``. Names in Java must start with a letter.
182182

183-
Finally we have the parameter list for the method. In this example we
184-
have one parameter. The name of the parameter is ``args`` however,
185-
because everything in Java must have a type we also have to tell the
183+
Finally, we have the parameter list for the method. In this example we
184+
have one parameter. The name of the parameter is ``args``, however,
185+
because everything in Java must have a type, we also have to tell the
186186
compiler that the value of ``args`` is an array of strings. For the
187-
moment You can just think of an array as being the same thing as a list
188-
in Python. The practical benefit of declaring that the method main must
189-
accept one parameter and the parameter must be a an array of strings is
187+
moment you can just think of an array as being the same thing as a list
188+
in Python. The practical benefit of declaring that the method ``main`` must
189+
accept one parameter and the parameter must be an array of strings is
190190
that if you call ``main`` somewhere else in your code and and pass it an
191191
array of integers or even a single string, the compiler will flag it as
192192
an error.
@@ -207,7 +207,7 @@ method in Java.
207207
Now there is one more character on this line that is significant and
208208
that is the ``;`` at the end. In Java the ``;`` signifies the end of a
209209
statement. Unlike Python where statements are almost always only one
210-
line long java statements can spread across many lines. The compiler
210+
line long, Java statements can spread across many lines. The compiler
211211
knows it has reached the end of a statement when it encounters a ``;``.
212212
This is a very important difference to remember. In Java the following
213213
statements are all legal and equivalent. I would not encourage you to

0 commit comments

Comments
 (0)