Submit Java Questions to Computer Education Techniques CETi

Submit Java Questions to Computer Education Techniques CETi

Submit Java Questions

Home

Submit Java Questions

Technology Update

Knowledge Base


Submit Java Questions to Computer Education Techniques CETi Advanced search
     

Interrelated Information Technology

WebSphere Questions WebLogic Questions
Oracle Questions DB2 Questions
CICS Questions XML Questions

The Computer Education Techniques knowledge base is a service for answering questions, inclusive of the research and validation of the accuracy of information in the public domain. Citation of source documentation and examples are used to provide answers to the questions. Utilization of the information of this service and reliance on the answers, information or other materials received through this web site is done at your own risk.

Q What is the least expensive and efficient way for our organization to code some simple Java programs and evaluate the Java programming language?
A Our recommendation would be to read the free Java tutorial, at http://java.sun.com/docs/books/tutorial/index.html.

Q

My "Hello World!" program run will not execute. Do you have any recommendations?

A

There are five common mistakes that will result in a VM (java or browser) being unable to execute your classes:

1. Did you code an applet or an application?
  • If an applet has been coded, the java.applet.Applet class has to be extended. The starting code should be in the init routine.
  • If an application has been coded, the starting code should be in a routine called main().

Only experienced Java programmers should consider coding applets with applications.

2. The main class must be declared as "public". When this is not done, some systems will still run the code, while others won't. The main class is either included as part of the main() method or in the case of an Applet, the class that extends Applet.
3. The class name and the file name must match exactly and this applied to case also. If the class is HelloWorld, then the source file must be HelloWorld.java and the class file will be "HelloWorld.class".
4. In the case of coding an Applet, and ftp has been used to transfer the classes to the server, all the classes must be "ftped" using the BINARY transfer (not ASCII).
5. Mistakes are made in the CLASSPATH and/or codebase in an applet.

Pointing inside a package or mistyping a path delimiter will result in problems.


Q How do I set the CLASSPATH?
A The CLASSPATH environment variable tells the VM's class loader where to find classes that are directly or indirectly invoked, including system classes.

The CLASSPATH variable should:

  • Point to the directory containing the class file, for classes not in a package.
  • Point to the package root, for classes in a package. The root is the parent directory of the highest directory of the package name.
  • Point directly to the zip or jar file, if the classes are in an archive file. It may be necessary to list the contents of the archive in order to get the correct package/path name for the class.

It is a requirement to separate multiple paths and archives with a platform-specific separator:" " for Windows; ":" for UNIX.

; MS Windows : UNIX


Q How are two Float objects added together?
A It would seem that straightforward coding would be:

Float One;

Float Two;

Float Hard = One + Two;

but the compiler does not allow it.

Java has two separate ways of representing a 32 bit floating point number, Float and float.

  • Float is a class, which "wraps" a floating point number in order that it can be treated as an object. The class does not support floating point arithmetic, because performance would be too slow.
  • float is a primitive type (like int) that is used for floating point arithmetic.

If all that is required of the floating point numbers is arithmetic, then they should be declared to be "float".

If the floating point numbers are to be used as object, then they should be declared as "Float".

The decision should be based upon predominant use. If both are required, then they will need to be declare one way and converted whenever the capabilities of the other are needed. The specific code can be written as:

Float One = new Float(1.0);
Float Two = new Float(2.0);
Float Hard = new Float(One.floatValue() + Two.floatValue());


Q How do I calculate the number of days between two dates?
A There is no API for this; however there should be!

The following code can be used for performing the calculation:

static final long ONE_HOUR = 60 * 60 * 1000L;
Calendar earlierDate = new GregorianCalendar();
Calendar laterDate = new GregorianCalendar();
earlierDate.set(1997, 1, 5, 0, 0, 0); // FEB!! 05, 1997
laterDate.set(1998, 1, 5, 0, 0, 0); // Feb 05, 1998
// the first getTime() returns a Date, the second takes
// that Date object and returns millisecs since 1/1/70.
// The API has misleading and horrible naming here, sorry.

long duration = laterDate.getTime().getTime() -
earlierDate.getTime().getTime();
// Add one hour in case the duration includes a
// 23 hour Daylight Savings spring forward day.

long nDays = ( duration + ONE_HOUR ) / (24 * ONE_HOUR);
System.out.println("difference in days: " + nDays);


Q Does Java have the equivalent of "const" arguments in C and C++?
A Java 1.1 added the ability to use the "final" keyword to make arguments constant.

When used to qualify a reference type, however, this keyword indicates that the reference is constant; this is , not that the object or array referred to is constant.


Q Do I need to know C++ to learn Java?
A No. Java is an easier language to learn than C++. And C++ is not a prerequisite. However, SYS-ED does offer multiple levels of both programming languages.

Q

What exactly is JavaScript? JavaScript is a subset of Java, right?

A

Java and JavaScript both have the word Java in their names. JavaScript is a programming language from Netscape which is incorporated in their browsers. It is superficially similar to Java; but in fact there are a number of differences.


Q

What is the difference between an application and applet?

A An application is a Java class that has a main() method. An applet is a Java class which extends java.applet.Applet. A class which extends java.applet.Applet and also has a main() method is both an application and applet.
  • An application is a stand-alone program, normally launched from the command line, and which has more or less unrestricted access to the host system.
  • An applet is a program which is run in the context of an applet viewer or web browser, and which has strictly limited access to the host system.

Q

My company requires that I receive Java training - ASAP. I want to be sure that the training will be on the identical release that I will be using back on the job.

A The Java programming language is currently shipping from Sun Microsystems, Inc. as the Java 2 SDK and Java 2 Runtime Environment.

Each release of the Java 2 SDK, Standard Edition contains:

  • Java Compiler
  • Java Virtual Machine
  • Java Class Libraries
  • Java AppletViewer
  • Java Debugger and other tools
  • Java Documentation (in a separate download bundle)

It is SYS-ED policy to train on the latest release of the product. However, we will upon request install older versions of the product for use in our workshops.


Q

My company makes extensive use of Java tools for application development and debugging? Will these tools be available in SYS-ED’s Java courses?

A Yes, we provide complete support and utilization of JUnit, Ant, XDoclet, Struts, JBuilder, Tomcat, and JEdit.

Moreover, we support all the major tools; but for many of the more substantial tools we offer standalone courses just for that tool. And we are committed to being first in line when it comes to using the new tools.


Q

Will SYS-ED courses prepare me for certification exams?

A Yes, SYS-ED Java training programs and Java boot camps can be taught to prepare participants to pass certification examinations.

Our restricted enrollment 3-, 4- ,5-day courses are not oriented to certification.


Q

Our shop has made a substantial investment in Microsoft APIs and development platforms. Which SYS-ED Java course will provide the expertise and content that I need in order to convert my Java classes to an executable .exe file for Windows?

A Depending on your operational objectives, we have several courses. FYI, Microsoft provides a free system development kit (SDK), for Java, which includes the jexegen tool. This will convert class files into .exe files.

Schedule