Start learning now
You've leveled up!
The secret CodeGym center's second motivational lesson is dedicated to...CodeGym. The first levels pass by quickly, and sometimes beginners don't pick up on certain nuances. In this lesson, we'll talk about how awesome our programmer training center is, thereby motivating you to soak up the knowledge more actively.
In this lesson, we'll focus on objects. Basically, interaction between objects is what gives a program life and motion. And a class is just a blueprint for an object. Or a drawing, if you like. A programmer can create his or her own classes, or can use others' classes, creating objects or calling methods on existing classes.
Primitive data types
It's time to talk about how variables are arranged internally. If you hear something about "primitive" types of data, it doesn't mean they're any worse than others. The designation only indicates that they're not composites. That is, a primitive type does not consist of any other types. Primitive and complex types are stored in different ways in memory.
How do you like this line? Cat cat = new Cat(); At first, it's confusing: why are there cats and both sides, and why is it so complicated? In fact, this is the standard way to create an instance (object) of the Cat class, named cat. The keyword new signals that we are creating a new "cat". This lesson has the details about creating cats and other objects.
Visibility of variables
Programs are divided into blocks. A block can be a class, or a method, or an operator. Java variables can be seen from one block but not another. This may seem superfluous to the beginner, but it's actually very convenient (and very important!). This lesson introduces you to variable scope and access modifiers.
Different ways to create variables
There are different kinds of variables, and you can create them in different ways. For example, you can first create a variable and then (someday!) put a value in it. And you can do all this in a single line. You'll also learn the difference between creating primitive variables and creating objects (i.e. composite variables).
This lesson teaches you about the important difference between primitive and composite variables. For example, primitive variables contain an actual, but all other variables contain the address of an object. An object and a reference to it are related approximately in the way a person and her home address are related. Accordingly, objects interact with each other using references, and not directly.
Calling methods, returning values
A program without a method is like a planet without inhabitants. It could exist, but nobody would ever know. A method is a series of actions (or commands) combined under a single name. In fact, the method itself becomes a command, only a composite, more specific command. We'll learn to write methods and call them in other methods.
Practice calling methods
Methods, or as they are also called — functions, work like this: they take a value (or several), rework them, and return a result... Or they don't return a result — such methods also exist. It's just like in life: any action can be represented as a function. It's time to complete several tasks with methods that return values.
Full class name
A robot's full name consists of the manufacturer's name, the model, and a personal identifier. What about the full name of a class? You'll learn how to name classes properly so they can be accessed from anywhere. After this lesson, the name java.io.FileInputStream fileInputStream will be as clear and simple as "Albert Einstein".
Useful links from the Professor – 2
As usual, at the end of the level the professor gives you additional literature to study. You don't need to read everything at once. Gradually progress (not at the expense of completing the tasks!) is very desirable. Perhaps after your reading, some topic previously shrouded in mystery will become understandable and instinctive.
Game of Codes: a song of bytes and wire
After working religiously to master Java fundamentals, you can relax a bit and watch a movie about Java! Today's Nerd Break features something far more intense than the Game of Thrones… It’s the Game of Codes. Bootstrap yourself for an epic soft-war between Java and the Googlisters for the sake of APIs :) And don’t nod at Dave!