Java Knowledge Bank – 1

Q : Give a few reasons for using Java?
A : Java is a fun language. Let’s look at some of the reasons:
􀂃 Built-in support for multi-threading, socket communication, and memory management (automatic garbage
collection).
􀂃 Object Oriented (OO).
􀂃 Better portability than other languages across operating systems.
􀂃 Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI. EJB etc)
and network protocols (HTTP, JRMP etc) with the help of extensive standardised APIs (Application Program
Interfaces).
Q : What are the advantages of Object Oriented Programming Languages (OOPL)?
A : The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account,
Customer etc. The features of the OO programming languages like polymorphism, inheritance and
encapsulation make it powerful. [Tip: remember pie which, stands for Polymorphism, Inheritance and
Encapsulation are the 3 pillars of OOPL]
Q : What is the difference between an abstract class and an interface and when should you use them?
A : In design, you want the base class to present only an interface for its derived classes. This means, you don’t want anyone to actually instantiate an object of the base class. You only want to upcast to it (implicit upcasting, which gives you polymorphic behaviour), so that its interface can be used. This is accomplished by making that class abstract using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents it.
The interface keyword takes this concept of an abstract class a step further by preventing any method or function implementation at all. You can only declare a method or function but not provide the implementation. The class, which is implementing the interface, should provide the actual implementation. The interface is a very useful and commonly used aspect in OO design, as it provides the separation of interface and implementation and enables you to:
􀂃 Capture similarities among unrelated classes without artificially forcing a class relationship.
􀂃 Declare methods that one or more classes are expected to implement.
􀂃 Reveal an object’s programming interface without revealing its actual implementation.
􀂃 Model multiple interface inheritance in Java, which provides some of the benefits of full on multiple
inheritances, a feature that some object-oriented languages support that allow a class to have more than one superclass.
When to use an abstract class?: In case where you want to use implementation inheritance then it is usually
provided by an abstract base class. Abstract classes are excellent candidates inside of application frameworks.
Abstract classes let you define some default behaviour and force subclasses to provide any specific behaviour.
Care should be taken not to overuse implementation inheritance .
When to use an interface?: For polymorphic interface inheritance, where the client wants to only deal with a type and does not care about the actual implementation use interfaces. If you need to change your design frequently, you should prefer using interface to abstract. CO Coding to an interface reduces coupling and interface inheritance can achieve code reuse with the help of object composition. Another justification for using interfaces is that they solve the ‘diamond problem’ of traditional multiple inheritance as shown in the figure. Java does not support multiple inheritances. Java only supports multiple interface inheritance. Interface will solve all the ambiguities caused by this ‘diamond problem’

Q : Explain the Java Collection framework?
A: The key interfaces used by the collection framework are List, Set and Map. The List and Set extends the Collection interface. Should not confuse the Collection interface with the Collections class which is a utility class.
A Set is a collection with unique elements and prevents duplication within the collection. HashSet and TreeSet
are implementations of a Set interface. A List is a collection with an ordered sequence of elements and may
contain duplicates. ArrayList, LinkedList and Vector are implementations of a List interface.
The Collection API also supports maps, but within a hierarchy distinct from the Collection interface. A Map is an object that maps keys to values, where the list of keys is itself a collection object. A map can contain duplicate values, but the keys in a map must be distinct. HashMap, TreeMap and Hashtable are implementations of a Map interface.
How to implement collection ordering? SortedSet and SortedMap interfaces maintain sorted order. The
classes, which implement the Comparable interface, impose natural order. For classes that don’t implement
comparable interface, or when one needs even more control over ordering based on multiple attributes, a
Comparator interface should be used.
Q : Give an example where you might use a static method?
A : Static methods prove useful for creating utility classes, singleton classes and factory methods Utility classes are not meant to be instantiated. Improper coding of utility classes can lead to
procedural coding. java.lang.Math, java.util.Collections etc are examples of utility classes in Java.

J2EE Overview

What Is the J2EE?
- Open and standard based platform for
- developing, deploying and managing
- n-tier, Web-enabled, server-centric, and component-based enterprise applications

What Makes Up J2EE?
- API and Technology specifications
- Development and Deployment Platform
- Standard and production-quality implementation
- Compatibility Test Suite (CTS)
- J2EE brand
- J2EE Blueprints
- Sample codes

Evolution of Enterprise Application Framework
- Single tier
- Two tier
- Three tier
– RPC based
– Remote object based
- Three tier (HTML browser and Web server)
- Proprietary application server
- Standard application server

J2EE 1.4 APIs and Technologies
- J2SE 1.4 (improved)
- JAX-RPC (new)
- Web Service for J2EE
- J2EE Management
- J2EE Deployment
- JMX 1.1
- JMS 1.1
- JTA 1.0
- Servlet 2.4
- JSP 2.0
- EJB 2.1
- JAXR
- Connector 1.5
- JACC
- JAXP 1.2
- JavaMail 1.3
- JAF 1.0

Summary
- J2EE is the platform of choice for development and deployment of n-tier, web-based, transactional, component based enterprise applications
- J2EE is standard-based architecture
- J2EE is all about community
- J2EE evolves according to the needs of the industry

Follow

Get every new post delivered to your Inbox.