Saturday, July 17, 2010

An interview in ITWORX Egypt in the free zone, Nasr City

the interview is divided into several parts, the most important one is the technical part which leads to the important question, what they are going to ask me.


  1. SQL & DB questions
  2. Software Life Cycle
  3. Software Life Cycle Diagrams
  4. OOP Concepts
  5. Java Questions
  6. JSP & servlet Questions

SQL interview questions and answers

  1. What are two methods of retrieving SQL?
  2. What cursor type do you use to retrieve multiple recordsets?
  3. What is the difference between a "where" clause and a "having" clause? - "Where" is a kind of restiriction statement. You use where clause to restrict all the data from DB.Where clause is using before result retrieving. But Having clause is using after retrieving the data.Having clause is a kind of filtering command.
  4. What is the basic form of a SQL statement to read data out of a table? The basic form to read data out of table is ‘SELECT * FROM table_name; ‘ An answer: ‘SELECT * FROM table_name WHERE xyz= ‘whatever’;’ cannot be called basic form because of WHERE clause.
  5. What structure can you implement for the database to speed up table reads? - Follow the rules of DB tuning we have to: 1] properly use indexes ( different types of indexes) 2] properly locate different DB objects across different tablespaces, files and so on.3] create a special space (tablespace) to locate some of the data with special datatype ( for example CLOB, LOB and …)
  6. What are the tradeoffs with having indexes? - 1. Faster selects, slower updates. 2. Extra storage space to store indexes. Updates are slower because in addition to updating the table you have to update the index.
  7. What is a "join"? - ‘join’ used to connect two or more tables logically with or without common field.
  8. What is "normalization"? "Denormalization"? Why do you sometimes want to denormalize? - Normalizing data means eliminating redundant information from a table and organizing the data so that future changes to the table are easier. Denormalization means allowing redundancy in a table. The main benefit of denormalization is improved performance with simplified data retrieval and manipulation. This is done by reduction in the number of joins needed for data processing.
  9. What is a "constraint"? - A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints that are currently supported by SQL Server: PRIMARY/UNIQUE - enforces uniqueness of a particular table column. DEFAULT - specifies a default value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action. Default is not a constraint. NOT NULL is one more constraint which does not allow values in the specific column to be null. And also it the only constraint which is not a table level constraint.
  10. What types of index data structures can you have? - An index helps to faster search values in tables. The three most commonly used index-types are: - B-Tree: builds a tree of possible values with a list of row IDs that have the leaf value. Needs a lot of space and is the default index type for most databases. - Bitmap: string of bits for each possible value of the column. Each bit string has one bit for each row. Needs only few space and is very fast.(however, domain of value cannot be large, e.g. SEX(m,f); degree(BS,MS,PHD) - Hash: A hashing algorithm is used to assign a set of characters to represent a text string such as a composite of keys or partial keys, and compresses the underlying data. Takes longer to build and is supported by relatively few databases.
  11. What is a "primary key"? - A PRIMARY INDEX or PRIMARY KEY is something which comes mainly from
    database theory. From its behavior is almost the same as an UNIQUE INDEX, i.e. there may only be one of each value in this column. If you call such an INDEX PRIMARY instead of UNIQUE, you say something about
    your table design, which I am not able to explain in few words. Primary Key is a type of a constraint enforcing uniqueness and data integrity for each row of a table. All columns participating in a primary key constraint must possess the NOT NULL property.
  12. What is a "functional dependency"? How does it relate to database table design? - Functional dependency relates to how one object depends upon the other in the database. for example, procedure/function sp2 may be called by procedure sp1. Then we say that sp1 has functional dependency on sp2.
  13. What is a "trigger"? - Triggers are stored procedures created in order to enforce integrity rules in a database. A trigger is executed every time a data-modification operation occurs (i.e., insert, update or delete). Triggers are executed automatically on occurance of one of the data-modification operations. A trigger is a database object directly associated with a particular table. It fires whenever a specific statement/type of statement is issued against that table. The types of statements are insert,update,delete and query statements. Basically, trigger is a set of SQL statements A trigger is a solution to the restrictions of a constraint. For instance: 1.A database column cannot carry PSEUDO columns as criteria where a trigger can. 2. A database constraint cannot refer old and new values for a row where a trigger can.
  14. Why can a "group by" or "order by" clause be expensive to process? - Processing of "group by" or "order by" clause often requires creation of Temporary tables to process the results of the query. Which depending of the result set can be very expensive.
  15. What is "index covering" of a query? - Index covering means that "Data can be found only using indexes, without touching the tables"
  16. What types of join algorithms can you have?
  17. What is a SQL view? - An output of a query can be stored as a view. View acts like small table which meets our criterion. View is a precomplied SQL query which is used to select data from one or more tables. A view is like a table but it doesn’t physically take any space. View is a good way to present data in a particular format if you use that query quite often. View can also be used to restrict users from accessing the tables directly. 
  1. What is Object Oriented Design? What are the benefits and drawbacks?
  2. What is the Agile software philosophy?
  3. What is the Lean software philosophy?
  4. Have you looked at "Domain Driven Design"?
  5. What are the benefits of Dependency Injection?
  6. What books have you read on software engineering that you thought were good?
  7. What are the really important aspects of software development?
  8. Tell me about your philosophy of database design. Database tools?
  9. What are important aspects of GUI design?
  10. What Object Relational Mapping tools have you used?
  11. Tell me about the Model-View-Controller pattern and why it's important?
  12. What is Test Driven Development and Design? Why is it important?
  13. Describe some of the software patterns you have used?
  14. How do you design scalable applications?
  15. What is continuous integration?
  16. What is the REST architecture pattern?
Learning Priority
Depicts high-level business processes, including data flow, or to model the logic of complex logic within a system.  See UML Activity diagram guidelines.
Shows a collection of static model elements such as classes and types, their contents, and their relationships.  See UML Class diagram guidelines.
Shows instances of classes, their interrelationships, and the message flow between them. Communication diagrams typically focus on the structural organization of objects that send and receive messages.  Formerly called a Collaboration Diagram.  See UML Collaboration diagram guidelines.
Depicts the components that compose an application, system, or enterprise. The components, their interrelationships, interactions, and their public interfaces are depicted.  See UML Component diagram guidelines.
Depicts the internal structure of a classifier (such as a class, component, or use case), including the interaction points of the classifier to other parts of the system.   
Shows the execution architecture of systems.  This includes nodes, either hardware or software execution environments, as well as the middleware connecting them.  See UML Deployment diagram guidelines.
A variant of an activity diagram which overviews the control flow within a system or business process.   Each node/activity within the diagram can represent another interaction diagram.   
Depicts objects and their relationships at a point in time, typically a special case of either a class diagram or a communication diagram. 
Shows how model elements are organized into packages as well as the dependencies between packages.  See Package diagram guidelines.
Models the sequential logic, in effect the time ordering of messages between classifiers.  See UML Sequence diagram guidelines.
Describes the states an object or interaction may be in, as well as the transitions between states. Formerly referred to as a state diagram, state chart diagram, or a state-transition diagram.  See UML State chart diagram guidelines.
Depicts the change in state or condition of a classifier instance or role over time.  Typically used to show the change in state of an object over time in response to external events. 
Shows use cases, actors, and their interrelationships.  See UML Use case diagram guidelines.


1) What is meant by Object Oriented Programming?
     OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

