Old Level 10

Published in the Java Developer group

Not higher not education

Old Level 10 - 1Let’s ask ourselves a question: why people enter the college? Remember that simple phrase: if you don’t study hard you’ll be a waiter all your life. You can even think that all people who go for higher education hate being waiters. So what do they want? They want a job on the opposite social side from waiter. People enter colleges to get well-paid, highly qualified jobs! So that they can buy a house and a car. Get everything; at least sometimes (middle class definition). People think that college education guarantees well-paid, highly qualified jobs. It doesn’t. But colleges keep quiet about it, and we keep thinking magical “I’ll get a good job when I graduate”. 5 years in a good college won’t get you an inch closer to your “good job”. That is why:

1. Teachers in colleges can’t teach you to be good specialist.

Give yourself a straight answer to this: people that teach you work in colleges getting paid modestly, don’t they? That’s because they cannot qualify for good positions on the labor market. They lack experience as well as qualification. The ones that don’t lack it – leave. It all different in world’s best universities, but we’re not speaking of those now. What’s your opinion: will a successful finance specialist go work for a bank earning $150,000 a year or teach in a college earning $60,000 a year? It often happens that looser-professionals teach in colleges, ‘cause they were unable to find a different job. There are exclusions, but they are scarce. I met good teachers in colleges, they really exist there. But that’s not even minority, they are very few. A good teacher not only gives you theory, but emphasizes the practical side of his subject. Most teachers don’t care about practice.

2. Teachers in most colleges praise science but despised professional realization

You should look for the roots of it in the fact that most teachers failed as professionals. And the only way to find an excuse is that professional realization is unworthy occupation. If you attend lectures and then participate in scientific conferences – you’re swell. And if you skip a lot because you work – well, you get a totally different treatment. Teachers are like hermit-monks. Profession is vanity of vanities for them. They’ve devoted themselves to serving god science and they pray write scientific articles all day long. Maybe the aim is noble, but it’s useless in real life. Old Level 10 - 2

3 Wrong etalon of comparison.

College students often compare themselves to school-students and are proud to be better. This illusion continues until a person starts thinking on getting a job and turns his gaze to another side. In fact if students compared themselves to working specialists they would see that they are getting to their goal in tiny-bitsy steps. Don’t be average in college. Because if you do “like everyone does” you’ll get the result “everyone gets”. Most students in a college are randoms, they don’t really have any other options. Perhaps they were forced to enter the college by their parents and they have no slightest idea of their future profession. This happens a lot. Don’t compare yourself to your mates. Your finished projects and your job successes will serve the best criteria for your knowledge and skills. Don’t compare yourself to “the faceless crowd”; compare yourself to “the market”.

4 Professional studies is only a small part of knowledge you get in colleges.

When you come to work you’ll be asked what you can do, not what you have learned. Your boss will be interested in what you know and able to do on the requirement list for the job: you are given a specific task, but you don’t get explanation on how to do it, and he expects results in due time. Good luck! You learn history in college, and you are going to work as a bank operator – is this brings you closer to your goal or farther from it? Technically, you know more. Does it mean it brings you closer? But in fact, with every semester you have less and less time to gain valuable professional knowledge and its amount remains the same. So practically – you’re farther from your goal.

5. College does not set a goal of “making you a highly-qualified specialist”.

It’s hard to hit a goal when you don’t aim it. In college they make you an all-round specialist. You get something like “second secondary education”. They only forget to mention that a person who studies everything knows nothing. Do you remember the three university goals: science, general education and professional education? What do you think had to be cut up in order to add science and general education? Right: professional disciplines. And do you still think that university’s goal is to make you a highly-qualified specialist?

6. If a person studies more than two subjects at once, he’s wasting his time.

This seems wrong after school education. You only get the truth of it at work. Classes are so short in school not because it’s effective, but because a school-student is still a child, he can’t keep concentrated for more than an hour. But often switches between tasks prevent your brain to think effectively. At work you’ll need to perform as an adult, and there switching between task often will strongly reduce your efficiency. Why do you think you can prepare for exams in no time? You simply do not multi-task and your effectiveness increases in times. Learning something in small pieces is utterly stupid. Just imagine you’re dieting only six hour a week – how soon will the result come?

7. In college a person only touches the subject slightly.

Let’s assume you study something for two semesters. You have two lectures and two practical classes a week. That some serious approach as for college. So how many hours does that make? Four classes is 2 academic hours (1.5 usual hours) – that’s 6 hours a week. We study for four month in the first semester: September, October, November, and December. 4 more in the second one: February, March, April, May. In total: 8 month, 4.5 week each. 6 hour each week. That makes 216 hour a year. Just so you know, my dear students, that there is 180 working hours in month. Any annual course can be learned in one and a half month, and if you really want (or need) in one month.

