CS121/IS223: ZooKeeper Example with Two Classes - Java Programming, Study notes of Computer Science

An example of a java program consisting of two classes, zookeeper and panda, created as part of a cs121/is223 course. The zookeeper class serves as the entry point, instantiating and running the panda class. The document also discusses the process of editing, compiling, and running a java program using an editor, compiler, and java virtual machine (jvm).

Typology: Study notes

Pre 2010

Uploaded on 08/09/2009

koofers-user-qhi-2
koofers-user-qhi-2 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS121/IS223
ZooKeeper Example with Two Classes
The following two classes make up a project called Zoo. The first class is the one where execution
begins. Execution begins with its main method. That method instantiates the second class, Panda. It
then runs the instance of the Panda class.
/*
* Created on Jan 22, 2007
* Created by Carol Wolf
* Course: CS 121/IS 223
*/
package zoo;
/**
* The zoo keeper manages the data for the animals in the zoo.
*/
public class ZooKeeper
{
public static void main(String[] args)
{
Panda panda = new Panda ();
panda.displayData();
} // main
} // ZooKeeper
/*
* Created on Jan 24, 2007
* Created by Carol Wolf
* Course: CS 121/IS 223
*/
package zoo;
/**
* A class that describes a panda.
* Pandas are native to China and eat bamboo shoots.
*/
public class Panda
{
private String name = "Mei Ling";
private int age = 6;
public void displayData ()
{
System.out.println (name + "'s age is " + age);
} // displayData
} // Panda
pf2

Partial preview of the text

Download CS121/IS223: ZooKeeper Example with Two Classes - Java Programming and more Study notes Computer Science in PDF only on Docsity!

CS121/IS

ZooKeeper Example with Two Classes The following two classes make up a project called Zoo. The first class is the one where execution begins. Execution begins with its main method. That method instantiates the second class, Panda. It then runs the instance of the Panda class. /*

  • Created on Jan 22, 2007
  • Created by Carol Wolf
  • Course: CS 121/IS 223 / package zoo; /*
  • The zoo keeper manages the data for the animals in the zoo. / public class ZooKeeper { public static void main(String[] args) { Panda panda = new Panda (); panda.displayData(); } // main } // ZooKeeper /
  • Created on Jan 24, 2007
  • Created by Carol Wolf
  • Course: CS 121/IS 223 / package zoo; /*
  • A class that describes a panda.
  • Pandas are native to China and eat bamboo shoots. */ public class Panda { private String name = "Mei Ling"; private int age = 6; public void displayData () { System.out.println (name + "'s age is " + age); } // displayData } // Panda

Editing, compiling and running a program The editor is used to create the .java file. The compiler then translates the Java programming language into Java bytecode. This is an intermediate code that can be run on a number of computers. The Java Virtual Machine (JVM) executes the program. Errors can occur both in compiling and running. The compiler checks for syntax errors. But there still may be run-time errors. These you have to find yourself when the program is run on the JVM. Syntax errors are errors in grammar, using the language. Run-time errors are errors in semantics, what the programmer intended. They are usually much harder to find. Syntax errors are things like missing semicolons. Run-time errors can be incorrect computations or errors in logic. They are often called bugs. You usually have to work on the after a break. Otherwise you can get stuck and not see where you have made a mistake. The following diagram shows the process. eclipse editor ZooKeeper.java Panda.java Java Compiler javac ZooKeeper.class Panda.class Output to screen

Java Virtual

Machine (JVM)

java