2) What is a Class?
     Class is a template for a set of objects that share a common structure and a common behaviour.

3) What is an Object?
     Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

4) What is an Instance?
     An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object.

5) What are the core OOP’s concepts?
     Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts.

6) What is meant by abstraction?
     Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

7) What is meant by Encapsulation?
     Encapsulation is the process of compartmentalising the elements of an abtraction that defines the structure and behaviour. Encapsulation helps to separate the contractual interface of an abstraction and implementation.

8) What is meant by Inheritance?
     Inheritance is a relationship among classes, wherein one class shares the structure or behaviour defined in another class. This is called Single Inheritance. If a class shares the structure or behaviour from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalised superclasses.

9) What is meant by Polymorphism?
     Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.

10) What is an Abstract Class?
     Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behaviour, typically by implementing its abstract operations.

11) What is an Interface?
     Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour.

12) What is a base class?
     Base class is the most generalised class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.

13) What is a subclass?
     Subclass is a class that inherits from one or more classes

14) What is a superclass?
     superclass is a class from which another class inherits.

15) What is a constructor?
     Constructor is an operation that creates an object and/or initialises its state.

16) What is a destructor?
     Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM.

17) What is meant by Binding?
     Binding denotes association of a name with a class.

18) What is meant by static binding?
     Static binding is a binding in which the class association is made during compile time. This is also called as Early binding.

