SECTION 4: COMMONLY ASKED LANGUAGE SPECIFIC QUESTIONS

4.1) What is Downcasting?

Downcasting is the term used in C++ [Stroustrup 97, p. 407] for casting a pointer or reference to a base class to a derived class. In C++, dynamic_cast is now used to perform this conversion. Downcasting is the opposite of the basic object-oriented rule, which states objects of a derived class can always be assigned to variables of a base class. Since base class variables can only sometimes be assigned to variables of a derived class (when polymorphically refering to an objects of that derived class), downcasting doesn't always work. Downcasting is therefore often both a cast and a query: Is this base variable pointing to a derived instance? In Java, the query is performed with the instanceof operator (animal instanceof Eagle) and the conversion is performed with the typical cast (eagle = (Eagle)animal), but in C++ this cast can return an undefined value (Java will throw a ClassCastException if it isn't valid). This is because Java casts are always performed at run time while C++ casts (except for dynamic_cast) are always performed at compile time. C++ requires polymorphic types for dynamic casts (they must contain virtual functions), but this is not shown in the example below.

    class Animal {}                     *pAnimal;
    class Bear: public Animal {}        *pBear   = new Bear;
    class Eagle: public Animal {}       *pEagle  = new Eagle;

    For example:
          pAnimal = pBear;                          // Ok, basic object-oriented rule.
          pAnimal = pEagle;                         // Ok, basic object-oriented rule.
          ...
          pEagle = pAnimal;                         // Compile error - base to derived.
          pEagle = (Eagle *)pAnimal;                // May be undefined - not checked.
          pEagle = dynamic_cast<Eagle *>(pAnimal);  // Returns pointer to an Eagle if pAnimal points
                                                    /// to an Eagle, else null.
          if(pEagle = dynamic_cast<Eagle *>(pAnimal))
		// pAnimal is an Eagle

4.2) What are Virtual Functions?

Look under Dynamic Binding and Polymorphism.

4.3) Can I Use Multiple-Polymorphism Or Multi-Methods In C++?

Yes, but you'll need to embed a dynamic typing scheme to do it. With dynamic types in place, an overriding method in a derived class can explicitly check argument types in a switch statement and invoke the desired method emulating multiple-polymorphism (See [Coplien 92].

For true CLOS multi-methods, the above technique implemented as a base function (CLOS defgeneric), switching to specialized functions (CLOS methods, made friends of all arguments) will provide the functional calling syntax, multiple- polymorphism and access to parameters found in CLOS. This can require some complex switching, which is somewhat mitigated when multiple-polymorphism is implemented with virtual functions.

4.4) Can I Use Dynamic Inheritance In C++?

Yes, [Coplien 92] describes a scheme where a class can contain a pointer to a base class that can switch between its derived classes, providing a limited form. Earlier chapters contain entries on bypassing C++'s message system and even bypassing static linking.

Future FAQs should contain more detail.


4.101) How Can I Get Help on Java Programming?

Perhaps the best source is the USENET newsgroups, also available over the Web. The most popular Java newsgroups are presently comp.lang.java.programmer and comp.lang.java.help. comp.lang.java.gui could also be helpful, among the following.

4.102) What Tutorials are Available Free Online for Java?

A lot! This section will be reorganized very soon.

From Sun
A practical guide for programmersHundreds of complete working examples
The Java Language EnvironmentA White Paper '96, Gosling, et. al.
Sun TutorialsMany Areas - 2D, 3D, Beans, J2EE, JFC/Swing, Etc.
New to Java - Essentials ... Monica Pawlan, 3/1999

Other
CRASH COURSE IN JAVA!Based on EECE291: Multimedia Progamming, Vanderbilt U
Java Tutorial4 Week Web Course from Bishops College
Java 101Introduction to Java
Java Short CoursesOn-Site Instructor, Some On-Line E.g. Swing, 2D
Java BoutiqueMany tutorials, Intro to Advanced.
Introducing JavaYour First Applet
THE JAVA TUTORA few introductory Applets & Source
Java Programming Tutorial: Introduction to Computer ScienceFor Non-Programmers, QUestions, 1 month course. Kjell, Central Connecticut State U
Java Coffee BreakSeveral beginning to advanced.
Knee Deep in JavaIntermediate Java. MenuBar, MediaTracker.
Java TutorialTechnion EE Software Laboratory
Dick Baldwin's Java Programming TutorialsMany, Beginner to Advanced, some downloadable.
Thinking in Java 2nd editionFree electronic book, Download. Java Seminars on CD.
Intro To JavaIBM Education
IBMWebsphere, e.g. translating Weblogic To Websphere;-) Also VisualAge Java Tutorial
The Java TutorialMary Campione and Kathy Walrath.
Understanding JavaWith exercises and soltions
Friedman-Hill's Java CourseJava Programming in Five Easy Lessons. Reading from Java in a Nutshell
Java Programming...From the Grounds UpArticle series on learning Java
The Java Developer's ResourceLecture Notes, Examples, ETC.

HUMOROUS
Don'T fear The OOPTitle says it all
Shlurrrpp......Java The first user-friendly tutorial on Java.
Java RanchFor the Java Rustler

4.103) What Resources are Available Online for Java?

Last Updated 1/9/2001

JavaSoftOfficial Java Site From Sun
JavaTM Programming Language Source CodeJDK Source Code, RTE to Compiler
Java RepositoryHuge resource site
GamelanHuge resource site
Java Programming ResourcesLots of stuff
Yahoo!Many Categories
Java BoutiqueHuge Resources from Applets to Articles

A Few Others
Java WorldJava Resources
Java LobbyJava Resources
Java Review ServiceListings & Ratings of Java Code
The Java CenterResources - Applet Library
Free Java AppletsFree & Professional Applet version for low $$$
Digital Cat's Java Resource CenterArticles, Tools, Components - some for pay
ProgSourceLiterature, Tools, Resources, Employment