Skip to main content

CPT 307: Java Newbie to Newbie

     For our first assignment in CPT 307: Data Structures & Algorithms, we were tasked with installing the Java Development Kit (JDK) and the NetBeans IDE.  Installing the JDK was straightforward and painless.  It was as simple as downloading the installer and following the installation wizard.  NetBeans was a slightly different story.  There were several different packages to download; I chose the package with the most language support.  In hindsight, I probably should have downloaded only the package supporting Java, saving the other packages for when I actually use the other tools.  After completing the NetBeans install, I kept getting an error about “GlassFish” whenever I tried creating a new project.  I attempted to search the forums for a fix but found the NetBeans forums to be extremely confusing, and I could not find a solution to the issue.  So I decided to search the internet for a different IDE to work with.  What I found was the IntelliJ IDEA.  JetBrains packed their IDE full of cool features and a massive library of plugins that can be downloaded.  It also included a fascinating auto-complete feature.  The install for IntelliJ was just about as easy as the install of the Java Development Kit (JDK).  Once the install completed, I searched the IntelliJ forums for a “Getting Started Guide,” and the first result was exactly what I was hoping to find.  The tutorial guided me through creating a new project, creating a new .java file, and completing the code for a “Hello World!” program.  After completing our initial program named “Hello, My name is” I moved on to complete the reading assignments given to us.

     The first page that I went to was the “Object-Oriented Programming Concepts” page on docs.oracle.com.  This page is the basic tutorial on OOP and describes principles that you need to know to program in Java successfully.  The page defines an object, a class, inheritance, an interface, and a package.  When observing the world, a person can quickly identify many real-world objects.  Each object shares two characteristics: state and behavior.  A pet can have state (name, color, breed, any valid descriptor) and behavior (barking, fetching, any valid action).  Like real-world objects, software objects also consist of both state and behavior.  When a software object stores state, the state is stored in fields or variables.  The behavior of a software object is determined by its methods or functions.  Methods operate on an object’s internal state and serve as the communicator between objects.  The site defines data encapsulation as when internal state is hidden, and all interaction is performed through an object’s methods.  Encapsulation is a fundamental principle of OOP.  Next, the tutorial explains what a class is.  In the physical world, you can observe many different objects of the same type.  For instance, you can observe cars with the makes of Toyota, Chevy, Subaru, Jeep, etc.  Each car is essentially the same, but each is still a car.  In OOP, we can say that a Toyota is an instance of the class of objects known as cars.  The class is the blueprint out of which individual cars will be created.  Next is an inheritance, where it begins by stating that in the Java programming language there can be one direct superclass for any regular class.  When using the example of bicycles, the bicycle class can be a superclass.  The subclasses of bicycle can be mountainBike, roadBike, tandemBike.  Each subclass will inherit specific properties that belong to all bicycles, but each subclass can then also define the properties that make it unique compared to any other bicycle subclass.  The tutorial states that the blank methods of an object from the object’s interface.  The interface determines how the object will interact with the rest of its program.  Finally, the tutorial defines a package as a namespace that organizes a set of related classes and interfaces.

     The second article that I read through was “4 Major Principles of Object-Oriented Programming.”  The article describes the four major principles: Encapsulation, Abstraction, Inheritance, and Polymorphism.  The article describes encapsulation as ‘…the hiding of data implementation by restricting access to accessors and mutators.”  Following the definition, the article elaborated on the definitions of both the accessor and mutator.  An accessor is defined as a method that is used to ask an object about itself.  When an accessor is related to OOP, the accessors are usually methods used to view properties that belong to an object.  In programming languages, the get method is an accessor method.  The article then describes what a mutator is, giving the definition “…public methods that are used to modify the state of an object while hiding the implementation of exactly how the data gets modified.”  In a similar way to accessors, a mutator method interacts with the properties on an object.  In programming, a set method is an example of a mutator.  In other words, a mutator method will change the value of the property it is being called by.  Abstraction is an attempt to simplify a program by focusing on the development of classes, objects, and types in terms of their functionality and interfaces.  Abstraction is a model, view, or some other representation of an object, rather than how an object is implemented.  Basically, abstraction is the name of an object, while the implementation details are the actual lines of code for the object.  From there, the article moves on to inheritance.  When an object is created with inheritance, it will inherit defined properties from its parent object.  In a file system, a folder will inherit the properties and permissions of the folder it is inside of.  Inheritance also helps to simplify coding.  By only having to name properties once, and then transferring those properties to other objects, the code will be simplified by eliminating duplication.  Polymorphism is used to define how one task can be performed in multiple different ways.  For example, the task “to speak something,” can be accomplished by “a cat speaks meow, a dog barks woof, a human speaks words.”  In Java, achieves polymorphism by using overloading and overriding methods.

     Between all of the articles, OOP is a way to keep programming software modular and easily adaptable.  Whereas, procedure-oriented languages get exponentially more difficult to manage as the amount of code changes and grows.  OOP also provides a way to hide data, versus procedure oriented that allows global data to be accessed from anywhere.  Actually, I am not entirely sure what procedure-oriented languages are, and I will definitely need to do my own research to identify the real differences.