19) What is meant by Dynamic binding?
     Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.

20) Define Modularity?
     Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

21) What is meant by Persistence?
     Persistence is the property of an object by which its existence transcends space and time.

22) What is colloboration?
     Colloboration is a process whereby several objects cooperate to provide some higher level behaviour.

23) In Java, How to make an object completely encapsulated?
     All the instance variables should be declared as private and public getter and setter methods should be provided for accessing the instance variables.

24) How is polymorphism acheived in java?
     Inheritance, Overloading and Overriding are used to acheive Polymorphism in java.



Basic Java interview questions

  1. What is a Marker Interface? - An interface with no methods. Example: Serializable, Remote, Cloneable
  2. What interface do you implement to do the sorting? - Comparable
  3. What is the eligibility for a object to get cloned? - It must implement the Cloneable interface
  4. What is the purpose of abstract class? - It is not an instantiable class. It provides the concrete implementation for some/all the methods. So that they can reuse the concrete functionality by inheriting the abstract class.
  5. What is the difference between interface and abstract class? - Abstract class defined with methods. Interface will declare only the methods. Abstract classes are very much useful when there is a some functionality across various classes. Interfaces are well suited for the classes which varies in functionality but with the same method signatures.
  6. What do you mean by RMI and how it is useful? - RMI is a remote method invocation. Using RMI, you can work with remote object. The function calls are as though you are invoking a local variable. So it gives you a impression that you are working really with a object that resides within your own JVM though it is somewhere.
  7. What is the protocol used by RMI? - RMI-IIOP
  8. What is a hashCode? - hash code value for this object which is unique for every object.
  9. What is a thread? - Thread is a block of code which can execute concurrently with other threads in the JVM.
  10. What is the algorithm used in Thread scheduling? - Fixed priority scheduling.
  11. What is hash-collision in Hashtable and how it is handled in Java? - Two different keys with the same hash value. Two different entries will be kept in a single hash bucket to avoid the collision.
  12. What are the different driver types available in JDBC? - 1. A JDBC-ODBC bridge 2. A native-API partly Java technology-enabled driver 3. A net-protocol fully Java technology-enabled driver 4. A native-protocol fully Java technology-enabled driver For more information: Driver Description
  13. Is JDBC-ODBC bridge multi-threaded? - No
  14. Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection? - No
  15. What is the use of serializable? - To persist the state of an object into any perminant storage device.
  16. What is the use of transient? - It is an indicator to the JVM that those variables should not be persisted. It is the users responsibility to initialize the value when read back from the storage.
  17. What are - Class level lock Object level lock Method level lock Block level lock
  18. What is the use of preparedstatement? - Preparedstatements are precompiled statements. It is mainly used to speed up the process of inserting/updating/deleting especially when there is a bulk processing.
  19. What is callable statement? Tell me the way to get the callable statement? - Callablestatements are used to invoke the stored procedures. You can obtain the callablestatement from Connection using the following methods prepareCall(String sql) prepareCall(String sql, int resultSetType, int resultSetConcurrency)
  20. In a statement, I am executing a batch. What is the result of the execution? - It returns the int array. The array contains the affected row count in the corresponding index of the SQL.
  21. Can a abstract method have the static qualifier? - No
  22. What are the different types of qualifier and what is the default qualifier? - public, protected, private, package (default)
  23. What is the super class of Hashtable? - Dictionary
  24. What is a lightweight component? - Lightweight components are the one which doesn’t go with the native call to obtain the graphical units. They share their parent component graphical units to render them. Example, Swing components
  25. What is a heavyweight component? - For every paint call, there will be a native call to get the graphical units. Example, AWT.
  26. What is an applet? - Applet is a program which can get downloaded into a client environment and start executing there.
  27. What do you mean by a Classloader? - Classloader is the one which loads the classes into the JVM.
  28. What are the implicit packages that need not get imported into a class file? - java.lang
  29. What is the difference between lightweight and heavyweight component? - Lightweight components reuses its parents graphical units. Heavyweight components goes with the native graphical unit for every component. Lightweight components are faster than the heavyweight components.
  30. What are the ways in which you can instantiate a thread? - Using Thread class By implementing the Runnable interface and giving that handle to the Thread class.
  31. What are the states of a thread? - 1. New 2. Runnable 3. Not Runnable 4. Dead
  32. What is a socket? - A socket is an endpoint for communication between two machines.
  33. How will you establish the connection between the servlet and an applet? - Using the URL, I will create the connection URL. Then by openConnection method of the URL, I will establish the connection, through which I can be able to exchange data.
  34. What are the threads will start, when you start the java program? - Finalizer, Main, Reference Handler, Signal Dispatcher