8. You are being taught most general, practically useless and outdated knowledge.

Old Level 10 - 3Each knowledge has different values depending on the problem you have to solve. When you are drowning knowing how to swim is much more useful than the philosophy course you’ve learned, right? And if you get a job as a cashier knowing how to count is better than knowing Latin language on basic level. Most useful part of your professional realizations is, without doubt, practical experience and being familiar with recent advances of your profession. Your college teacher most likely had never had any practical experience and is unfamiliar with latest advancements. And even if he read about them somewhere, he has no idea of their value and the field they are applied to. Even if you learn 100 useless subjects they won’t stand for 10 useful.

9 Practical skills are 10 times more valuable than theory.

In real life you often have to DO something at work. If you know how to do it, or you think that you know, it does not necessarily mean you can actually do it. You know smoking is bad for you, but can you quit? You know doing sports is the right thing to do, but are you actually working out? You know foreign languages are good for your career, but can you actually learn a few? In life all that matters is practice. The more knowledge you have without practice, the less is their value. How are you going to decide which knowledge is wrong, old, misused, and which really work? You never thought about this? Welcome to the real world. You can learn traffic regulation on A or B, but you still won’t be able to drive. Theory is a good ground for practice. Let assume you are building a wall: bricks are practice, grout is theory. Without grout (theory) the wall will be unstable, but without bricks (practice) your theory is useless. So, gentlemen, divide your 5 years in college by 10. Half a year – that’s the true result of your longstanding “effort”. You want proof? When you get a job and work for half a year you’ll see that your college knowledge doubled.

You have reached a new level

Level 10

Old Level 10 - 4

1 Elly, About the strong typing of objects

- Hey, Amigo! - Hey, Elly! - I’m in a cheerful mood today, so I’ll tell you something very interesting. I’ll start with primitive types in Java. - In Java, every object and every variable has its hardcoded immutable type. The type of a variable is defined during the program compilation, the type of an object - during its creation. The type of the newly created object and/or the variable remains the same all their lifetime. Example: Old Level 10 - 5- But there are a couple of interesting details that you should remember. - First, a reference variable not always stores the object of the same type as its own type. - Second, in the interaction of the variables of two different types, they must first be converted to a common type. - What about the division? If we divide 1 by 3, we get 0.333(3). Isn’t it? - No, it isn’t. When you divide two integers, the result is also an integer. If you divide 5 by 3, then the answer is one and two in the remainder. The remainder is thus discarded. - If you divide 1 by 3, we get 0 (and 1 – the remainder is discarded). - What should I do if I still want to get 0.333? - In Java, before dividing two integer numbers it’s best to cast one of them to a real (fractional) type by multiplying it by real number 1.0 . Old Level 10 - 6- Got it.

2 Risha, List of basic types

- Hey, Amigo! - Hey, Risha! - You already learned the basics of Java syntax, but I wanna tell you some things more detailed. - Today I’ll tell you a little about the primitive types and how much memory they occupy. You’ll need it, and perhaps even today. These types are: Old Level 10 - 7- I’ll detail each type. - The type byte is the smallest type of integers. Each variable of this type takes only one byte of memory. So it can store values in the range of -128 to 127. - Why do we need such a small type? Why not use int everywhere? - You can do it. But if you create huge arrays, and you don’t need to store values more than 100 in there, then why not to use this type? Am I right? - The type short is twice as long as the type byte and it also stores only integers. The largest number that fits in it is 32767. The largest negative number is -32768. - You already know the type int. It may store integers up to two billion, both positive and negative. - The type float is created to store real (fractional) numbers. Its size is 4 bytes. - All fractional numbers are stored in memory in a very interesting form. - For example, 987654.321 may be represented as 0.987654321*106. Therefore, in the memory it’s represented as two numbers «0.987654321» (the significand) and «6» (the exponent - the power of ten) - Why is that so difficult? - Such internal structure of variable enables to store much larger numbers than int, using only 4 bytes. But thus we give up accuracy. A part of memory is used to store exponent, so fractional numbers keep only 6-7 digits after the decimal point and the rest are discarded. -These numbers are also called floating point number. By the way, hence the type name – float. - I see. - The type double is the same type as float, but twice (double) as long - it occupies eight bytes. The maximum exponent size and the number of significant digits in this type are bigger. Use this type if you need to store real numbers. - Type char is a hybrid type. Its values can be interpreted both as numbers (which you can add and multiply) and as characters. This was done because though characters have a visual representation, for the computer they’re just numbers. It’s much easier to use them as numbers. There’s one more comment: the type char is strictly positive. It cannot store negative values. - The type boolean is a logic type, it can store only two values: true and false. - The type Object, though presented in the table, is not a primitive type. This is the base class for all the classes in Java. First, all the classes are considered inherited from this class, and therefore contain its methods. Second, it can be assigned object references of any type. Including the null reference. - I’ve learned a lot. Thanks for the lecture, Risha.

