ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

How To Study For A Java Computer Science Final Exam

Updated on December 12, 2011

When studying for a computer science exam, I recommend several methods. First, try to think of some sample problems that may be on the exam. If these problems are given to you, then great. Otherwise look at or think about past exams and practice with those. Try to reconstruct the answer to the problem on the computer without looking at the previous answer. Next, try to do this again from memory. Rewrite or retype the code out somewhere. Anywhere is fine, be it a sheet of paper or in the form of a hub (like me lolooooololo). This helps ingrain the code in your heart, not just in your head! It's also a good idea to put on some Basshunter or maybe even the Tron soundtrack. :)

Necessary Equipment:

You won't want to go into this session ill-equipped! You'll study best with a mechanical keyboard, especially a loud one, because it will make the environment that much more intense!! Plus, it will be durable enough to last during the millions of keystrokes you'll no doubt be inputting. It's also good to stock up on your favorite energy drinks. The nastier the better! Write now I'm drinking some NOS as I write this and I'm loving it!

You'll also need the Basshunter CD "Now You're Gone" and maybe even a Java reference book.

Java Vocabulary

First get acquainted with some Java vocabulary. If a test question mentions something from this list then you'll know exactly what they're asking for!

An Explanation of the Primitive Types in Java

There are eight primitive types in Java. Four of these are integer-based: byte, int, short, and long. Two model floating points: float and double. Finally there is the true/false boolean type and the char type.

byte - The byte is an 8-bit signed two's complement integer. They have a minimum value of -128 and a maximum value of 127. (-2^7 through 2^7 - 1)

int - The int is an 32-bit signed two's complement integer. They have a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647. (This translates to values between -2^31 and 2^31 - 1).

short, long - The short and long types are very similar except they are 16 and 64 bit signed respectively.

float - A float is a single-precision 32-bit IEEE 754 floating point. This basically just means it allows decimals and can be fairly long. Unless the situation calls for severe memory restrictions, a double is usually used instead.

double - A double is a double-precision 64-bit IEEE 754 floating point. They can be very, very long and are commonly used when decimal values are required.

boolean - A boolean can be either true or false. Unlike in other languages, 1 and 0 cannot be substituted for these as they are considered integers and not of the boolean type.

char - The char type represents a single 16-bit Unicode character. Strings are made up of characters.

Java Wrapper Classes

What are wrapper classes in Java? Well, put simply, they are classes that are built into Java that handle the primitive types for you! They enable you to add primitive types directly to data structures such as an ArrayList or a Stack. WOW!!! They also come complete with handy methods such as parse! Here is a list of the wrapper classes:

  • Byte
  • Short
  • Integer
  • Long
  • Float
  • Double
  • Boolean
  • Character

The Byte, Short, Integer, Long, Float, and Double wrapper classes are subclasses of the Number class. You can read more about that (and a more robust list of methods) here.

Java Wrapper Class Examples:

Integer.parseInt(String s);
Double.parseDouble(String s);
// etc. etc.

//In earlier versions of Java you needed 
//to use wrapper classes to
//add primitive types to ADTs.  
//Now it's done automagically. :)

Stack a = new Stack();
a.add(new Integer(9));

What Are Reference / User-Defined Types?

Reference types are basically all data types that are included in Java besides the primitive types. These are denoted with a capital letter. Example: The String type.

User-Defined types are user created and can be anything. Note, that to test for equality between two references types you cannot use the == operator. This just checks the memory references for equality and it will return false. Unlike primitive types, reference types will have a memory address for each instance. To test for equality it will be necessary to use included predicates within the reference type, such as the equals method for String.


This method returns a boolean of either true or false.

Below is an example of Fraction, a user-defined type that represents fractions and features some operations to work with them. The if statements in the toString method are mainly for simplification and to make the output data pretty.

Fraction - A User Defined Type

//This is a really simple example of
//a user defined type.

