Andrew Golovko
@andrewgolovko
Blog of a self-taught programmer writing about the experience, tips and other stuff
153 posts
Java

Theory: Call stack

When you write a program, it probably contains several methods invoking each other, either programmer-defined or standard ones, and all of them need to be executed. How does the machine understand the order of the execution? How does it switch between different methods? How does it know when the program execution is over? To shed light on these questions we need to learn about a special data structure — a call stack.

Thread Safety

Recall race conditions: multiple threads sharing the same mutable variable without coordinating what they’re doing. This is unsafe, because the correctness of the program may depend on accidents of timing of their low-level operations.

Theory: Map

In some situations, you need to store pairs of associated objects. For example, when counting the number of words in a text, the first one is a word and the second one is the number of its occurrences in the text. There is a special type of collections called map to effectively store such pairs of objects.

Theory: Set

When you need only unique elements within a collection, get rid of duplicates in a sequence, or intend to perform some mathematical operations, you may use a set.

Theory: Generics and Object

As you know, generics enable types to be parameters when defining classes (or interfaces) and methods. Parameterized types make it possible to re-use the same code while processing different concrete types.

Theory: The main method

Java is primarily an object-oriented language. It means a Java program can be considered as a collection of objects that communicate via calling each other's methods. A typical Java program includes a lot of classes, interfaces, objects, and other concepts from object-oriented programming.

Theory: Abstract class vs interface

Abstract class and interface are both tools to achieve abstraction that allow us to declare the abstract methods. We cannot create instances of abstract classes and interfaces directly, we can only do that through classes that inherit them.

Theory: Abstract class

Sometimes you have a set of fields and methods that you need to reuse in all classes within a hierarchy. It is possible to put all the common members to a special base class and then declare subclasses which can access these members. At the same time, you do not need to create objects of the base class. To achieve it, you can use an abstract class as the base class in the hierarchy.

Theory: Match results

A simple check whether a string contains a substring matching our regular expression is not the only thing we can do with a Matcherobject. It also provides us with additional information about matches, which is essential in some tasks.

Theory: Polymorphism

In general, polymorphism means that something (an object or another entity) has many forms.