Thursday, December 16, 2021

Java Installation and OOP Concepts

 

This week we start our explorations into data structures and algorithms through CPT 307: Data Structures & Algorithms. This course makes use of the Java programming language, and our first task was to install Java and an integrated development environment (IDE) of our choice. I followed the course guidance and downloaded NetBeans to use as my IDE. However, first I downloaded and installed the latest Java SE Development Kit. Installation was a breeze after deciding on which installation pack to download (I chose the MSI installer package). After installing, we were tasked with creating a simple “Hello World” program based on the tutorial provided. The tutorial was written based on an earlier version of NetBeans, and this video helped to fill in the gaps and successfully run my first program in Java:

 



Java is often referred to as an object-oriented programming (OOP) language. OOP is implemented through an organization of objects. To understand what that means, you should first understand what a class is. Nakov in Fundamentals of Computer Programming described classes as being descriptions or models of real entities, which possess characteristics and display behaviors. An object would be an instance of such a class. One of the great benefits of objects in programming is that they can be used to represent complex ideas in a simple way – that is we can use an object without necessarily understanding all its inner workings. This is one of the four key concepts of OOP and is known as abstraction. Abstraction makes programming easier and more flexible.

Inheritance is another essential property of OOP. It allows classes to maintain properties as they are passed down through a hierarchy. If a parent class possesses a certain property, then its child class inherits that property without the need to obtain it independently. A class can pass down traits to a superclass which can further pass down traits to subclasses as described in Oracle’s Java Tutorials.

Encapsulation is another main concept of OOP and refers to how variables of a class are hidden from other classes. Encapsulation can be achieved in Java by declaring variables as private. This allows control over what variables in a class can be read or written by other classes.

Polymorphism is a final major concept of OOP that we will discuss.  Java T point describes polymorphism by defining the Greek words it comes from: poly (many) and morphs (forms). In programming this translates to potential to perform a single action in more than one way. In Java, polymorphism can be implemented at either compile time or runtime and is achieved by method overloading or method overriding. Method overloading can happen when a class has multiple methods with the same name but different parameters. Method overriding works with inheritance and can happen when a child class has the same method as its parent class.

0 comments:

Post a Comment