class Fraction {
  int num, den;
  Fraction(int num, int den) {
    this.num = num;
    this.den = den;

  public String toString() {
      int num = this.num;
      int den = this.den;
      String friend = "";
      if (this.den == 0) {
        friend = "Undefined.";
      else if (this.num == this.den){
        friend = 1 + "";
      else if ((this.num != this.den) && ((Math.abs(this.num) == this.den) || (this.num == Math.abs(this.den)))) {
        friend = "(" + -1 + ")";
      else if ((this.den == 1) || (this.num == 0)) {
        friend = this.num + "";
      else  if (((num < 0) || (den < 0)) && (((num < 0) && (den < 0)) == false )) {
        friend = "(-" + Math.abs(num) + "/" + Math.abs(den) + ")";
      else  if (((num < 0) && (den < 0))) {
        friend = Math.abs(num) + "/" + Math.abs(den);
        friend = num + "/" + den;
      return friend;
  public Fraction simplify() {
    int num = this.num;
    int den = this.den; 
    int a = this.num;
    int b = this.den;
    //This finds the GCF so we can simplify.
    while (b != 0) {
      int gcf = b;
      b = a % b;
      a = gcf;
    num = num/a;
    den = den/a;
    Fraction simpfrac = new Fraction(num, den);
    return simpfrac;
  //These are the operators.
  public Fraction plus(Fraction other) {
    int num = (this.num * other.den) + (other.num * this.den);
    int den = (this.den * other.den);
    Fraction addfrac = new Fraction(num, den);
    addfrac = addfrac.simplify();
    return addfrac;
  public Fraction minus(Fraction other) {
    int num = (this.num * other.den) - (other.num * this.den);
    int den = (this.den * other.den);
    Fraction subfrac = new Fraction(num, den);
    subfrac = subfrac.simplify();
    return subfrac;
  public Fraction times(Fraction other) {
    int num = (this.num * other.num);
    int den = (this.den * other.den);
    Fraction multifrac = new Fraction(num, den);
    multifrac = multifrac.simplify();
    return multifrac;
  public Fraction divideBy(Fraction other) {
    int num = (this.num * other.den);
    int den = (this.den * other.num);
    Fraction divfrac = new Fraction(num, den);
    divfrac = divfrac.simplify();
    return divfrac;
  //Here are the predicates.
  public boolean equals(Fraction other){
    Fraction a = this.simplify();
    Fraction b = other.simplify();
    if ((a.num == b.num) && (a.den == b.den)) {
      return true;
    else return false;
  public boolean isInt(){
    Fraction a = this.simplify();
    if (Math.abs(a.den) == 1) {
      return true;
    else return false;
  public boolean greaterThan(Fraction other){
    Fraction a = this.simplify();
    Fraction b = other.simplify();
    double onefrac = a.num / a.den;
    double twofrac = b.num / b.den;
    if (onefrac > twofrac) {
      return true;
    else return false;

What Are The Differences Between Static and Instance Members?

Static members belong to the class itself and instance members belong to each instance of that class. You can call upon static members of a class without instantiating the class!!!! I actually like the explanations in these blog posts:

What Is A Constructor?

A constructor is an initialization procedure that instantiates a class. By default, Java includes a no-arg constructor with every class which basically does nothing. You'll have to make your own constructors if you want to accomplish anything. :)

In the Fraction class above, the line

Fraction(int num, int den) { }

is a constructor.

What Is Inheritance?

The term inheritance in Java refers to the ability of classes to be derived from other classes and to inherit their members. A class that inherits from another class is called a subclass. Every class in Java apart from Object is a subclass to a superclass (the parent).

What Is Polymorphism in Java?

Polymorphism refers to the ability of a class in Java to be of more than one type. Subclasses can be of the type of any of their superclasses.

What Is Dynamic Method Lookup?

Dynamic method lookup refers to the ability of an inherited method to be redefined for use in a subclass.

What Is Constructor Chaining?

Every constructor method will automatically construct its superclass using super(...) until all of the superclasses have been constructed. This is called constructor chaining and happens in the first line of each constructor.

What do This and Super do??

The this keyword can only be used by instance members and when used as a constructor it can only be used in the first line of a constructor. It calls upon the class itself. :)

Likewise the super keyword calls upon the superclass!

Java this and super Example :)

//This program is complete nonsense, but it uses
//examples of this and super. :)

public class Test  {
  public static void main(String[] args) {
    Clayton clayton = new Clayton();
    Nich nich = new Nich();
    System.out.println("Now comes in Nich :)");

class Clayton {
  String yeah = "Yeah!";
  public String command() {
    return "Hey!  Here's what you should do:";
  public String talk() {
    return this.yeah;

class Nich extends Clayton{
  public String talk() {
    return "Timmmms!!";
  public String repeat() {

Java Class vs Abstract Class

An abstract class cannot be instantiated. Other classes can inherit from it though!

A Class Inheriting From An Abstract Class

class Test {
  public static void main(String[] args) {
    Nich nich = new Nich("tims");

abstract class Clayton {
  String hey = "Hey!";
  String huh = "Huh!";
  String yeah = "Yeah!";
  public String laugh() {
    String chain = "";
    for (int i = 0; i < 10; i++) {
      if (i % 2 == 0) {
       chain += (" " + yeah);
      else chain += (" " + huh);
    return chain;
class Nich extends Clayton {
  Nich(String n){
    super.huh = n;

What is an Interface?

An interface is a group of related methods with empty bodies. They provide a structure that classes must follow if they wish to implement them and prevent the classes from compiling if they do not. Interfaces differ from abstract classes in that they cannot have members! :)

gud luck



    0 of 8192 characters used
    Post Comment

    No comments yet.

    Click to Rate This Article