Java for the masses!

Java Installation



On my Windows 11 Laptop, I went to Java Downloads | Oracle and downloaded the Java exe for x64 devices. I created a new repository for my class files in Azure Dev Ops, which I downloaded in Visual Studio Code, my IDE of choice. I had to add the JDK path to my system Path variables, after which I could compile and run a sample test file. Java Hello World Program - GeeksforGeeks


Object-Oriented Programming is the concept of creating classes to use as cookie cutters for creating objects that will contain desired behaviors. By combining these objects, coders can create system functionality in reusable chunks of code.

Objects are created as classes that will define a concept.
A car is an object with the following properties.
    Name
    Id
    Description
    Make
    Model
    Manufacturer
    Trim
    Year

You can create multiple instances of a car class as objects representing the cars in your sales lot.

Encapsulation

Encapsulation is the concept of controlling how the properties of an object are manipulated. Accessors are mechanisms for retrieving the properties without directly accessing them. Mutators are mechanisms for setting the values. Using encapsulation, you can hide the inner implementations of a class, allowing the structure to change as long as the external mechanisms remain the same.

Data Abstraction

This is the art of defining the shape of the objects we will work with. In the above car example, I did not include pricing data, tax information, or incentives, as I am only modeling enough information to display inventory. If I required pricing information, my abstraction of the car could accommodate adding these properties. For now, we will go with an attitude of only including what we know we will need.

Inheritance

Inheritance is a technique for sharing common functionality between classes. If we were going to list items at a street market, we might start with a simple concept of ItemForDisplay that includes a Name, Id, Picture, and Description. 

My car object could be rewritten as 
Car : ItemForDisplay
    Make
    Model
    Manufacturer
    Trim
    Year

And if we were also displaying guitars
Guitar: ItemForDisplay
    Manufacturer
    Strings
   
This allows us to guarantee the common properties for our item list will be treated the same. We can add behaviors and properties for the inheriting classes that allow them to model behaviors that are not held in common to all ItemsForDisplay.

Polymorphism

This is the strategy of having a method on a class that can be overridden by each inheriting class.
On my ItemsForSale I might have a GetDisplayText method, which, by default, provides the Id and Name. On my car, I can override GetDisplayText and have it provide Id, Make, Model, Manufacturer, and Year. On my Guitar, I might have it display Id, Manufacturer, and Name. Working with a collection of ItemsForSale, I can ask each to provide a GetDisplayText and get the specific version for the class I am working with through the common method that is overridden by the inheriting classes. 

This is a brief introduction to object-oriented programming. Grab an IDE and come back for more later!



Comments