Java interview questions and answers

  1. What is garbage collection? What is the process that is responsible for doing that in java? - Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
  2. What kind of thread is the Garbage collector thread? - It is a daemon thread.
  3. What is a daemon thread? - These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
  4. How will you invoke any external process in Java? - Runtime.getRuntime().exec(….)
  5. What is the finalize method do? - Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.
  6. 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, …)
  7. What is the basic difference between string and stringbuffer object? - String is an immutable object. StringBuffer is a mutable object.
  8. What is the purpose of Void class? - The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
  9. What is reflection? - Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.
  10. What is the base class for Error and Exception? - Throwable
  11. What is the byte range? -128 to 127
  12. What is the implementation of destroy method in java.. is it native or java code? - This method is not implemented.
  13. What is a package? - To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.
  14. 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.
  15. What is a DatabaseMetaData? - Comprehensive information about the database as a whole.
  16. What is Locale? - A Locale object represents a specific geographical, political, or cultural region
  17. How will you load a specific locale? - Using ResourceBundle.getBundle(…);
  18. What is JIT and its use? - Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.
  19. Is JVM a compiler or an interpreter? - Interpreter
  20. When you think about optimization, what is the best way to findout the time/memory consuming process? - Using profiler
  21. What is the purpose of assert keyword used in JDK1.4.x? - In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.
  22. How will you get the platform dependent values like line separator, path separator, etc., ? - Using Sytem.getProperty(…) (line.separator, path.separator, …)
  23. What is skeleton and stub? what is the purpose of those? - Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.
  24. What is the final keyword denotes? - final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.
  25. What is the significance of ListIterator? - You can iterate back and forth.
  26. What is the major difference between LinkedList and ArrayList? - LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.
  27. What is nested class? - If all the methods of a inner class is static then it is a nested class.
  28. What is inner class? - If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.
  29. What is composition? - Holding the reference of the other class within some other class is known as composition.
  30. What is aggregation? - It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.
  31. What are the methods in Object? - clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString
  32. Can you instantiate the Math class? - You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
  33. What is singleton? - It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }
  34. What is DriverManager? - The basic service to manage set of JDBC drivers.
  35. What is Class.forName() does and how it is useful? - It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).
  36. Inq adds a question: Expain the reason for each keyword of

    public static void main(String args[])

