ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

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.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: ""

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)