JAVA FUNDAMENTALS
Published: 2023-11-29 21:41:48

**OOP? Wut?**
Object-oriented programming (OOP) is a programming paradigm that organizes the code around the concept of objects, which can contain data and perform specific given actions. Many programming languages, such as Python, C++, and Java, are based on OOP. 

The main fundamental elements of OOP are classes, objects, methods, and attributes. 

Classes define the attributes and methods of the object we want to create.
An object is the instance of the class. It carries the methods and attributes written in the class.
Methods are a set of instructions defining the behavior of the object.
Attributes describe the characteristics of the objects. For example, if the object is a car, its attributes can be “speed,” “color,” “model,” etc.

Besides the elements, OOP has Fundamental principles, called 4 OOP Pillars, that help the developer write clear, effective, and well-organized code. There are four pillars: abstraction, encapsulation polymorphism, and inheritance.
 
Abstraction
Abstraction helps us hide away unnecessary details and simplify our code so that we can see what an object does, ignoring the process of execution. The best example of this is the remote. It has buttons that allow you to change the channels; however, you never open it because you don't really need to know how the internal system works.

Encapsulation
Encapsulation hides the internal details of an object's work and exposes only what is necessary for external use. Sounds quite familiar to abstraction; however, besides hiding away the internal data, encapsulation allows access and modification of hidden data only through specific methods to restrict direct access to the components. For example, imagine there is a bank, and inside the bank, there is a certain amount of money. Here, the bank has the role of a class, and the money inside is your private data. In this context, encapsulation means you cannot see the money directly because it's hidden from direct access. However, the only two ways you can interact with it are by putting money in or taking it out. These actions represent the methods of the class. You don't need to know exactly how the bank stores the money, but you can use the method to interact with it.

Inheritance 
Inheritance allows a new class to inherit the attributes and methods from an existing class. This way, you can reuse the same code for several classes, defining it only once in an existing class, which is the mother class. In the same way, children inherit common traits from their parents while having some unique characteristics that their parents don't have.

Polymorphism
Polymorphism lets us use the same method for different classes and allows each class to provide its own unique execution of that method. A good polymorphism example is the brushes. They share the same common method which is “draw”. However, each of them provides its unique style.


**Java fundamentals**
Java is an object-oriented programming language widely used for developing desktop, web, and mobile applications. It was created by Sun Microsystems in 1995. 
Java is platform-independent, which means it can run on any device. If we want the program to execute in Java, first, we must install Java Development Kit (JDK), which contains all the necessary tools, such as compiler, JRE, JVM, java docs, etc. 
Java Compiler (JAVAC) is responsible for translating Java code into bytecode.
Java Runtime Environment (JRE) is a software package containing many necessary tools, such as JVM, to execute Java applications. It doesn’t have the Java compiler, though.
Java Virtual Machine (JVM) allows Java programs to be platform-independent. It translates the bytecode provided by JAVAC into machine code specific to the underlying software system.

**Types in Java**
Types in Java specify different data sizes that can be stored in variables. It has two categories: primitive and non-primitive. 
Primitive types are the most basic types available in Java, so they cannot be further divided into even more primitive types. Those are byte (8-bit signed integer), short (16-bit signed integer), int (32-bit), long (64-bit), float (32-bit, represents numbers with decimal point), double (64-bit, represents numbers with decimal point), Boolean (the only outputs are true and false), and char (16-bit).
Non-primitive types can be used to store multiple values, and they always start with capital letters. Non-primitive types can contain primitive and non-primitive types in themselves. Some non-primitive types in Java are class, string, and array.
A string is a sequence of characters, such as “I have tons of hw to do.”
An array is a type that can store a fixed-size sequence of elements of the same data type.