Types of classes

Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don't hold it against me. One of the perils of having a 20+ year old website!

Today and over the last couple of days we have been talking about classes in Java. I’m fairly certain I understand them enough to now talk about them here. Tonight I will introduce them and continue the discussion later.

Basically, a class “consists of a collection of types of encapsulated instance variables and types of methods, possibly with implementation of those types together with a constructor function that can be used to create objects of the class. A class is a cohesive package that consists of a particular kind of compile-time metadata. A Class describes the rules by which objects behave; these objects are referred to as “instances” of that class. …” In basic terms, it is the blue prints of an object. Inside of a class, you will find instance varibles with values, methods to manipulate these variables, and constructors of those objects. If we were to make a class called Student , it might look something like this:

public class Student{

private String name;
private int age;
private float gpa;
private char status;

public Student (String stuName, int stuAge, float stuGpa, char stuStat){
name= stuName;
age= stuAge;
gpa= stuGPA
status= stuStat

}
public Student(){
name= “”;
age= 0;
gpa= 0.0;
status= null;
}

}

This class has 2 methods- both constructors- and 4 instance variables in it. The variables are initialized, but have no values. This is where the constructors come in. The first constructor for Student has 4 arguments sent to it. One for name, age, gpa and status. The constructor takes these 4 values sent by the client (NOT necessarily a user) and applies them to our 4 instance variables. The second constructor, which has no arguments, simply creates an object where all of them variables are set to nothing values.

For right now we only have constructors in our class. Next time, I will talk about other possible methods for our Student class, and subclasses that might inherit out Student class. Later

PS- to read ahead, and check out the counter class we have been working on in class, you can find it here
I know this was a little rushed, so if you have any questions, feel free to comment them or email me.

Similar Posts

  • |

    WordPress and .gitignore

    Updates have been added after the jump! In the coming weeks I’ll likely put a lot of my own personal code (as in, not code people pay me to write) in public repos on Github. A lot of my work is WordPress related so I’ll make a local repo at the root of some WordPress…

  • Use Input Masks for Better UX and Easier Validation

    Recently I was developing a few forms for a project at work and wanted a fairly specific format for the input of one of the fields. It was a time of day, and since the <time> element isn’t very well supported in browsers yet, I opted for my own text input and validation. While I…

  • |

    About Coding with AI…

    Telling an AI to make an app is not app development, just like telling a 5 year old to draw a Picasso isn’t a Picasso.

  • |

    How to Learn a New Programming Language

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website! As I said in the last two posts, Google I/O was truly inspiring. It got me to thinking about how…

  • |

    Gloss WordPress Plugin

    Note: This article was published while I was in my early 20s. I was much younger and dumber. Please don’t hold it against me. One of the perils of having a 20+ year old website!Today, I officially released my first public WordPress plugin, Gloss. Gloss is a dictionary/glossary management plugin I decided to build which…