-
What is the difference between an if statement and a switch statement
The if statement is used to select among two alternatives. It uses a boolean expression todecide whichalternative should be executed. The switch statement is used to select among multiplealternatives. It usesan int expression to determine which alternative should be executed.
-
What are the similarities and differences between Java and C/C++?
FeaturesJavaC/C++PointerNoYesOperator OverloadNoYesPreprocessorsNoYesStructures, UnionsNoYesEnumsNoYesFunctionsNo (only methods within classes)YesGoto statementNoYesAutomatic CoercionsNo (types should be converted explicitly)YesGlobal VariablesNo (variable is a part of a class)YesTemplatesNoYesPrivate, Protected, PublicYesYesInheritanceNoYesDefault parametersNoYesGarbage CollectionYesNoMulti-thread...
-
What is the purpose of the toolkit in the Abstract Window Toolkit (AWT)? How does AWT work ?
The AWT toolkit is an interface between the abstract window layer and a specific windowing implementation.
-
What is layout manager ? How does it work ?
A layout manager is an object that positions and resizes the components in a Container according to some algorithm; for example, the FlowLayout layout manager lays out components from left to right until it runs out of room and then continues laying out components below that row.
-
Q: What you know about Corba implementation in Java ?
Java 1.2 promises full CORBA IDL support.
-
Q: What do you know about networking support in Java ?
Java supports "low-level" and "high-level" classes. "Low-level" classes provide support for socket programming: Socket, DatagramSocket, and ServerSocket classes. "High-level" classes provide "Web programming": URL, URLEncoder, and URLConnection classes. Networking programming classes ease the programming of network applications, but do not substitute your knowledge of networking. Java networking like...
-
Q: How to make application thread-safe ?
You should use the word synchronized to mark the critical section of code. You may also use other methods of thread synchronization (see wait(), notify(), notifyAll() etc.
-
What is the difference between StringBuffer and String class?
A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented...
-
Describe, in general, how java's garbage collector works?
The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java's dynamic memory areas for objects, marking...
-
What's the difference between == and equals method?
The equals method can be considered to perform a deep comparison of the value of an object, whereas the == operator performs a shallow comparison. The quals() method compares the characters inside a string object. == operator compares two object references to check whether they refer to the same instances or not.
-
How can you force all derived classes to implement a method present in the base class?
Creating and implementing an interface would be the best way for this situation. Just create an interface with empty methods which forces a programmer to implement all the methods present under it. Another way of achieving this task is to declare a class as abstract with all its methods abstract.
-
Java says "write once, run anywhere". What are some ways this isn't quite true?
Any time you use system calls specific to one operating system and do not create alternative calls for another operating system, your program will not function correctly. Solaris systems and Intel systems order the bits of an integer differently. (You may have heard of little endian vs. big endian) If your code uses bit shifting, or other binary operators, they will not work on systems that have opposide...
-
Describe java's security model.
Java's security model is one of the most interesting and unique aspects of the language. For the most part it's broken into two pieces: the user adjustable security manager that checks various API operations like file access, and the byte code verifier that asserts the validity of compiled byte code. public abstract class SecurityManager java.lang.SecurityManager is an abstract class which different...
-
What is the difference between a Vector and an Array. Discuss the advantages and disadvantages of both?
The vector container class generalizes the concept of an ordinary C array. Like an array, a vector is an indexed data structure, with index values that range from 0 to one less than the number of elements contained in the structure. Also like an array, values are most commonly assigned to and extracted from the vector using the subscript operator. However, the vector differs from an array in the following...
-
How many different types of JDBC drivers are present? Discuss them.
Type 1: JDBC-ODBC Bridge plus ODBC Driver: The first type of JDBC driver is the JDBC-ODBC Bridge. It is a driver that provides JDBC access to databases through ODBC drivers. The ODBC driver must be configured on the client for the bridge to work. This driver type is commonly used for prototyping or when there is no JDBC driver available for a particular DBMS.Type 2: Native-API partly-Java Driver: The...
-
What is RMI?
RMI stands for Remote Method Invocation. Traditional approaches to executing code on other machines across a network have been confusing as well as tedious and error-prone to implement. The nicest way to think about this problem is that some object happens to live on another machine, and that you can send a message to the remote object and get a result as if the object lived on your local machine....
-
What is JDBC? Describe the steps needed to execute a SQL query using JDBC.
The JDBC is a pure Java API used to execute SQL statements. It provides a set of classes and interfaces that can be used by developers to write database applications. The steps needed to execute a SQL query using JDBC: 1. Open a connection to the database.2. Execute a SQL statement.3. Process th results.4. Close the connection to the database.
-
-
Discuss the differences between creating a new class, extending a class and implementing an interface; and when each would be appropriate.
*Creating a new class is simply creating a class with no extensions and no implementations. The signature is as followspublic class MyClass(){}*Extending a class is when you want to use the functionality of another class or classes. The extended class inherits all of the functionality of the previous class. An example of this when you create your own applet class and extend from java.applet.Applet....
-
What is the difference between instanceof and isInstance?
instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() determines if the specified object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is nonnull and can be cast...
Java Interview Questions
Ans