Java fundamentals and OOP in Java

oganesyan

Aren

Posted on November 29, 2023

Java fundamentals and OOP in Java

JVM, JDK, JDE

Java is a language that can be run on any device, from the computer to the refrigerator. This is possible if we have specific software that allows us to compile Java to a code the machine will understand. So what are those JVM JDK and JDE?

JVM (Java Virtual Machine):

Imagine you have a particular computer inside your computer. This specific computer understands and executes Java programs. Pretty simple, right?
When you run a Java program, the JVM is responsible for translating and executing the Java code on your computer, regardless of the hardware or operating system you use.

JDK (Java Development Kit):

Think of the JDK as a toolbox for Java developers. It contains all the tools, executables, and binaries needed to develop, compile, and run Java applications.
The JDK includes the Java compiler (which turns Java code into something the computer understands), various development tools, and the JRE (more about later), essentially the JVM plus some libraries your Java program might need to run.

JRE (Java Runtime Environment):

Picture this as a part of the JDK. It's what you need to run Java applications on your computer.
What it includes: The JRE consists of the JVM (so it can execute Java programs) and some libraries the programs might need to run.

So, to conclude in a few words:

JVM runs Java programs.
JDK is a developer's kit containing tools to develop, compile, and run Java programs.
JRE is a part of the JDK, containing what's needed to run Java programs without development tools.
Think of it like baking a cake: every mentioned part is an ingredient to make a perfect and yummy cake!

Types in Java (primitive and non-primitive()

There are two main types of variables in Java; among them are primitives like numbers, single characters and booleans and non-primitives like classes, arrays, interfaces and strings.

Primitive Types:

These are the simplest types that store basic values.

Examples:
byte: 8-bit signed integer.
short: 16-bit signed integer.
int: 32-bit signed integer.
long: 64-bit signed integer.

Floating Types:
float: 32-bit float number.
double: 64-bit float number.

Other:
char: 16-bit Unicode character.
boolean: Represents true or false.

Non-Primitive Types

These types refer to objects in Java, which are instances of classes.
Examples:
String: Stores a sequence of characters.
Arrays: Stores a dynamic list of elements.
Object: The superclass of all classes in Java.
Interfaces: Allows the creation of interfaces, which are like blueprints for classes.

Primitive vs Non-primitive Types:

Primitive types store the actual values, whereas reference types store references (memory addresses) to objects.
Primitive types are faster and use less memory because they directly store values.
Non-primitive types are "heavier" as they can represent complex structures.

OOP and Four Pillars

Object-Oriented Programming (OOP) is a programming way used in Java and many other languages. It works around the concept of "objects," which are instances of classes that encapsulate data and behaviour. OOP in Java is based on four fundamental principles known as the "Four Pillars of OOP."(Thank you, Wiki :D)

1. Encapsulation:
Imagine a capsule or container that holds data and the methods (functions) that can operate on that data. So everything is stored here.

2. Inheritance:
Think of inheritance as passing on traits or characteristics from a parent to a child.
You can create a new class that is a "child" of an existing class, inheriting its attributes and methods( like color of eyes, hair, height and etc.).
3. Polymorphism:
"Poly" means many, and "morph" means forms. So, think of polymorphism as something that can take many forms.
It is used when we can inherit parental class attributes,and even add our own or modify them.
4. Abstraction:
Abstraction involves simplifying complex systems by modelling classes based on essential properties and behaviours. In other words, we just use something and do not bother about how it works.

💖 💪 🙅 🚩
oganesyan
Aren

Posted on November 29, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related