Submit Java Questions to Computer Education Techniques CETi

Submit Java Questions to Computer Education Techniques CETi

Submit Java Questions


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 How is a Conditional Breakpoint set?  Adding a breakpoint to the source can be prepared by right clicking on a source line and selecting Toggle Breakpoint.  There is no option for selecting a Conditional Breakpoint.
A To set a Conditional Break, set a break point using the conventional technique of right clicking on a source line and selecting Toggle Breakpoint.  Run the program in Debug Mode by selecting the Debug icon or selecting Run, Debug As.  Once the first breakpoint is initiated, locate the breakpoint tab. If the Breakpoint tab can not be found, select Windows, Show View, and Breakpoints.  Reset the breakpoint by selecting the checkbox Conditional and entering in a condition such as s1.contains("DEBUG"). Execution can be resumed by selecting Run, Resume or pressing F8.


A A Hit Count is a another type of conditional breakpoint is.  Selecting the Hit Count checkbox and entering in an integer value, will suspend the breakpoint execution of a thread the nth time it is hit, but not again, until it is re-enabled.
A Once at a breakpoint, the standard function keys then can be used.

Key Description
F5 Used to execute the currently selected line and proceeds to the next line in the source code.
F6 F6 steps over the call.
F7 F7 steps out to the caller of the currently executed method. It will finish execution of the current method and return to the caller of the method.
F8 Resumes the execution.

Q What are some useful Eclipse shortcut keys?
A The Ctrl Shift L provides a list of the shortcut keys.
Function Shortcut Key
Activate Editor


Activate Task


Add Artifact to Target Platform


Add Block Comment


Add Import Ctrl+Shift+M
Add Javadoc Comment Alt+Shift+J
All Instances Ctrl+Shift+N
Backward History Alt+Left
Build All Ctrl+B
Change Method Signature Alt+Shift+C
Close Ctrl+F4
Close All Ctrl+Shift+F4
Collapse Ctrl+Nupad_Subtract
Collapse All Ctrl+Shift+Numpad_Divide
Commit… Ctrl+#
Content Assist Ctrl+Space
Context Information Ctrl+Shift+Space
Copy Ctrl+Insert
Copy Lines Ctrl+Alt+Down

