Introduction / Java Types
Subtitles of the Movie
This lesson is about Java types. Now, you are familiar with the fundamental types. The fundamental types can be used in your program and you can stick values in them, but you can't change the types themselves. They are what they are. The Boolean type can only assume one of two values. It can be assigned the value of true or false and it can be used in a conditional expression to test which it is. The byte type is an eight-bit signed integer. The short is a 16-bit signed editor. The care or char, however you want to say it, is the only unsigned data type in java. It's a 16-bit unsigned integer and you can do arithmetic with it, but it's always interpreted by Java as being a Unicode character. I have some more information on Unicode in an upcoming movie. The int is a 32-bit signed integer. The long, a 64-bit signed integer. Floating point numbers are either floats or doubles. Doubles are twice the size of floats and have a larger degree of accuracy. Almost all floating point arithmetic is done with doubles these days. Floats are smaller and they save space when storing large amounts of data on disk, but that's about all they're used for anymore. When you declare a location for storing an object, you are declaring a reference. A reference is a pointer. Even though a lot of people don't like to think of it that way and you can't do arithmetic with the contents of a reference. All you can do is store addresses. There are four types that you can program. These are types that you can define to contain whatever you want them to contain. The first and foremost of these types is class. Writing a Java program is fundamentally a job of defining classes. For a Java program to run, it uses the class definitions to create objects and the objects contain all the instructions to make your program do things. This is an example of a simple class. It contains a variable and it contains methods that can modify and return the value of its variable. This is an example of a class definition being based on another class definition. The circle class extends the figure class by inheriting all of it and adding a few things of its own. The figure class is the super class or the base class or sometimes called the parent class. Nothing of the super class is lost when it's extended this way. It's all inherited. An object of the circle class is also an object of the figure class. An object of the circle class can be made to masquerade in your program as an object of the figure class. Such masquerading has the fancy name polymorphism. This is an abstract class. Notice that it has a method named get maximum that doesn't have any code. That makes it an abstract method. The method is incomplete, therefore the class is incomplete. Now, you can't create actual objects from an abstract class. You can only use such a class as a base class to construct other class definitions. There are three things that will make a class abstract. You could put in an abstract method as in this example or two, you can extend an abstract base class and not implement the abstract methods or three, you can implement an interface but not implement all the methods of that interface. Speaking of interface, it's the second of the four types that you can program. An interface is defined about the same way a class is defined, but all the methods are abstract. This is an interface definition. It looks like a class with method definitions, but none of the methods have bodies defined for them. They're all abstract. You don't have to use the keyword abstract with an interface because everything is always abstract. An interface is used like a contract. It's sort of a unbreakable promise. If a class implements an interface, it's guaranteed that that class has an implementation of all the methods defined by the interface. Otherwise the class is abstract and can't make objects. The next type that you define is the enumeration. This was a later addition to the language. The addition of the enumeration type did not add a new capability. It only added optional syntax for doing something that could already be done. Here's an example of a simple enumeration. Declaring a simple enumeration is not much more than specifying a list of names that you can use to tag things. It works when you have a small set of known possible values. This example shows how you can define a list of names. Then use an enum variable to hold one of them. Later in this course I'll be showing how you can add values to the symbols and how they can be used in if statements and for loops. The last of the types is the annotation and annotation does not cause any executable code to be included in your program. It only adds descriptive information that can be accessed by external processes wishing to find out information about your program. I'll have some examples of doing this in a later movie.
Tutorial Information
| Course: | Java 6 |
| Author: | Arthur Griffith |
| SKU: | 33858 |
| ISBN: | 1-934743-59-3 |
| Release Date: | 2008-02-29 |
| Duration: | 7 hrs / 92 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 