References:

Java OOPs Concepts - Javatpoint. (n.d.). Retrieved October 17, 2018, from https://www.javatpoint.com/java-oops-concepts

Lesson: Object-Oriented Programming Concepts. (n.d.). Retrieved October 17, 2018, from https://docs.oracle.com/javase/tutorial/java/concepts/index.html

Lewallen, R. (2005, July 19). 4 major principles of Object-Oriented Programming. Retrieved October 17, 2018, from http://codebetter.com/raymondlewallen/2005/07/19/4-major-principles-of-object-oriented-programming/



Comments

Popular posts from this blog

CPT 200: Fundamentals of Programming Languages

    During my quest to obtain a Bachelor of Information Technology from Ashford University, my fourth class was CPT 200: Fundamentals of Programming Languages.  For that class, the programming language that is taught is Python 3.     On the first week of class, we were asked to create code that would ask a user to input several pieces of information about any specific employee.  We were to use the variables: employeeName, employeeSSN, employeePhone, employeeEmail, and employeeSalary.  After the data was inputted, it needed to be printed on the screen.  Below was what I turned in for Functionality 1:     During the second week of class, we were to read two chapters: Chapter 3: Types and Chapter 4: Branching.  These chapters introduced us to the different types of variables that can be used within Python as well as how to use branching in your scripts. For the second functionality, we were instructed to adjust our code to allow for 5 different employees to be input into the system

CPT 200: Employee Management System Final Project

import sys import csv employeeList = {} employeeImport = {} lstMenuOption = ('1', '2', '3', '4', 'Q') edtMenuOption = ('1', '2', '3', '4', '5', 'Q') validation = False #initialize validation check to "False" menuSelection = None numEmployees = None num = 1 def cls():     print('\n'*50)     def main_menu():     totalEmployees = len(employeeList) #Display number of employees in the databse     print('{:~^79}'.format('~'))     print('{:~^79}'.format('                              '))     print('{:~^79}'.format('  Employee Management System  '))     print('{:~^79}'.format('          James Hardy         '))     print('{:~^79}'.format('                              '))     print('{:~^79}'.format('~'))     print(' ')     print('{:^79}'.format('There are (%d) employees in the

CPT 200: Functionality 3 - Loops and Functions

import sys employeeList = {} lstMenuOption = ('1', '2', '3', 'Q') #i = 0 #loop count variable validation = False #initialize validation check to "False" menuSelection = None numEmployees = None num = 1 def main_menu():     print('-----------------------------------------------------')     print('(1) Add new employee(s)')     print('(2) View all employees in the database')     print("(3) Check employee's information")     print('(Q) Exit\n')     totalEmployees = len(employeeList) #Display number of employees in the databse     print('There are (%d) in the database' % totalEmployees)     print('-----------------------------------------------------')     option = input('Please select an option from the menu: ')     return option def valid(option): #Function to validate menu selection     if (option.isnumeric() == True):         if option in lstMenuOption:             return True