|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 6
Type the above program into a file named MyProgram.java. It's a good idea to put it in its own directory just to keep things organized. Use your favorite text editor for this, or
check out the Resources section for some of my favorites. Once you've done that, go to a command line that is open to the location your file is in.
Type in the following code to compile the file. (This generates the .class file from the .java file):
javac MyProgram.java
Once it compiles without errors, do a directory listing to see that you've generated a MyProgram.class file. (Hey -- that's the bytecode.)
Now type the following to run the program:
java MyProgram
This executes the JVM, and makes it run the bytecode in the MyProgram.class file. You should see the following output on your screen:
Eureka, I can put Java on my resume.
Congratulations! You've generated your first Java program.
There are a couple of things you should notice. The Java compiler (javac) requires that you include the .java extension for the files you're compiling. It's just a program, and that's what it expects you to give it. The JVM (java) does not expect you to include the .class extension. Try typing java MyProgram.class, and you'll get an error message because it will look for a file called MyProgram.class.class. Note also that things are set up in such a way that you have to do everything from one directory.
Object-oriented programming is the key organizational factor in using Java well. Simply put, this means that you organize your program around objects. What's an object? It's a representation of some concept or thing. This is a powerful model because it reflects the way we think about the world, and the way we conceptualize it using language.
Here are the key characteristics that define an object:
You might see object described elsewhere using different terminology, but don't worry too much about that. Grasping the concepts is the important thing.
Let's further explore the notion of type. We're almost always dealing with many different objects, and the natural inclination is to classify or label them in some way. A type is the way to classify objects, and it's also the blueprint that defines the behavior and properties for objects of a certain type.
Here are some real-world examples of different types from different areas:
Every object has a type associated with it, and possibly more than one type. Creating types and classifying your objects is one of the arts of OOP, and there is no single "correct" way to do this.
Let's examine the alarm clock type. We'll take a crack at determining its behavior and properties.