3 Elly, Type conversion. Type widening and narrowing.

- And here goes the fun. I’ll tell you about the type conversion. Though the types of variables are always the same, there’s a place where you can convert types. It’s an assignment. - You can assign variables of different types to each other. By so doing, the value taken from a variable of one type will be converted to a value of another type and assigned to the second variable. - So there are two types of conversion: the widening and narrowing. The widening is like moving things from a small basket into a bigger one - the operation is smooth and trouble-free. Narrowing is like putting things from a big basket into a smaller one: there may not be enough space and something will have to be thrown away. - Here are types sorted by the size of the «basket»: Old Level 10 - 8- There are a couple of comments:
  1. char is the same “basket” as short, but there is one point: when coping values from short to char, values less than 0 are discarded. When coping from char to short, values greater than 32,767 are discarded.
  2. When converting integers to fractions, low-order digits may be discarded. But since the fractional number is meant to store an approximate value, then such an assignment is allowed.
- When narrowing the type you must clearly show the compiler that you are not mistaken and discarding a part of a number on purpose. To do this, use a type cast operator. It’s a type name in parentheses. - Here’s how to assign variables of different types: Old Level 10 - 9 - A type cast operator must be declared before a number/variable each time a part of a number is discarded or type narrowing occurs. The operator applies only to the number/variable that follows right after it. Old Level 10 - 10- I see.

4 Diego, Integer type conversion tasks

- Hey, Amigo! Here are your tasks on conversation of integer types. You need to put cast operator where needed, so the program compiles:
Tasks
1 1. Type cast and conversation
byte a = 1234;
int b = a;
byte c = a * a;
int d = a / c;
2 2. Type cast and conversation
int a = 15;
int b = 4;
float c1 = a / b;
float c2 = (float) a / b;
float c3 = (float) (a / b);
3 3. Type cast and conversation
float f = 333.50;
int i = f;
byte b = i;
4 4. Type cast and conversation
short number = 9;
char zero = '0';
char nine = zero + number;
5 5. Type cast and conversation
short number = 9;
char zero = '0';
short nineCode = zero + number;

5 Elly, Conversion to the type String

- Now we’ll have a small, but interesting topic - String conversion. - In Java, you can convert any type of data to the type String. - Sounds promising. - In fact, it’s even better. You can implicitly convert almost all types to String. This is best shown when you add two variables: String and «non-String». In such case the non-String variable is forcibly converted to String. - Here, take a look at a couple of examples: Old Level 10 - 11Conclusion: If we add a String to any other type, the second object is converted to String. - Pay attention to the fourth row of the table. All the operations are executed from left to right, so the addition of 5 + ‘\u0000’ occurs as the addition of integers. - So if I write a code like String s = 1+2+3+4+5+"m", then I get s = "15m" ? - Yeah. First, the numbers will be added, and then converted to a string.

6 Diego, Tasks on conversion of types in general

Old Level 10 - 12- And now, a little lecture by Diego. Short and to the point about the reference types. - So far, we begin with a variable of Object type. This variable can be assigned a reference of any type (type widening). In order to do the inverse assignment (type narrowing) we have to explicitly specify a cast operator: Old Level 10 - 13- There are no changes in the object when reference to it is changed. Type narrowing and type widening on assignment is checking the compatibility of reference variable type and object type. - Wow, it is much clearer now. Thank you, Diego. - To avoid errors, as in the examples, there’s a way to find out what type is stored in a variable of the type Object: Old Level 10 - 14- It’s better to make such check before each type narrowing if the type of stored object is a totally unknown. - Got it.

7 Elly, Real types

- Here are a couple of interesting things about the real (that are fractional) types. Let’s start with this example: Old Level 10 - 15- As a result of this calculation the value of f is equal to … zero! - Risha told me something like that … - Oh, really? It’s good. Practice makes perfect. - In fact, there’s no mistake in example. When one integer number divides by another integer number, the result is also integer; remainder of division is just discarded. To avoid this, make sure that at least one of the two numbers involved in the division is fractional. - If one of the numbers is fractional, the second number is first converted to a fractional type, and then the division follows. - Here’s how we can solve this problem: Old Level 10 - 16- And what if variables are involved in the division? - Then it goes like this: Old Level 10 - 17- But this doesn’t look good. Is there any more convenient division operator? - No. That’s all. - Well, okay, I guess, there’ll be no problem.

8 Elly, Literals