Core Java interview questions

  1. Can there be an abstract class with no abstract methods in it? - Yes
  2. Can an Interface be final? - No
  3. Can an Interface have an inner class? - Yes.
    	public interface abc
    		static int i=0; void dd();
    		class a1
    				int j;
    			public static void main(String a1[])
    				System.out.println("in interfia");
  4. Can we define private and protected modifiers for variables in interfaces? - No
  5. What is Externalizable? - Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)
  6. What modifiers are allowed for methods in an Interface? - Only public and abstract modifiers are allowed for methods in interfaces.
  7. What is a local, member and a class variable? - Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables
  8. What are the different identifier states of a Thread? - The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock
  9. What are some alternatives to inheritance? - Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
  10. Why isn’t there operator overloading? - Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().
  11. What does it mean that a method or field is “static”? - Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class.
  12. How do I convert a numeric IP address like into a hostname like
    	String hostname = InetAddress.getByName("").getHostName();
  13. Difference between JRE/JVM/JDK?
  14. Why do threads block on I/O? - Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed.
  15. What is synchronization and why is it important? - With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors.
  16. Is null a keyword? - The null value is not a keyword.
  17. Which characters may be used as the second character of an identifier,but not as the first character of an identifier? - The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.
  18. What modifiers may be used with an inner class that is a member of an outer class? - A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
  19. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? - Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
  20. What are wrapped classes? - Wrapped classes are classes that allow primitive types to be accessed as objects.
  21. 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).
  22. What is the difference between preemptive scheduling and time slicing? - Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
  23. What is a native method? - A native method is a method that is implemented in a language other than Java.
  24. What are order of precedence and associativity, and how are they used? - Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left
  25. What is the catch or declare rule for method declarations? - If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.
  26. Can an anonymous class be declared as implementing an interface and extending a class? - An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Junior Java programmer interview questions

  1. What is the purpose of finalization? - The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
  2. What is the difference between the Boolean & operator and the && operator? - If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
  3. How many times may an object’s finalize() method be invoked by the garbage collector? - An object’s finalize() method may only be invoked once by the garbage collector.
  4. What is the purpose of the finally clause of a try-catch-finally statement? - The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
  5. What is the argument type of a program’s main() method? - A program’s main() method takes an argument of the String[] type.
  6. Which Java operator is right associative? - The = operator is right associative.
  7. Can a double value be cast to a byte? - Yes, a double value can be cast to a byte.
  8. What is the difference between a break statement and a continue statement? - A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
  9. 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.
  10. What is the advantage of the event-delegation model over the earlier event-inheritance model? - The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component’s design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
  11. How are commas used in the intialization and iteration parts of a for statement? - Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.
  12. What is an abstract method? - An abstract method is a method whose implementation is deferred to a subclass.
  13. What value does read() return when it has reached the end of a file? - The read() method returns -1 when it has reached the end of a file.
  14. Can a Byte object be cast to a double value? - No, an object cannot be cast to a primitive value.
  15. 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.
  16. If a variable is declared as private, where may the variable be accessed? - A private variable may only be accessed within the class in which it is declared.
  17. What is an object’s lock and which object’s have locks? - An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.
  18. What is the % operator? - It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
  19. 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.
  20. Which class is extended by all other classes? - The Object class is extended by all other classes.
  21. Can an object be garbage collected while it is still reachable? - A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.
  22. Is the ternary operator written x : y ? z or x ? y : z ? - It is written x ? y : z.
  23. How is rounding performed under integer division? - The fractional part of the result is truncated. This is known as rounding toward zero.
  24. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? - The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
  25. What classes of exceptions may be caught by a catch clause? - A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
  26. If a class is declared without any access modifiers, where may the class be accessed? - A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
  27. Does a class inherit the constructors of its superclass? - A class does not inherit constructors from any of its superclasses.
  28. What is the purpose of the System class? - The purpose of the System class is to provide access to system resources.
  29. Name the eight primitive Java types. - The eight primitive types are byte, char, short, int, long, float, double, and boolean.
  30. Which class should you use to obtain design information about an object? - The Class class is used to obtain information about an object’s design.

