You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/part-1/2-printing.md
+17-19Lines changed: 17 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,9 +60,9 @@ Hello world!
60
60
61
61
Tulostuskomennon avulla tulostettavaa tekstiä voi vaihtaa mielivaltaisesti, kunhan komento `System.out.println("mielivaltainen teksti");` -- eli `System` piste `out` piste `println` sulut auki `(` "teksti" sulut kiinni `)` ja puolipiste `;` pysyy muuttumattomana. Alla oleva komento tulostaa tekstin "Hei vaan!". -->
62
62
63
-
In this material, the text boxes like the one above demonstrate an output produced by the example code. Accordingly, the above program would produce the print output "Hello World!". You can try any of these examples in the exercise template named "Sandbox", which you will find in the programming environment.
63
+
In this material, text boxes like the one above demonstrate an output produced by the example code. Accordingly, the above program would produce the print output "Hello World!". You can try any of these examples in the exercise template named "Sandbox", which you will find in the programming environment.
64
64
65
-
You can print any text you want with the command, as long as the command `System.out.println("arbitary text");` -- i.e., `System` dot `out` dot `println` open parenthesis `(` "the text" close parenthesis `)` and semicolon `;` remains unchanged. The command below will print the text "Hello there!".
65
+
You can print any text you want with the command, as long as the command `System.out.println("arbitrary text");` -- i.e., `System` dot `out` dot `println` open parenthesis `(` "the text" close parenthesis `)` and semicolon `;` remains unchanged. The command below will print the text "Hello there!".
66
66
67
67
<!-- ```java
68
68
System.out.println("Hei vaan!");
@@ -100,7 +100,7 @@ public class Esimerkki {
100
100
101
101
## Program Boilerplate
102
102
103
-
Our programs have to be written within a program boilerplate (the frame around the program itself), such as the one below, for them to work. The name of the boilerplate, `Example` in this case, corresponds to the name of the file that contains the source code (e.g. `Example.java`).
103
+
In Java, our programs have to include some boilerplate code to function. This boilerplate, an example of which is shown below, for example tells the computer what your program is called. Below, the name of the program is `Example`. This name has to correspond to the name of the file that contains the source code (e.g. `Example.java`).
104
104
105
105
```java
106
106
publicclassExample {
@@ -122,7 +122,7 @@ Tulostettava teksti
122
122
123
123
-->
124
124
125
-
Execution of the program starts from the line that follows `public static void main(string[] args) {`, and ends at the closing curly bracket `}`. Commands are executed one line at a time. We will get know the meaning of the words `public class` and `public static void` later on. In the above example, `System.out.println("Text to be printed")` is the only command to be executed and its output is:
125
+
Execution of the program starts from the line that follows `public static void main(string[] args) {`, and ends at the closing curly bracket `}`. Commands are executed one line at a time. We will get to know the meaning of the words `public class` and `public static void` later on. In the above example, `System.out.println("Text to be printed")` is the only command to be executed and its output is:
126
126
127
127
<sample-output>
128
128
@@ -159,7 +159,7 @@ The examples in the material will not always show the boilerplate, but you can a
159
159
System.out.println("Hello world");
160
160
```
161
161
162
-
In reality however, the above example written as a full Java program looks like this:
162
+
In reality, the above example written as a full Java program looks like this:
163
163
164
164
```java
165
165
publicclassExample {
@@ -202,14 +202,12 @@ Kun olet tehnyt tehtävän ja huomaat, että ohjelma tulostaa halutun merkkijono
202
202
-->
203
203
204
204
You'll find the second programming exercise of the course below. If you want, you can watch the video linked below in advance to see how the exercise is solved.
205
-
Here is the second programming exercise of the course. If you want, you can see first the video on how to solve this exercise:
The exercise template has the following boilerplate code:
213
211
214
212
```java
215
213
publicclassAdaLovelace {
@@ -228,7 +226,7 @@ Ada Lovelace
228
226
229
227
</sample-output>
230
228
231
-
Once you've finished the exercise and see that it prints the correct string, return the exercise to TMC server. After that, you can read more about [Ada Lovelace](https://en.wikipedia.org/wiki/Ada_Lovelace), who was one of the first programmers.
229
+
Once you've finished the exercise and have confirmed that it prints the correct string, return the exercise to TMC server. After that, you can read more about [Ada Lovelace](https://en.wikipedia.org/wiki/Ada_Lovelace), who was one of the first programmers.
232
230
233
231
</programming-exercise>
234
232
@@ -248,13 +246,13 @@ Käytössämme oleva ohjelmointiympäristö kääntää ja suorittaa ohjelman yh
248
246
249
247
<text-boxvariant='hint'name='Running the program'>
250
248
251
-
You can run a program in TMC by pressing the green play-button, or by selecting "Run project" from the TMC-menu.
249
+
You can run a program in TMC by pressing the green playbutton, or by selecting "Run project" from the TMCmenu.
252
250
253
251
Although running the program is straightforward, a lot happens behind the scenes. When a program is run, the source code is first compiled into Java bytecode. This compilation process is done by Java's own compiler, which itself is a program. Following that, the program gets executed, meaning the commands are executed one-by-one by a Java-interpreter that is able to read Java bytecode.
254
252
255
-
This compile process affects how and when errors occur. When program is compiled before execution, the compiler can search errors from your program. This can also help the IDE to give tips, so the programmer can immediately notice their errors.
253
+
This compiling process affects how and when errors occur. When program is compiled before execution, the compiler can search for errors in your program. This allows the IDE to give you tips, so that you may more easily correct your mistakes.
256
254
257
-
The IDE both compiles and executes the program with just one touch of a button. However, the programming environment compiles the program continuously, so it can report errors. You can for example try to change above Ada Lovelace exercise print command to `Systemoutprintln("hi!")` -- you will notice, that the line will be underlined and there will be notification about a error on the left side.
255
+
The IDE both compiles and executes the program with just one touch of a button. However, the programming environment also compiles the program continuously, so that it can report errors. You can, for example, try to change above Ada Lovelace exercise print command to `Systemoutprintln("hi!")` -- you will notice that the line will be underlined and there will be notification about a error at the left end of the line.
258
256
259
257
</text-box>
260
258
@@ -282,7 +280,7 @@ Hei maailma!
282
280
283
281
## Printing Multiple Lines
284
282
285
-
Programs are constructed command by command where each command comes on a new line. In the example below, command `System.out.println` appears twice, which means that two print commands are being executed in the program.
283
+
Programs are constructed command by command so that each command comes on a new line. In the example below, the command `System.out.println` appears twice. This means that two print commands are being executed in the program.
286
284
287
285
```java
288
286
publicclassOhjelma {
@@ -319,9 +317,9 @@ Ohjelmoinnin opettelu onkin oikeastaan tie täynnä virheitä -- jokainen virhev
319
317
320
318
Programming exercises will be checked by TMC Henrik, who is very exact. Expectations about the print format in assignments are very precise. If, for example, the assignment expects you to print a parenthesis, you must obey and print the parenthesis.
321
319
322
-
This exactness in printing is widely relevant in programming. Missing a single character can cause an error. Beginner programmers often enter a comma instead of a dot, write for example `printin`instad of `println`, leave out apostrophes, or forget the ending semicolon after a command. Any of these would cause an error and make executing of a program fail.
320
+
This exactness in printing is widely relevant in programming. Missing a single character can cause an error. Beginner programmers often enter a comma instead of a dot, write `printin`instead of `println`, leave out apostrophes, or forget the semicolon after a command. Any of these would cause an error and make the program fail to execute.
323
321
324
-
Learning programming really is a road full of errors -- every error message is a chance to learn. So look for any red signs in the IDE and read the test errors!
322
+
Learning programming really is a road full of errors, with every error message a chance to learn. So look for any red signs in the IDE and read the test errors!
325
323
326
324
</text-box>
327
325
@@ -364,7 +362,7 @@ public class OnceUponATime {
364
362
}
365
363
```
366
364
367
-
Edit the program so that it will print the following text. Use three `System.out.println`-commands for printing.
365
+
Edit the program so that it will print the following text. Use three `System.out.println`commands for printing.
368
366
369
367
<sample-output>
370
368
@@ -388,9 +386,9 @@ Alla oleva animaatio kuvaa sout-komennon käyttöä. Kun käyttäjä on kirjoitt
388
386
389
387
<text-boxvariant='hint'name='"sout"'>
390
388
391
-
Writing the command `System.out.println("...") can be pretty cumbersome. In NetBeans try to write on a blank line (in main) **sout** and press tabulator (key left to q). What happens? This small tool will propably save much of your time.
389
+
Writing the command `System.out.println("...")` can be pretty cumbersome. In NetBeans, write on a blank line (in main) **sout** and press tabulator (key to the left of q). What happens? This small tool will propably save much of your time.
392
390
393
-
Animation below illustrates the use of sout-command. Firstuser writes sout and then pressed tabulator. A Magic Trick!
391
+
The animation below illustrates the use of sout-command. First, the user writes sout and then presses the tabulator. A Magic Trick!
394
392
395
393

396
394
@@ -492,7 +490,7 @@ world
492
490
493
491
</sample-output>
494
492
495
-
Although the previous example works, it's important to be considerate of other programmers (and future you!) and to use line breaks. That way, anyone reading the program knows that each line does only a single concrete thing.
493
+
Although the previous example works, it's important to be considerate of other programmers (and your future self!) and to use line breaks. That way, anyone reading the program knows that each line does only a single concrete thing.
496
494
497
495
<!-- TODO: quiz, jossa kysytään että mistä tietyssä termissä on kyse -->
0 commit comments