Level 41

Old Level 01

Published in the Java Developer group

The future has come

Old Level 01 - 1The attributes of 20th century were a hoover, a washing-machine, a TV-set and a car. If you continue to wash clothes by hand, ride a horse, use candles for illumination, then, by standards of 20th century, you are living in 19th. The internet, cell phone, Skype, social networks, became the attributes of 21th century. By means of the Internet it is possible to get access to any information well-known to humanity. It is possible to work and do business, get education and teach in the web. By means of social networks it is possible to find a friend, a job, a girlfriend, a group by interests. You can become acquainted practically with any person in the world, to ask advice or help from that person. You can befriend people in the whole world, and then come to visit or invite them to you place, or go somewhere together. By means of Skype you can communicate with the friends, brothers, sisters, parents, relatives, and any other people in the whole world. Free visual communication in any place of the world. People didn’t even dare to dream about it 20 years ago. Now it is an ordinary fact. GoogleStreetView enables you to “walk” the streets of any city of any country on earth. You can choose a place, where would like to live, and move there. The owner of a "modern telephone" can: talk, write messages, send pictures, surf for information in the web, install hundreds of millions of free applications. What else? Make videos-calls, listen to some music, watch video, make video, take photos, see the location on a map, put location-marks on it, use the organizer, communicate in social networks and “like” kittens. Old Level 01 - 2You can learn English in a year (or any other language), listening to audio courses, when you go to work and from work. Any information is accessible in the web, any textbooks. Do you want the video-lecture of the best world universities with sub-titles? There they are as well. If you speak English, you can write a book, publish it on Amazon and earn a fortune. You can order a web-site for several hundred dollars and do business over the web all over the world. Stop living in 20th century waiting to be told what to learn, how to learn, what to do and where to live. Decide it on your own. Opportunities to change your life surround you on every step. And the last thing, there is this joke: A flood happened. Everyone is running for their lives, except for an old and very devotional Jew, who sits and prays. A truck is passing by, and people in it shout to the Jew: - Haim, get in, save yourself! - I’ve been praying all of my life and kept to all the traditions, God will save me, - Haim answers. Water is getting higher, up to the windows. A boat floats by. Same question, same answer. Water keeps getting higher, up to the roof. Haim sits and prays. A helicopter flies by. Same question, same answer. And Haim drowned. And in the Other World he began chiding God: - I’ve been praying all of my life and kept to all the traditions, why did You not save me? - I’ve sent you a car, a boat and a helicopter, so why are you complaining?

You have reached a new level

Old Level 01 - 3

Level 1

- Congratulations on your first level! - Thanks! It was easier than I thought! - And I had a lot of fun! - You’ll find it even more exciting. Now, I’ll prove it. Are you ready? - Let’s roll!

1 Risha, acquaintance with the program.

1 Risha

- Hi, my young friend. I hope you haven’t forgotten that I’m bureaucrat in 16th generation. I would never become so successful if I didn’t systematize all my knowledge. I have a lot of useful tips that will help you with some tasks. First, let me tell you what an ordinary Java program is. - Ok, go ahead. - Fact one. A Java program consists of classes. Each class is stored in a separate file. A file name matches a class name; the file extension is .java. - The program comprises of a .java file set, in each file there is a code of one class, right? - Absolutely right, Amigo! If the file name is, it contains MyCat class. - Fact two. If we have a lot of files with classes, we group them into folders and subfolders. Note that classes are grouped into packages and subpackages. Names of packages and subpackages have to be specified in a class code. They must match names of folders and subfolders on the disc. - So we have files arranged into folders on the one side and classes arranged into packages on the other. The class name must match the name of the file in which the class is described. A package name matches the name of the folder to store the class. - Tell me more about this. - Names of subpackages are described separated by a point, almost like links on the Web. - So if you have a Cat class located in “animals.pets” package, it means that A) There is src folder on the disc. All project files are stored in this folder; B) Inside it there’s a folder animals which comprises of a folder named pets, C) In the pets folder there’s a file, which contains a class code Cat. - I kinda understand, but I’m not sure. - Well then, the structure of classes and packages is the same as the structure of the folders and files on the disk. If there’s a file located in the folder src/com/houses/ then it means that there’s a class House, which is in the package com.houses. - In this context, the full file name is «com/houses/», and the full name of the class com.houses.House. - Got it. - Good, you are so brainy. Now watch the screen - here’s a small class code. I’ve marked all the key points: Old Level 01 - 4- Everything’s clear as much as it can be on the first try. Heh, heh. - Bully for you! You needn’t understand much. The trick is to catch something now, you’ll understand everything else later. Well, then, I’m done for today, let someone else take care of you.

2 John Squirrels, How to use this online course

- Good day, Amigo. I am John Squirrels, the Captain of Galactic Rush spaceship. - Good day, Captain. - Today I am going to explain you how our learning process is arranged.

CodeGym Guide

I always told my students that computer programming is easy and interesting. Now you can make sure of it by yourself. The goal of the course is to enjoy studying, have fun and gain real programming skills in Java, which will help you to get a job as a software developer. That’s why there are many practical tasks in the course. Task complexity grows gradually from simple to the most complex ones.

How the course is arranged

The course consists of 40 levels. Each level contains 10-12 lectures and 20-30 practical tasks. Each level corresponds to a separate solar system on the star map below, and lectures in the level are planets of the solar system. Each opened lecture is a flight to another planet. When all lectures are opened, the spaceship flies to the next star system. Old Level 01 - 5For solving practical tasks, watching videos and many other things you get a reward – a few units of “dark matter”. Old Level 01 - 6To move to the next lecture or level, you need to do "a flight on the spaceship," which requires "one refueling ship": Old Level 01 - 75 units of dark matter are needed to refuel the spaceship.

Moving to the next level

To move to the next level, you need to go through all lectures in the current level. To move to the next lecture, you need to press the big Green Button: Old Level 01 - 8When you move to the next lesson, your spaceship flies to another planet. If you run out of fuel or your ship isn’t filled, the button will not be able to press and will look like this: Old Level 01 - 9You can fill the ship in the section "My Page". If you cannot refuel the ship because there is no dark matter, you need to solve several tasks and earn it. To solve a task use the Yellow Button, that is to the left of lectures, near practical tasks: Old Level 01 - 10

Practical Tasks

Entering the code as in a sample - this is the most simple practical task. To solve this task, you must enter Java code at the lower part of the window. The code should be identical to the sample (it is at the upper part of the window). Old Level 01 - 11Write a program - a practical task of average complexity. To solve it, you should write the program in Java. You need to find out how to solve the task, and enter the code solution in the main window. Then press the button: Old Level 01 - 12Old Level 01 - 13To make your studying easier, as well as for simplifying the checking process of the program, the code should be written only in the place marked by the comment "Add your code here". In the case of a successful compilation, the program will automatically be checked - whether current task is solved correctly. If the program displays something on the screen, there is a special window below – the Output window. It shows everything that the program has displayed to the screen at last run. You can always hide the window with the code to see something in lectures or to postpone the solution of the task. Simply press the button on the top right corner. When you come back to this task again, your previous code stays there. The button looks like this: Old Level 01 - 14If the size of the window with code is too small, you can maximize it by clicking the maximize button (available from the 4th level): Old Level 01 - 15Home tasks must be solved in Intellij IDEA (available from 3rd level). This is a special program for developers (IDE) to make coding easier. I wrote a plugin for IDEA, which will give you the ability to check whether your program is correct in less than a second. The plugin consists of only two buttons: Old Level 01 - 16Left button shows the list of available tasks for you: Old Level 01 - 17Right button sends the task to the server for checking: Old Level 01 - 18You can also earn "dark matter" watching videos: Old Level 01 - 19

3 Risha, Basics of memory work

- It’s me again: I just forgot to explain you something. I want to tell you about variables and memory addressing. Don’t take much thought about it, but if you remember something - that’s a mercy! - Love your approach. Good, if point taken, if not - well, okay. - If it goes, it goes, don’t force it. That’s obvious. Why, is it different with you? - It is. We have another approach to studying: if you don’t want to, you do have to. - Hmm, what an outdated approach. Just fancy, you waste lots of time and effort, and there’s almost no result. - Dead right! But let that pass. - All right. Imagine Excel. Everybody knows Excel. An Excel sheet consists of cells, each cell has its unique number (A1, A2,…B1, B2). You can put some value in a cell or obtain stored value, when you know cell number. A computer’s memory is arranged in much the same way. Old Level 01 - 20- So far, it’s clear. - At runtime the program and its data are stored in memory. The entire computer’s memory is represented by small cells - bytes. Each cell has its unique number - 0,1,2,3, ... (starting with zero). If you know the cell’s number, we can save there some data or take the data from the cell. Some cells store the program code, a processor’s command set, the other store the program data. The number of each cell is also called its address. - Processor, commands… - Professor has told me something about it, but just a little. - Processor is a thing that can run commands from a program brought into memory. Almost every processor command looks like that: "take data from some cells, make something with them, and then put the result into other cells". Combining hundreds of them, we thus get complex and useful commands. - Why on earth do I need all this? - When a variable is declared in a code, it is given a piece of unused memory, usually a few bytes. When declaring a variable you also need to specify the type of information that the program will store in a variable: numbers, text, or other data. For convenience, each variable is given a unique name. - So then, a variable is a name and a type, or a piece of memory and a value? - All combined. Let’s have a look at a few examples. Old Level 01 - 21

4 Elly, Acquaintance with the types of int and String

- Hey, Amigo. - Hello, Eleanora Carry. - Call me just Elly, so it will sound not that officially. - OK, Elly. - I think with my assistance you’ll quickly become one of the best programmers. I have great experience in teaching beginners. Follow me, and it will go like clockwork. Let’s get started. - In Java there are two basic types: String and int. In String we store strings/text, and in int numbers (integers). To declare a new variable, you need to write its type and name. The name must not match any other name of variable and/or function. Old Level 01 - 22- When declaring variables you can immediately enter values to them. Old Level 01 - 23- To enter a new value to a variable you need to use equals sign “=”. It’s also called an assignment operator. Assignment is putting to a variable a value taken from another variable or calculated based on several variables. Old Level 01 - 24- A new value of a variable can be calculated based on expression to the right of sign «=». The expression can contain the same variable. Old Level 01 - 25- You can combine strings using the plus sign: Old Level 01 - 26- Sometimes it’s convenient to use a string consisting of one or more spaces: Old Level 01 - 27Now I explain you how to display text and value of variable: Old Level 01 - 28Old Level 01 - 29- By the way, Diego asked me to give you a couple of tasks. Don’t be surprised, they are in the style of Diego:
1 Write a program that displays «If something goes wrong at the office, blame the guy who can't speak English.»
2 Write a program that displays «I don't get excited by money, they soothe me.» 10 times.
3 Write a program that displays «If you don't like the way I drive, stay off the sidewalk.».

5 Diego, Good advice

Old Level 01 - 30- Hey, buddy! It’s me again, do you remember? The one who will teach you right staff! - No one understands you better than me, because we are both robots. So don’t listen to the theory of those "bags of bones". I am the one you should listen to. And I say: nothing can replace practice. You’re not going to learn to swim reading a swim guide, are you? Ha-ha. Who practices wins. That’s what robots do. - Here’s a new task: write a program to display «Kiss my shiny metal ass!»
1 A new text output task
Write a program that displays «Kiss my shiny metal ass!»

6 Risha, Signing of the contract

- It’s me again! I think you already know enough to start making smart decisions. It’s high time to sign a contract with your new employer. You have to fill in an application, here’s a model form. Just display its text on the screen, that’s all. Sign it blind, I always do so.
Task: display text

My name is Amigo.

My salary for the first year will be $100
My salary for the second year will be $200
My salary for the third year will be $300
My salary for the fourth year will be $400
My salary for the fifth year will be $500

Thanks for being generous, my friend Risha!

Amigo thought to himself for a moment. «It doesn’t look very generous at all. I remember Diego has taught me an expression...»
New task: CONTRACT. Write a program to display:

My name is Amigo.

My salary for the first year will be $60,000
My salary for the second year will be $80,000
My salary for the third year will be $100,000
My salary for the fourth year will be $120,000
My salary for the fifth year will be $150,000

Kiss my shiny metal ass!

Risha returns: - Well, how are you? - Done. I’ve signed it. - Nicely done! I sign blind, too. We in the Galactic Rush never cheat each other. - Heh, heh. Thanks for being so generous, my friend Risha!

7 Elly, Output to screen

- It’s me again. Today you have three lessons. This is the second one! Sit back and listen, I’ll tell you about the output to the screen. It’s simple and easy: Old Level 01 - 31- Could you once again tell me about print() and println()? - The print() function displays entire text letter by letter. When the line is full, text appears on the next line. You can interrupt output on the current line, and make the text display on the next line if you use the println() function. - Got it. And what’s that magic of adding strings to numbers? - If a number is added to a number, the result will be a number: 2+2 equals 4. If a string is added to a number, then the number is converted to a string and then two strings are combined. - Yeah. I kinda thought so seeing the examples, but you never know. Thanks for the interesting lecture, Elly.

8 Bilaabo, Comparison with Pascal

Old Level 01 - 32- Hi! I am Dr. Laga Bilaabo, I’m an alien, hope we’ll be friends. - Me too. - On our home planet, we use the progressive programming language Pascal, instead of outdated Java. Here’s a little comparison between Java and Pascal: Old Level 01 - 33- It’s the same program written with various languages. As you can see, in Pascal it takes less lines; it’s a sign of Pascal’s progressiveness. - I think this comparison can improve your understanding of Java, if you have ever seen Pascal. - No, I haven’t. But it would still be interesting to look at comparison of two different programming languages. - Yeah, you are right. Let’s continue. - In Pascal, we put the written code in the program body, procedures or functions. In Java, it’s all been greatly simplified: the program body, procedures and functions were replaced by functions, and functions called methods. Old Level 01 - 34- In the Pascal column, I see «program body», «function» and «procedure», and in Java column there are only functions. It looks a bit strange. - Yes, it seems very strange to everyone in my planet, but people like to simplify everything. - In Java, all code is in functions, so, to declare a function, you don’t even need to write function, as you do in Pascal. - It’s that simple: If the line of code is of «Type + name» form, it’s a declaration of either a function or a variable. If brackets follow the name, then it’s a declaration of a new function. If there are no brackets, then a new variable is declared. - Declaration of variables and functions in Java is very similar, let’s compare: Old Level 01 - 35A function has the name getName and the return type String. - More than this, Java functions can’t exist by themselves. They have to be inside of a certain class. Therefore, when humans need to write a small program in Java, they must first create a class, then write the function main inside it, and then write their code in it. Earthlings are such freaks. - So, as you see, Pascal is much better. And if I could choose I would teach you Pascal. But my crew forced me to give you some tasks on Java. At least I’ll try to give you some good motivation:
1 Write a program that displays 9 times: «Life is not fair - get used to it.».
2 Write a program that displays 4 times: «The most important stakeholder in your life is You.».
3 Write a program that displays 16 times: «What you plant now, you will harvest later.».

9 Professor talks about the benefits of lectures

Old Level 01 - 36- Hey, Amigo! - Good afternoon, Professor Hans. - I’ve seen a lot in my time. Now, that’s what I’m going to tell you… - Sometimes people understand what they are taught at once, sometimes they don’t. It is all according what you’ve been taught before, and whom by. I mean, the teacher must motivate his students. - When a student wants to learn, the teacher is helpless here. - That’s right. A student can’t turn a boring lecture or lesson into a fun one. Only a teacher can do it. A teacher has to make lessons interesting and informative, rather than complain that students don’t want to learn and attend classes. - Just imagine a director of a movie that foundered at the box office blaming the audience who aren’t interested in his films and don’t watch them. If you meet such a director or lecturer, just ignore them. - Thanks for the advice, professor. - I asked Elly and Risha to explain to you new material in informative and interesting ways. But they can still make mistakes. Err is human. Sometimes their story is half-finished, sometimes you don’t understand something. But it should not stop you in learning new topics. Because there is the world of exciting adventures and interesting work before you! - I’ll give you links to articles on the same topic. Refer to these articles, if you have troubles with task solving. If you want to read something else on a different subject, you can visit our website You’ll find there more information in useful links. CodeGym Lecture 1 Discussion Here is also an awesome book «Thinking in Java». It’s a must-read for every Java programmer. The book isn’t aimed at newbies at all, but still it will help you understand a difficult subject. If you get what is written there, I’ll be proud of you.

10 Elly

- Hey, Amigo! Diego and I have a break and we are telling jokes, wanna join? - Of course! A young man studying in a college abroad sent this SMS to his father: Dear dad, no mon, no fun, your son. The father replied: Dear son, too bad, so sad, your dad.

11 Diego

- It’s my turn. Listen to this one: There was a student who was desirous of taking admission for a study course. He was smart enough to get through the written test, a GD and was to appear for the personal interview. Later, as the interview progressed, the interviewer found this boy to be bright since he could answer all the questions correctly. The interviewer got impatient and decided to corner the boy. "Tell me your choice;" said he to the boy, "What's your choice: I shall either ask you ten easy questions or ONE real difficult. Think well before you make up your mind." The boy thought for a while and said, "My choice is ONE real difficult question." "Well, good luck to you, you have made your own choice!" said the man on the opposite side. Tell me: What comes first, Day or Night?" The boy was jolted first but he waited for a while and said: "It's the DAY, sir." "How???????" the interviewer was smiling ("At last, I got you!" he said to himself.) "Sorry sir, you promised me that you will not ask me a SECOND difficult question!" Admission for the course was thus secured.

12 Julio

- Hey, Amigo! - I think you’ve had worked long enough today. - How about a well-earned break?

  • Popular
  • New
  • Old
You must be signed in to leave a comment
This page doesn't have any comments yet