- And finally, a professor-style lecture by Risha, which is a whole lot of useless information. All lecturers love this. This one may seem hard to understand for you. So just have a look and do not give much thought to it. - OK, then I’m ready. - Today I’ll tell you what literals are. Literals are all the data stored directly in the Java code. Examples: Old Level 10 - 18- In fact, there are some more literals. Using literals, you can set values of any known type: Old Level 10 - 19- In other words, the code is methods, classes, variables,... and literals are specific values of variables stored directly in the code. Do I get it right? - Yes, you do. - Fine. Finally, I’m getting the picture of all this Java.

9 Professor, Lecture on types

- Great! Finally, this is my favorite topic - type conversion. I even remember when my professor told me about it. It was very “fascinating”. I didn’t understand anything then. But of course, you’ll understand everything thanks to these awesome lectures. Here they are: Java Conversions and Promotions (Oracle Documentation) Data Type Casting (Type Conversion) Java Cast and Conversions Widening and Narrow conversions

10 Julio

- Wow! Well, you’re really smart, Amigo! So many things learned in just two weeks! You’re like a monster. By the way, how about some fun after two weeks of slave labor?

11 Captain Squirrels

(- I’ve helped you out. Do it at home.) Homework (10 units) - Hello, soldier! - Good morning, sir! - I have some awesome news for you. Here’s a quick check to reinforce your skills. Do it every day, and you’ll enhance your skills real quick. Tasks are specially designed to do in Intellij IDEA.
Additional tasks to do in Intellij Idea
1 1. The correct answer is: d=2.941
Add one type casting operator to obtain d = 2.941
2 2. The correct answer is: d=5.5
Add one type casting operator to obtain d = 5.5
3 3. The correct answer is: d=1.0
Add one type casting operator to obtain d = 1.0
4 4. Big salary
Display to the screen the message «I don’t want to study Java, I want a big salary» 40 times following the example.

Example:
I do not want to learn Java, I want a big salary
do not want to learn Java, I want a big salary
do not want to learn Java, I want a big salary
o not want to learn Java, I want a big salary
not want to learn Java, I want a big salary
not want to learn Java, I want a big salary
5 5. The number of letters
Read from the keyboard 10 strings and count the number of different letters in them (for all 26 letters of the alphabet). Display the result to the screen.

Example output:
a 5
b 8
c 3
d 7

z 9
6 6. Constructors of the class Human
Write a class Human with 6 fields. Come up with 10 different constructors for it and implement them. Each constructor should have meaning.
7 7. Move a minimum of static modifiers
Move as few static modifiers as possible so the code compiles.
8 8. Array of string lists
Create an array whose elements are lists of strings. Fill the array with any data and display them to the screen.
9 9. Identical words in the list
Read from the keyboard 20 words, fill a list with them. Count the number of identical words in the list. Result should be a Map <String, Integer>. The key of the map should be a unique string, the value - count of this string in the list. Display to the screen contents of the map.
10 10. Five largest numbers
Create a list of integers. Read 20 integers from the keyboard and fill a list with them. Create a method to extract numbers from the list safely:
int safeGetElement(ArrayList<Integer> list, int index, int defaultValue)

The method should return an element of the list by its index. If an exception occurs in this method, you need to catch it, and return the defaultValue.
- Those tasks were for greens. I added bonus tasks of higher complexity. For top guns only.
Bonus tasks
1 1. Program doesn’t compile and run. Fix it.
Task: The program shows how HashMap works. The program reads from the keyboard a set of pairs (a number and a string), places them in a HashMap and displays to the screen the contents of HashMap.
2 2. Add new functionality to the program.
Old Task: The program should display a pair (a number and a string) entered from the keyboard.
New task: The program should store in HashMap pairs (a number and a string) entered from the keyboard. An empty string means the end of input. Numbers may be repeated. Strings are always unique. Input data must not be lost! The program should display the contents of HashMap to the screen.

Example input:
1
Stop
2
Look

Example output:
1 Stop
2 Look
3 3. Learning and practicing algorithm.
Task: Read from the keyboard 30 numbers. Display to the screen the 10th and 11th minimum numbers.
Hint:
The minimal number is the 1st minimum.
The next minimum is the 2nd minimum

Explanation 1:
1 15 6 63 5 7 1 88
The first minimum is 1
The second minimum is 1
The third minimum is 5
The fourth minimum is 6

Explanation 2:
0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87
36 0 6 9 39 42 78 12 15 30 33 63 66 69 3 81 84 87 45 48 51 54 57 60 72 75 18 21 24 27
69 36 0 18 21 6 27 9 39 42 78 12 33 63 66 3 81 84 87 45 15 30 48 51 54 57 60 72 75 24
The first minimum is 0
The second minimum is 3
...
The tenth minimum is 27
The eleventh minimum is 30

Example input:
36 0 6 9 39 42 78 12 15 30 33 63 66 69 3 81 84 87 45 48 51 54 57 60 72 75 18 21 24 27

Example output:
27
30
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION