Java: Navigating the World of Versatility and Code Elegance
Meline Afrikyan
Posted on November 30, 2023
Java is a programming language used to develop mobile apps, web apps, desktop apps, games and much more. The first version of Java was developed in the 1990s. Its future’s original vision was a programming language that could operate on various platforms, thus simplifying the tasks of writing compilers(translation programs) for each class of appliances. So, the creating team decided to use for Java a two-step translation process.
When using any development environments for Java on any computer, there is a complex process happening between hitting the button run and seeing the output of our code on the console. When we hit the button run, the human-readable code is firstly translated into byte-code which is a form of intermediate language that is understandable by any computer. Then that byte code with the help of Java Virtual Machine is translated to machine language and executed, so we see the output of our code on the console. And by the way, the process of translating some form of code to other is called compilation, so let’s refer to it like that for the future.
Although the described process seems pretty straightforward, there was one term that may have been weird to encounter- JVM or Java Virtual Machine. So what is Java Virtual Machine?
JVM is basically a virtual computer inside your computer. When we install some integrated development environments for java on our computers, that environments generally have JVM, and the role of JVM is to take the byte-code of our original code and translate it to machine language so that our computer can understand it and output it on the console. Since we’re on the topic, let’s also explore some concepts related to JVM. JVM, in general, is contained in the Java Runtime environment(JRE), which is a package that contains important class libraries for Java(we’ll explore classes later in the post). And JRE is contained in Java development kit(JDK) which is basically a software development package that contains the tools and libraries needed to develop, test and run Java applications. And all of these are essential parts of the process of compiling and executing the Java codes that we developers write.
Java is an OOP language. OOP stand for object-oriented programming which basically means that everything is regarded as objects. And in Java that objects are in fact called objects. So if we want to develop some game with Java, and for example that in that game there are characters, there are some different worlds the characters might appear in, all of that are regarded as objects.
We know that there can be many kinds of the same object, like a bicycle can be big, small, yellow, red, with 4 wheels, with 2 wheels, etc. But they are all bicycles because they have the same components, there were in a sense constructed from the same blueprint. That blueprint in Java is called a class. Object of similar type or kind are in the same class and that classes are the blueprint for the creation of other objects. Also we know that objects aren’t just useless. They do something. The actions carried out by object are called methods.
In java we’re working with data of course. And for that data there are data types. There are primitive and non-primitive data types. Primitive data types are predefined in Java. Non-primitive types are created by the programmer and is not defined by Java. Examples of primitive data types are boolean(values true and false), char(single character) or int(integer). Non-primitive data type examples are strings, arrays, classes. So basically non-primitive data types are constructed from primitive data types. Also non-primitive data types can be used to call methods, while primitive can’t.
We spoke what is OOP, and know let’s discuss what are the 4 important pillars of OOP. First important pillar is abstraction, which is basically the filtration of the unnecessary data to use the only data we need. More correctly defined, we abstract complex systems and model classes based on the essential properties we need. Inheritance allows a class to inherit the properties, behaviours, methods from another class. Polymorphism enables different methods and classes to take on multiple forms, so basically during inheritance polymorphism allows the subclass to do different actions or operations and that is not being reflected on the superclass. And encapsulation is the process of bundling data and methods into a single unit and restricting access to their implementation. The user will only have access to the class, it’s methods and objects, but not their implementation.
Posted on November 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024