Q: What is a output comment?
A: A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser. JSP Syntax

Example 1

Displays in the page source:

Q: What is a Hidden Comment?
A: A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or "comment out" part of your JSP page. You can use any characters in the body of the comment except the closing --%> combination. If you need to use --%> in your comment, you can escape it by typing --%\>.
JSP Syntax
<%-- comment --%>

<%@ page language="java" %>

A Hidden Comment

<%-- This comment will not be visible to the colent in the page source --%>

Q: What is a Expression?
A: An expression tag contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. Because the value of an expression is converted to a String, you can use an expression within text in a JSP file. Like
<%= someexpression %>

<%= (new java.util.Date()).toLocaleString() %>
You cannot use a semicolon to end an expression

Q: What is a Declaration?
A: A declaration declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as they are separated by semicolons. The declaration must be valid in the scripting language used in the JSP file.

<%! somedeclarations %>
<%! int i = 0; %>
<%! int a, b, c; %>

Q: What is a Scriptlet?
A: A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.Within scriptlet tags, you can 1.Declare variables or methods to use later in the file (see also Declaration).

2.Write expressions valid in the page scripting language (see also Expression).

3.Use any of the JSP implicit objects or any object declared with a tag.
You must write plain text, HTML-encoded text, or other JSP tags outside the scriptlet.

Scriptlets are executed at request time, when the JSP engine processes the client request. If the scriptlet produces output, the output is stored in the out object, from which you can display it.

Q: What are implicit objects? List them?
A: Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. The implicit objects re listed below

  • request
  • response
  • pageContext
  • session
  • application
  • out
  • config
  • page
  • exception

Q: Difference between forward and sendRedirect?
A: When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completly with in the web container. When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completly new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.

Q: What are the different scope valiues for the ?
A: The different scope values for are
1. page
2. request

Q: Explain the life-cycle mehtods in JSP?
A: THe generated servlet class for a JSP page implements the HttpJspPage interface of the javax.servlet.jsp package. Hte HttpJspPage interface extends the JspPage interface which inturn extends the Servlet interface of the javax.servlet package. the generated servlet class thus implements all the methods of the these three interfaces. The JspPage interface declares only two mehtods - jspInit() and jspDestroy() that must be implemented by all JSP pages regardless of the client-server protocol. However the JSP specification has provided the HttpJspPage interfaec specifically for the JSp pages serving HTTP requests. This interface declares one method _jspService().
The jspInit()- The container calls the jspInit() to initialize te servlet instance.It is called before any other method, and is called only once for a servlet instance.
The _jspservice()- The container calls the _jspservice() for each request, passing it the request and the response objects.
The jspDestroy()- The container calls this when it decides take the instance out of service. It is the last method called n the servlet instance.

Mobile OS war is coming ...!

Choosing OS is one of the main consideration when buying a mobile phone. You may have 8 MP camera, AMOLED screen and best hardware but without proper OS, you wont get 100% from your phone. Android, iPhone, Blackberry, Windows mobile, Web OS, Symbian and many other Proprietary mobile platforms to choose from, when purchasing a mobile phone. Thanks to Gartner who estimated the share of each mobile OS in 2012. This stats by Gartner will probably help you to know about the OS users around in near future.

