Q1. What Is The Difference Between Choice And List?
A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.
Q2. What Are Controls And Their Different Types In Awt?
Controls are components that allow a user to interact with your application and the AWT supports the following types of controls:
Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components.
These controls are the subclasses of the Component.
Q3. Can An Object’s Finalize() Method Be Invoked While It Is Reachable?
An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.
Q4. Can An Interface Be Final?
Not possible. Doing it will result in compilation error.
Q5. Explain The Encapsulation Principle?
Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by the other code defined outside the wrapper.
Q6. Why Does It Take So Much Time To Access An Applet Having Swing Components The First Time?
Because behind every swing component are many Java objects and resources. This takes time to create them in memory. JDK 1.3 from Sun has some improvements which may lead to faster execution of Swing applications.
Q7. What Is Java And Their Uses?
Java is an object-programming language that was designed to be portable across multiple platforms and operating systems. Developed by Sun Microsystems, Java is modeled after the C++ programming language and includes special features that make it ideal for programs on the Internet. Still, you may be wondering why Java is suddenly receiving so much hype, and what possible improvements could have been made to this new language so as to push aside a well-established language such as C++.
First and foremost, Java makes it easy to put interactive graphics and other special effects on a World Wide Web page. As with any programming language, Java lets you write programs. Special Java programs, called applets, execute inside a Web page with a capacity matching that of any traditional program. Furthermore, when you run a Java applet, the remote server, Java trmits the applet to your browser across the Internet. So rather than going out to a computer store to buy software, Java applets let you download applications automatically when you need them.
Q8. What Are The Approaches That You Will Follow For Making A Program Very Efficient?
By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.
Q9. What Are Class, Constructor And Primitive Data Types?
Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
Q10. How Java Uses The String And Stringbuffer Classes?
Java strings are immutable, which me after you create a String object, you cannot change that object’s contents. The Java designers found that most of the time, programmers do not need to change a string after it is created. By making String objects immutable, Java can provide better error protection and more efficient handling of strings. However, in case you do need to change the String, you can use a class called StringBuffer as a temporary “scratchpad” which you use to make changes. In short, your programs can change the String objects you store within a Stringbuffer and later copy the buffer’s contents back to the String object after your alterations are complete.
In short, you should use String objects for “frozen” character strings whose contents you don’t expect to change. In contrast, you should use the StringBuffer class for strings you expect to change in content or size. Within your programs, you can take advantage of features from both classes because both provide methods to easily convert between the two.
Q11. Explain The Trient Field Modifier?
When you declare a variable in a class trient, you tell Java that the variable is not a part of the object’s persistent state. Currently, Java does not use the trient keyword. However, future (persistent) versions of Java may use the trient keyword to tell the compiler that the program is using the variable for “scratch pad” purposes and that the compiler does not need to save the variable to disk. The following statement illustrates the use of the trient keyword:
trient float temp__swap__value;
Q12. What Modifiers Can Be Used With A Local Inner Class?
A local inner class may be final or abstract.
Q13. Difference Between A Class And An Object ?
A class is a definition or prototype whereas an object is an instance or living representation of the prototype.
Q14. Why Are There No Global Variables In Java?
Global variables are considered bad form for a variety of reasons: Adding state variables breaks referential trparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.
Q15. What Is The Difference Between A While Statement And A Do Statement?
A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.
Q16. What Must A Class Do To Implement An Interface?
It must provide all of the methods in the interface and identify the interface in its implements clause.
Q17. What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
Q18. What Restrictions Are Placed On Method Overriding?
Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.
Q19. What Kind Of Thread Is The Garbage Collector Thread?
It is a daemon thread.
Q20. What Is The Difference Between A Switch Statement And An If Statement?
If statement is used to select from two alternatives. It uses a boolean expression to decide which alternative should be executed. The expression in if must be a boolean value. The switch statement is used to select from multiple alternatives. The case values must be promoted to an to int value.
Q21. What Do You Understand By Casting In Java Language?
The process of converting one datatype to another in Java language is called Casting.
Q22. What Is Javac_g?
As you have learned, the javac compiler examines your source-code files and produces the bytecode .class files. As your Java applets become more complex, it may become difficult for you to locate errors (bugs) within your code. To help you locate such errors, most Java development environments provide a special debugger program. In the case of the Sun’s Java Developer’s Kit, the debugger program is named jdb (for Java debugger). To provide jdb with more information to work with, the Sun’s JDK provides special version of the compiler named javac__g. Sun designed the javac _g compiler for use with debuggers. Essentially, javacjg is a non-optimized version of the javac compiler which place tables of information within the bytecode that the debugger can use to track down errors. To compile a Java applet using the javac__g compiler, you simply specify the applet source-file named within the javac^g command line, as shown here:
C:JAVACODE> javac „ g SomeFile.Java
Q23. How Are This() And Super() Used With Constructors?
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
Q24. Can You Explain The Final Method Modifier?
Java lets you extend one class (the superclass) with another (the subclass). When a subclass extends a class, the subclass can override the superclass methods. In some cases depending on a method’s , purpose, you may want to prevent a subclass from overriding a specific method. When you declare a class method as final, another class cannot override the methods. Methods which you declare static or private are implicitly final. To declare a method as final, simply precede the method header with the final keyword, as shown:
public final CannotOverrideThisMethod();
Q25. What Is The Program Development Process?
- Depending on what development package you use to create your Java programs, will go about compiling, organizing, and testing your programs in different ways. However, the general development process is mostly the same no matter which package or platform you use.
- As discussed, the end result of the Java programs development process is a bytecode file which the server downloads to the browser for interpretation and execution. When you compile your Java source file, you are creating a bytecode file. Java source-code files, on the other hand, contain the class definitions and program statements you write using the Java language. In addition to the Java source-code files, you must create a small HTML file, which the browser uses to invoke your applet.
- After the compiler creates the bytecode and you create an HTML file, you can test your applet using either your browser or an appletviewer. If your applet contains errors, many Java development environments provide a debugger program that you can use to track down the errors. When you are ready to release your applet to the public, you must place the applet and a corresponding HTML file on a Web server.
- Therefore, the general development cycle of a Java applet includes the creation of source-code and HTML files, compiling the source into bytecode, testing the bytecode through an appletviewer, detecting and removing any errors from the applet using a debugger and, finally, releasing the applet for use on a Web server.
Q26. What Do You Mean By Platform Independence?
Platform independence me that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).
Q27. What Is Composition?
Holding the reference of the other class within some other class is known as composition.
Q28. How Do I Include Static Files Within A Jsp Page?
Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the trlation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.
Q29. What Is A Jvm?
JVM is Java Virtual Machine which is a run time environment for the compiled java class files.
Q30. Which Containers Use A Flow Layout As Their Default Layout?
Panel and Applet classes use the FlowLayout as their default layout.
Q31. When Can An Object Reference Be Cast To An Interface Reference?
An object reference be cast to an interface reference when the object implements the referenced interface.
Q32. What Is The Difference Between Assignment And Initialization?
Assignment can be done as many times as desired whereas initialization can be done only once.
Q33. What Is Mutable Object And Immutable Object?
If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)
Q34. Why Do People Says “java Is Robust”?
When people talk about code being robust, they are referring to the code’s reliability. Although Java has not eliminated unreliable code, it has made writing high-quality software easier. To begin, Java eliminates many of the memory problems that are common in languages such as C and C++. Java does not support direct access to pointers to memory. As a result, a Java applet cannot corrupt your computer’s memory. Also, Java performs run-time checks (while the applet is running) to make sure that all array and string references are within each items’s bounds. In other programming languages, many software bugs result from the program not freeing memory that ought to be freed or freeing the same memory more than once. Java, on the other hand, performs automatic garbage collection (which releases unused memory), eliminating the program’s need to free unused memory.
Next, Java is more strongly typed than C++ and requires method declarations, which reduces the potential for type-mismatch errors. Finally, Java institutes an error trapping method known as exception handling. When a program error occurs Java signals the program with an exception, which provides the program with a chance to recover from the error- and warns the user that something caused a specific operation to fail.
Q35. What Are Different Type Of Exceptions In Java?
There are two types of exceptions in java. Checked exceptions and Unchecked exceptions. Any exception that is is derived from Throwable and Exception is called checked exception except RuntimeException and its sub classes. The compiler will check whether the exception is caught or not at compile time. We need to catch the checked exception or declare in the throws clause. Any exception that is derived from Error and Runtime Exception is called unchecked exception. We don’t need to explicitly catch a unchecked exception.
Q36. How To Define A Constant Variable In Java?
The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can’t be changed also. static final int PI = 2.14; is an example for constant.
Q37. I Want To Print “hello” Even Before Main Is Executed. How Will You Acheive That?
Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it will be executed only once.
Q38. What Is The Impact Of Declaring A Method As Final?
A method declared as final can’t be overridden. A sub-class can’t have the same method signature with a different implementation.
Q39. Explain The Protected Field Modifier?
To control a class member variable’s scope, you can precede the variable’s declaration with the public, private ox protected keywords. A protected variable is one that is only visible within its class, within subclasses or within the package that the class is part of. The different between a private class member and a protected class member is that & private class member is not accessible within a subclass. To declare a variable protected, simply use the protected keyword at the start of the variable declaration, as shown:
protected int ImProtected;
Q40. Can An Interface Extend Another Interface?
Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
Q41. What Do You Understand By A Variable?
The variables play a very important role in computer programming. Variables enable programmers to write flexible programs. It is a memory location that has been named so that it can be easily be referred to in the program. The variable is used to hold the data and it can be changed during the course of the execution of the program.
Q42. What Is The Difference Between A Static And A Non-static Inner Class?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
Q43. Explain The Different Forms Of Polymorphism?
From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
- Method overloading
- Method overriding through inheritance
- Method overriding through the Java interface.
Q44. What Is The Difference Between Notify And Notifyall Method?
notify wakes up a single thread that is waiting for object’s monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. notifyAll Wakes up all threads that are waiting on this object’s monitor. A thread waits on an object’s monitor by calling one of the wait methods.
Q45. What Is The Difference Between Constructor And Method?
Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
Q46. What An I/o Filter?
An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
Q47. Is A Class Subclass Of Itself?
No. A class is not a subclass of itself.
Q48. How To Optimize The Javac Output?
When you compare the performance of a Java program against that of a C/C++ program, you will find that the current generation of Java programs can be as much as twenty times slower than their C/C++ counterparts. This performance loss is mostly due to the fact that the browser musf interpret the Java bytecode and convert it into the computer’s native code (such as a Pentium or Motorola-specific code) before the code can run. In C/C++, the code is in the processor’s native format to begin with, so this time-consuming trlation step is not required. Remember, however, that Java’s generic bytecode allows the same Java code to run on multiple platforms.
The Java designers are working on various solutions to speed up Java. In the meantime, you can use the -O compiler switch with javac, which may increase the applet’s performance. The -0 switch directs javac to optimize its bytecode by “inlining” static, final and private methods. For now, don’t worry what “inlining” such code me other than it may improve your applet performance. Unfortunately, when you use inlining, you may increase the size of your bytecode file, which will increase the applet’s download time. The following Javac command illustrates how you use the -0 switch:
C:JAVACODE> javac -O MyFirst.java
Q49. Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier?
The non-Unicode letter characters $ and _ may appear as the first character of an identifier.
Q50. What Is Java Jit Compilers?
- When your Java-enabled browser connects to a server and tries to view a Web page that contains a Java applet, the server trmits the bytecode for that applet to your computer. Before your browser can run the applet, it must interpret the bytecode data. The Java interpreter performs the task of interpreting the bytecode data.
- As you have learned, using an interpreter to read bytecode files makes it possible for the same bytecode to run on any computer (such as a Window-based or Mac-based computer) that supports Java. The big drawback is that interpreters can be 20 to 40 times slower than code that was custom or native, for a specific computer.
- As it turns out, a new type of browser-side software, called a Just-In-Time compiler (JIT), can convert (compile) the bytecode file directly into native code optimized for the computer that is browsing it. The JIT compiler will take the bytecode data sent by the server and compile it just before the applet needs to run. The compiled code will execute as fast as any application you already use on your computer. As you might expect, the major compiler and IDE manufacturers, such as Borland, Microsoft, Symantec and Metroworks, are all developing JIT compilers.