![]() Programming Center Supplement Welcome to the Java Developer ConnectionSM New to Java Programming Center Supplement! This monthly supplement provides a way for you to learn the basics of the Java programming language, discover new resources, and keep up-to-date on the latest additions to the JDC's New to JavaTM Programming Center. CONTENTS
1. Java Programming Language Basics
2. Making Sense of the Java Class Libraries
4. Java Bits
5. New to Java Technology Forum Latest
6. New to the New to Java Programming Center
8. Program Challenge Solution and Explanation
9. Downloading the Java 2 Platform
Java Programming Language BasicsClasses, Objects, and Constructors: What's the Difference?Distinguishing between classes, objects, and constructors can be confusing. Understanding differences between these terms is important so you know when you're designing an object versus using an object, and how your objects are constructed. Classes and objects are the foundation of Java programming. All objects are based on classes. A class is a recipe or plan for an object. Classes specify the following:
A class is a template that defines an object in the same way a recipe defines your favorite food. A recipe's focus is on food, and the class' focus is on data. A class is not an object any more than a recipe for apple pie is a pie.
Suppose you write a class called
You define methods that operate on that data. To use this class, instantiate an instance of the class by calling the constructor. The constructor is a special method that creates the object of the class from which it is called.
For instance:
creates a Constructors may include parameters, so when the object is instantiated, it is initialized with the arguments that are supplied.
In the previous example
BankAccount(double account, String name) {
account = account;
customername = name; }
When
Create as many constructors as you need. If you don't
write a constructor, a default constructor is provided for
you like the first constructor shown above in The J2SE documentation details how to instantiate objects for the predefined classes in the library by calling the constructor or constructors. For instance, consider the following paragraph from the J2SE documentation:
creates a
If you want to use this
* Note: Providing constructors ensures that objects are built exactly as desired, with the data specified in the parameters. Making Sense of the Java Class LibrariesThe ArrayList class explained:Applications frequently need to store a group of data within a single object. Arrays serve this purpose well, but sometimes you need to dynamically increase or decrease the number of elements in the array, or have it hold different types of data. This is common among applications like online stores. A customer adds merchandise to a shopping basket, and behind the scene, the items are stored or removed automatically.
For this kind of growing and shrinking of a data group, you can use the
An
An
If you need to cycle through the
See For More Information for links to tutorials and articles on this topic. Program Challenge
You've learned about classes, objects, constructors, and
the
The results should look similar to the following:
Java BitsWhy Command-Line Arguments are not 100% Pure Java TechnologyApplications that require command-line arguments are not 100% Pure Java because not all systems have a command line available. If you have a command line on your system, using command-line arguments during application development is useful for testing code logic, or reading in files. Otherwise, consider using properties so that your applications are portable. See properties in a future issue of the New to Java Programming Center supplement. New to Java Technology Forum Latest
Compile the file: See: the Forums to respond to this question. New to the Java Programming CenterTest your knowledge of Java technology terminology with this new crossword puzzle online game. Look for new Java related puzzles in the future. For More InformationThe Java Tutorial Trail: Lesson: Object Basics and Simple Data Object Ess entials of the Java Programming Language, Part 2 Lesson 8: Object-Oriented Programming Fundamentals of the Collection Framework: Essentials of the Java Programming Language, Part 2 Lesson 5: Collection POSIX Conventions for Command Line Arguments Java 2 SDK, Standard Edition, version 1.3: Summary of New Features and Enhancements Program Challenge SolutionThis is one possible solution to the Program Challenge:
Results:
Downloading the Java 2 Platform
Have a question about programming? Use Java Online Support. - Note - Sun respects your online time and privacy. The Java Developer Connection mailing lists are used for internal Sun Microsystems purposes only. You have received this email because you elected to subscribe. - Unsubscribe - To unsubscribe to this newsletter, go to the subscriptions page uncheck the "JDC New-to-Java Supplement" checkbox, and click "Update". - Subscribe - To subscribe to other JDC mailings, go to the subscriptions page choose the newsletters you want to subscribe, and click "Update". - Feedback - Comments? Send your feedback on the JDC Newsletter to: jdc-webmaster - Copyright -
Copyright 2001 Sun Microsystems, Inc. All rights reserved. This document is protected by copyright.
JDC New-to-Java Programming Center Supplement 1 As used on this web site, the terms "Java virtual machine" or "JVM" mean a virtual machine for the Java platform. | |||||||||||||||||
|
| ||||||||||||