Though iPhone and Android users are increasing, still 1/3rd of the mobile phone users are using Symbian OS. There are already 1 million applications for iPhone. Andriod apps number is also increasing slowly. According to Gartner, in 2012 Android will become the 2nd most used mobile OS after Symbian. But this will not reduce the share of iPhone or blackberry, in fact Android's gain will be from Symbain's loss. Android will eat away a little share from Symbian. The following are the estimated shares in 2012:
    • Many mobile manufacturers are preferring Android OS currently. Internet Giant Google behind the OS is also one of the reason for its fast capturing of market share.
    • iPhone is faster with lots of apps making your phone a Universal System.
    • Blackberry OS speed is very impressive and its best for business people.
    • Windows mobile looks quite promising with new versions 6.5 released and 7 releasing in next year.
    • Symbian OS has its history and in fact its the oldest and most used OS till current date.
    Mobile OS war between Android vs iPhone vs Blackberry vs Symbian vs Windows Mobile will make mobile users more advantageous with lots of new features in new models.

    [edit] Operating systems feature comparison

    Java 7 What`s New, Performance Benchmark 1.5 1.6 1.7

    java is one of the language which has overhauled it’s underneath technology ground-up. Even though, the basic concept of running inside JVM holds good, the way JVM handles Objects, Memory management has completely been revamped.

    A lot changed over 1.4 to 1.5. There were critical compile-time improvements, Runtime smartness and with Java 6 more performance optimizations; Java 7 – the modularity.

    Let’s start discussing each aspect of Java 7 which makes it go Loud -

    • Modularization – JSR 294 or Project Jigsaw
    • JVM Support for dynamic languages
    • More New I/O APIs which are nearly finished, includes true asynchronous I/O and finally a real file system API – JSR 203
    • The native language support for XML. (probable)
    • Safe rethrow – Allows a broad catch clause, with the compiler being smarter on what you’re allowed to rethrow based on what is thrown from the try block. (I had not seen this before but it looks nice)
    • Null dereference expressions – Null checks with ‘?’ syntax similar to Groovy… lettign developers avoid a nest of null checks.
    • Better type inference – Example around generics instantiations, but it was not clear how far the inference would be taken (the more the better in my opinion).
    • Multi-catch - Allows a comma separated list of disjunctive exception types in catch clause.
    • JSR 296 – Swing application framework – It still needs to be easier to create Swing apps.
    • Update: As per Sun Blogs

    After much discussion it’s become clear that theSwing Application Framework API as it is today hasn’t reached consensus and we feel still needs further design work done.

    Since the SAF API was committed to milestone 5 of JDK7 and that time is already here, this date is now impossible, and we need to decommit SAF from any specific JDK 7 milestone.

    The “Small” Sun changes are:

    • Upgrade class loader architecture – Work started in Java 5 and continues to evolve. There are some deadlock issues today in classloader delegation that will be addressed.
    • XRender pipeline for Java 2D – This was an Open JDK Integrators Challenge project,and is an analog to the OpenGL pipeline but much more portable across x11.
    • Swing Updates – JXLayer, DatePicker, CSS styling (maybe) that Ethan Nicholaus (sp?) has been working on
    • JavaFX

    Update: Few new Small changes of “Project coin” are available here.

    The “Fast” changes from Sun (This refers to performance improvements):
    Hotspot run-time compiler enhancements

    • A couple of concurrency (JSR 166) tweaks (Better support for Multicore)
    • G1 Garbage collector- Leads to much smaller pause times and hopes to replace CMS (Concurrent mark sweep) GC
    • Compressed pointer 64 bit VM
    • MVM-lite – Multiple Virtual Machines will help run isolated applications and allow a kill -9 on a Java application. Mark said it is not clear what problem would be solved, and original project was extremely ambitious, but desire to drag apps out of browser plugin presents a good usage and need for MVM. (This could be moved to a later release)

    The Theory and Practical

    As far as what changes you’ll see in your day-to-day work, my guess is that the major impact will be stuff like JSR 203 which overhauls the file system API. If JSR 310 is included, then it would also have a major impact on how you interact with any aspect of the date and time APIs. Many of the other JSRs will only impact you if you happen to already do something in that particular area (JMX – JSR 255, concurrency – JSR 166, etc).

    The biggest thing most people will notice may be performance. This is my favorite. And that is exactly what I thought about writing, and it expanded the scope to features aswell. As usual, each JDK brings a whole new set of performance optimizations. We’ve already seen some very encouraging results in String performance, array performance, and a new concurrent garbage collector (G1). I suspect many people will find that their existing code will work and run noticeably faster than it did in the past.


    I saw this one about the new features in Java 7:

    They use MergeSort as an example of how to exploit multiple CPUs for sorting. Java 7 has the nice feature, that it can now decide at runtime, how many threads should be used to solve a particular problem (see the coInvoke part).

    However, there is this tricky constant, SEQUENTIAL_THRESHOLD, which is used to decide whether to enforce sequential processing or not. How do you set this value? Well, you set it at design time, even though the example was meant to show how Java adapts at runtime…

    The next thing is that the whole array is passed as parameter. No matter what programming language you use, this is a bad design. If Java doesn’t copy the memory, you may have 2 CPUs looking at the same RAM area. If Java has a runtime optimization that detects that 2 CPUs are looking at the same area, and decides to copy the data, it will copy too much data…

    I’m not sure this example would perform better on a 4-CPU machine than on a single-CPU machine with the same CPUs…

    The basic problem in all this is, that it is extremely hard to find real world examples of parallelization of algorithms that can be optimized to any kind of parallel hardware. Good multi-threading must be done on a functionality level, not on the algorithm level.

    Also, every time we add multi-threading to code, we make it more complex. In other words, it comes at a cost. I predict that some of the future performance gains don’t come from making algorithms more threaded, but from changing data structures, reducing memory footprint and simple optimizations. As the price of more performance increases, efforts will be spent where most speed can be gained at the lowest price.

    Benchmarking JDK 7

    As per Sun, The JDK 7 delivers quite a speed boost over JDK 6 array accesses. For us, this is huge. It’s like another year and a half of Moore’s law for free. Only in software. And you don’t even have to write multi-threaded code.

    It’s basically a stress test that I used for ArrayLists, HashMaps, gets, array sets, and simple multiply-add-subtract, arithmetic, and concurrency APIs, Threads.

    I installed the following beta release of JDK 7:

    > java -version
    java version "1.7.0-ea"
    Java(TM) SE Runtime Environment (build 1.7.0-ea-b66)
    Java HotSpot(TM) Client VM (build 16.0-b06, mixed mode, sharing)

    Java has always suffered relative to C/C++ in matrix multiplication because Java does range checks on every array access (set or get). With some clever static and run-time analysis, we are able to eliminate most of the array bounds checks. They show on matrix benchmarks that this one improvement doubles the speed of the LU matrix factorization benchmark in the U.S. National Institute of Standards (NIST) benchmark suite SciMark 2, which like our clustering algorithm, is basically just a stress test for array access and arithmetic.

    I’m pretty excited about the new fork-join concurrency, too, as it’s just what we’ll need to parallelize the inner loops without too much work for us or the operating system.

    I decided to take my on Test-check for performance for Java 7 and then compare it with 5, 6.

    My tests have been on a Dell D630 Notebook running Windows 7 RTM (32 bit) with an Intel Core 2 CPU (2.4GHz), and 3GB of RAM.

    Here are the Benchmark Tests -

    Test 1. Add 5 Million String values (each calculated with some complex Math arithmetic)

    Test 2. ArrayList with 5 Million insertions (with values from Test1). Insertions are conditional and have additional computation before adding to array.

    Test 3. HashMap with 5 million keys, values. Each key, value pair is being calculated via concurrent thread. (This tread tests both Arithmetic and concurrency capabilities)

    Test 4. Printing 5 million items of ArrayList to number of Files (1000) and Reading back again. (Tests multicore concurrency to the edge) My CPU, HDD, RAM all went to Max.

    All of these tests were very memory intensive. Heap size varied between 1 – 2 GB during tests, due to large no. of objects. CPU Utilization was sometimes 50% (1 core’s max) and most of the time >70% and in Test3, Test4; CPU touched 100% most of the times.

    The Result is mind blowing!

    And the Result The Winner is … Java 7

    Java 5 <=== 18% faster=== < Java 6 < ===46% faster===< Java 7

    Note – This was totally based upon my tests, doesn’t necessarily means it’s for overall Java. The results may vary for different kinds of computations.