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

  • How Do We Best Teach Programming to Beginners?

    I’ve been thinking a lot lately about how I teach. I tend to take a “learn by doing” approach in my online courses where there are very clear, step-by-step instructions completed via video. However, this format gets pretty tough to execute in other contexts. For example, I teach an online graduate course for the University…

  • | |

    On the Personal Side of Things

    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!It’s been a while since I’ve posted on here or on Freelancing the Net. In my defense I’ve been extremely busy,…

  • |

    Sass, Sublime Text, Github, and Changing my Development Workflow

    When I left the full time freelancing world 2.5ish years ago, I had a very specific way I did things and I enjoyed it; however, admittedly, it wasn’t the best. I was using Coda, not making local copies, not using any form of version control, and my frameworks were becoming stale. I’ve been going to…

  • | |

    My First NETTUTS Tut

    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!Web Design tutorial blog NETTUTS published an article I wrote about Building a Facebook Appication Check it out! New post here…

  • |

    Using Remember the Milk for Assignments

    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! After reading about Gradefix over at College V2, I started thinking about the best way for me to keep track…

  • | |

    Fading Pages in Javascript

    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!I am not a huge proponent of Javascript. However, I recognize that it is becoming more and more powerful and used,…