Q Java execution performance is important for our organization. How can the amount of time a section of code executes be measured?
A Code two calls to System.currentTimeMillis; one call will return and store the current time in milliseconds before the execution of the code.  The other call to System.currentTimeMillis will return and store the execution of code after the execution of the code.  Subtracting the after value from the starting value provides the number of milliseconds required to run the section of code.
  public class TimeCode {
         public static void main(String[] args) {
                long start, end;
                int[] tbl1 = new int[4500000];
                int[] tbl2 = new int[4500000];
                System.out.println("Start initialize array");
                for (int i = 0; i < tbl1.length; i++) {
                       tbl1[i] = i;
                System.out.println("End initialize array");

                start = System.currentTimeMillis();
                for (int j = 0; j < tbl1.length; j++) {
                      tbl2[j] = tbl1[j];

                end = System.currentTimeMillis();
                System.out.println(end - start
                     + " milliseconds to copy an array ");

Q How can I get a list of the java Path used to find directories and JAR archives containing class files?
A Use the System.getProperty with a property of java.library.path.  The output of System.getProperty is parsed for using the  split method specifying the File.pathSeparator to separate the values.

public class OSDetermine {

       public static void main(String[] args) {

              String libPath = System.getProperty("java.library.path");

              String[] classpathEntries =
              for (String path : classpathEntries) {

Q  Even after initialization has been set to false, this code always applies a flag which returns a true condition.  How can this flag be set equal to true?
  public class EqualityTest {
       public static void main(String[] args) {
       boolean flag = false;
       if (flag = true)
              System.out.print("Flag is always true");
A This error can be difficult to locate.  The typing of a single equals sign instead of a double equal sign when a boolean value will have Java perform an assignment state reinitializing flag to true.  Either use a double equals or leave out the condition altogether:
  if (flag == true)


if (flag)  

Q What is a native method?
A A native method is a method that is implemented in a language other than Java.

Q To what value is a variable of the String type automatically initialized?
A The default value of a String type is null.

Q Can a stack trace of an exception be printed when coding a JSP page?
A Yes. This is performed by creating a new instance of the PrintWriter. Use an implicit object 'out' in a printWriter and pass the object to the printStackTrace method in Exception.

              // an Exception is thrown
          } catch(Exception e) {


Q Can JSP be used for setting focus on an input field in a HTML form?
A No.  Set focus on an input field using a scripting language such as JavaScript in HTML.  JSP is a server-side technology, which is responsible for generating dynamic content in HTML, DHTML or XML format.

Q Are there JSP comments or should HTML comments be used?
A JSP does have JSP style comments to document scriptlets or selectively block out code while debugging. JSP comments are not visible at the client browser.

<%--         beginning of comment
        out.printlin("Display debugging information"):
--%>         end of comment

Q There is a JSP with a method in a program. Can the method be accessed from a different JSP page?
A JSP code can be accessed by with an include directive in the code. 

<%@   include file="method.jsp" %>

Q Is there a significant advantage associated with using JSP or servlets?  
A JSP: JavaServer Page is based on servlet technology; both should be used in a well-designed web supplication. In most situations, servlets will be used for controlling part of MVC and JSP for rendering the views.  There are some things that a JSP cannot do and should be performed by a servlet such as generating binary content. Each has its advantages.

Q After coding a JSP program and invoking a bean, the program cannot find the bean. What is causing the problem?  
A Common reasons why a bean can not be found include: 

Compile the bean and verify that the class file is resident in the hierarchy rooted at the WEB-INF/classes folder.
Check that WEB-INF/classes is spelled properly.
Check class name spelling.
Store beans in a package.
Code a fully-qualified class name for inclusion in the useBean declaration. 
Use the package name in the fully-qualified class name.  

Q What are the advantages associated with using JSP: JavaServer Page instead of a scripting language such as JavaScript?  
A JavaScript can generate HTML dynamically on the client; however there are limitations with its ability to interact with the web server to perform complex tasks such as database access, file I/O, and image processing. 

Q What is autoFlush attribute in s page directive?  
A Buffered output should be flushed automatically when the buffer is filled. Otherwise an exception should be raised to indicate buffer overflow.  

Q The struts.xml file has been changed; but the changes are not reflected at execution time.  How can a forced reload of the action mapping (struts.xml) be applied?  
A A utility program can provide this functionality. Invoke the program to reload the struts.xml.

String execute() {
   return SUCCESS;

Q What are the naming conventions associated with XML Struts 2 validation?
A The XML file should be named the actionclass-Validation.xml.  

For example, if the action class is Employee the validation file is Employee-Validation.xml.  The field names in the validation xml should match the field names in the action class.

Q Can the struts.xml file configure an action node in order that one action node can be used to associate several different Action URLs that are specific methods of the Action class.
A  Yes. The wildcard method selection technique can be used for enabling Struts 2 to dynamically choose the correct method to call at runtime. Code the wildcard character, *, in the name value.

Q How can the Struts configuration for debugging systems be displayed?
A Use the Struts 2 config browser plugin to view the information managed by the Struts 2 framework.  The struts2-config-browser-plugin-x.x.x.x.jar is required to be in the application's class path. The jar is part of the Struts 2 download. 

Call index.action in namespace config-browser to use the plugin in your application.


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


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


There are six common mistakes that will result in a VM Java or browser being unable to execute 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 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() -
// 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.


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


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.


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.


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.


The Java programming language is currently shipping from Oracle Corporation as the Java JDK 8u20 and Java Runtime Environment.

Each release of the Java JDK, 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.


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, Maven, 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.


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 3-, 4-, and 5-day courses are not oriented at the current time to certification.


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 SDK: system development kit for Java, which includes the jexegen tool. This will convert class files into .exe files.