Owner: Interview Questions In Java And Java EE URL:http://interviewjava.blogspot.com/ Join Date: Fri, 08 Jun 2007 16:46:10 -0500 Rating:0 Site Description: World of tricky Core Java Q&A Covering Object Oriented Analysis and Design,JVM Internals,Java Language Fundamentals(Datatypes,Keywords,Operators and Assignments,Identifies etc.,Declarations and Modifiers,Conversion,Casting and Promotion,Flow control,Asser Site statistics:Click here
Java Tools 2007-10-03 08:31:00 To increase the efficiency and productivity of Java Developers,they all need a set of tools which equip them to design,code and test their work in consolidated ways.Here I tried to summarize various essentials or must have Java tools for all those who are fascinated with this language. Eclipse.org - It is an open source development platform for Java based applications, as well as other languages.Hibernate.org - An open source persistent classes development tool; due to licensing, it can be included in to other open source projects.JUnit.org - An open source testing platform for Java that works towards understanding your intentions.PMD - A Sourceforge project that scans Java apps and looks for bad code.SpringFramework.org - A Java/JEE application framework with a large support system and training sessions all over the world.Idevelopment Java Examples - A large collection of examples of Java programming along with documentation.JAD - A non-commercial use Java decompiler.Java.net - A s Read more:Tools
How do you connect to a MySql Database using JDBC? 2007-10-24 07:24:00 Recently some newbie asked me a simple question of connecting to MySql database using JDBC.Here is a code snippet for that.The important thing here is to ensure that you have added MySql database driver classes(mysql.jar) in your classpath. Here goes the code snippet:import java.sql.*;public class MySqlConnect { public static void main (String[] args) { Connection connection = null; try { String userName = "root"; String password = "bunty"; String url = "jdbc:mysql://localhost:3306/systdb"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); connection = DriverManager.getConnection (url, userName, password); System.out.println ("Database
connection established"); } catch (Exception e) { System.err.println ("Connection to database server cannot be establish"); } finally { if (connection != null)
Explain different inheritance mapping models in Hibernate. 2007-10-22 01:29:00 There can be three kinds of inheritance mapping in hibernate1. Table per concrete class with unions2. Table per class hierarchy3. Table per subclassExample:We can take an example of three Java classes like Vehicle, which is an abstract class and two subclasses of Vehicle as Car and UtilityVan.1. Table per concrete class with unionsIn this scenario there will be 2 tablesTables: Car, UtilityVan, here in this case all common attributes will be duplicated.2. Table per class hierarchySingle Table can be mapped to a class hierarchyThere will be only one table in database named 'Vehicle' which will represent all attributes required for all three classes.Here it is be taken care of that discriminating columns to different
iate between Car and UtilityVan3. Table per subclassSimply there will be three tables representing Vehicle, Car and UtilityVan
Read more:models
, Hibernate
Velocity Framework 2007-11-19 01:27:00 What is Velocity
Framework?Velocity is a Java based template engine.It permits anyone to use a simple yet powerful template language to reference objects defined in Java code.Velocity is inspired from 'WebMacro' , an alternative to JSP,PHP and ASP( www.webmacro.org).Where can Velocity be used?Velocity framework can be used in following areas:- Web apps, dynamic HTML pages are created and processed with VelocityViewServlet or number of frameworks that support Velocity - Source code generation- Automatic e-mails- XML transformation, provides an ant task called Anakia which reads an XML file and makes it available to a Velocity template. What are the features of Velocity?Velocity framework has following features:- Velocity is MVC based- It segregates HTML template code from Java code- It emphasizes on role based web app development - Velocity offers better maintainable web applicationsHow Velocity works?When using Velocity in an application program or in a servlet (or anywhere, actua
What are Tag Libraries provided with Struts? 2007-11-28 04:37:00 Struts supports following tag libraries:a).Bean Tags: All tags which correspond to struts-bean.tld provide capability of accessing beans related activities.b).HTML Tags: All tags which correspond to struts-html.tld used for HTML UI/Forms creation. c).Logic Tags: All tags which correspond to struts-logic.tld manages condition based logic,iterate over a statement based on some logic and application flow management. d).Nested Tags: All tags which correspond to struts-nested.tld make it easy to manage nested beans.e).Template Tags: All tags which correspond to struts-template.tld used for template creation while providing better maintenance of such websites. f). Tiles Tags: All tags which correspond to struts-tiles.tldJava Standard Tag Library (or JSTL as it's known), provides a specification for four separate areas of concern: * Core * XML Processing * Internationalization * DatabaseThe specif Read more:Libraries
, provided
What are the core classes of the Struts Framework? 2007-11-28 00:17:00 The classes which are at core of Struts Framework can be enumerated as given below:- org.apache.struts.action.Action- org.apache.struts.action.ActionForm- org.apache.struts.action.ActionMapping- org.apache.struts.action.ActionServlet - org.apache.struts.action.ActionForward
What are the differences between ActionErrors and ActionMessage?/What are the differences between Action.saveErrors(...) and Action.saveMessages(...)? 2007-11-25 23:38:00 To summarize, the difference between the classes Action
Errors/ActionError/ActionMessages/ActionMessage has absolutely nothing to do with the difference in behavior in Action.saveErrors(...) and Action.saveMessages(...) The difference between the classes is zero -- all behavior in ActionErrors was pushed up into ActionMessages and all behavior in ActionError was pushed up into ActionMessage. This was done in the attempt to clearly signal that these classes can be used to pass any kind of messages from the controller to the view -- errors being only one kind of message. The difference between saveErrors(...) and saveMessages(...) is simply the attribute name under which the ActionMessages object is stored, providing two convenient default locations for storing controller messages for use by the view. If you look more closely at the html:errors and html:messages tags, you can actually use them to get an ActionMessages object from any arbitrary attribute name in any scope. The difference b Read more:differences
How to handle duplicate submits in Struts? 2008-02-10 03:08:55 The duplicate form submission occurs-When a user clicks the Submit button more than once before the response is sent back or- When a client accesses a view by returning to a previously bookmarked page.It may result in inconsistent transactions and must be avoided.In Struts this problem can be handled by using the saveToken() and isTokenValid() methods of Action class. saveToken() method creates a token (a unique string) and saves that in the user's current session, while isTokenValid() checks if the token stored in the user's current session is the same as that was passed as the request parameter.It can be done by loading JSP through an Action and before loading the JSP call saveToken() to save the token in the user session. When the form is submitted, check the token against that in the s
Write Into An Excel File Using Java 2008-03-18 12:32:55 package example;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.util.Locale;import java.util.Properties;import jxl.Workbook;import jxl.WorkbookSettings;import jxl.format.Colour;import jxl.write.Label;import jxl.write.WritableCellFormat;import jxl.write.WritableFont;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.Write
Exception;public class JExcel
Example { int mCount = 0; public static void main(String[] args) { try { boolean isOutputFolder = false; JExcelExample jexcel = new JExcelExample(); Properties prop = jexcel.loadProperties(); String sheets = prop.getProperty("org.sheets"); File directory = new File(prop.getProperty("output.folder")); Read more:Using Java
Get Locale Specific Date 2008-03-18 12:09:58 import java.text.DateFormat;import java.util.Date;import java.util.Locale
;public class LocaleDate { /** * @param args */ public static void main(String[] args) { Locale americanLocale = new Locale("en", "US" ); Locale germanLocale = new Locale("de", "DE"); DateFormat americanFormat = DateFormat.getDateInstance(DateFormat.SHORT, americanLocale); DateFormat germanFormat = DateFormat.getDateInstance(DateFormat.SHORT, germanLocale); Date date = new Date(); System.out.println(americanFormat.format(date)); System.out.println(germanFormat.format(date)); }}
Read more:Specific
Sending EMail To GMail SMTP Server Using Java Mail APIs 2008-03-19 12:10:56 import java.security.Security;import java.util.Properties;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;/** * This application will require Java Mail API and which can be downloaded from * JavaBeansTM * Activation Framework extension or JAF (javax.activation) can be downloaded * from * * * @author pundeerd * * */public class MailingApplication { /** * @param args */ public static void main(String[] args) { // recepients String[] to = { "abc@gmail.com" }; String subject = "Test Email"; String message = "Hello there"; // sender String from = "xyz@gmail.com"; try { postMail(to, subject, message, from); } catch (MessagingExcep Read more:Sending
Some commonly used validations like EMail,Phone Number,SSN,Numeric values through Regular Expressions 2008-03-29 13:18:56 import java.util.regex.Matcher;import java.util.regex.Pattern;public class RegularExpressionExample { /** * @param args */ public static void main(String[] args) { System.out.println("Validating Email:" + isEmailValid("abc@xysss.comccccc")); System.out.println("Validating Phone Number
:" + isPhoneNumberValid("1234567798")); System.out.println("Validating SSN:" + isSSNValid("23456-werfdf")); System.out.println("Validating Numeric Values:" + isNumeric("-1234")); } public static boolean isEmailValid(String aEmail) { boolean isValid = false; /* * Examples:The following email addresses will pass validation * asdf@tttdd.com xyzzz@tyyy.in zxg.asd@tx.govt */ String emailExpression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; CharSequence inputStr = aEmail; Pattern patter Read more:Expressions
What is AJAX? Explain in detail how it works.Discuss its advantages and disadvantages. 2008-04-09 09:18:16 AJAX stands for Asynchronous Javascript and XML which is used for developing dynamic web applications. This concept was not new, as a matter of fact asynchronous loading of content without a full reload was existing for a long time.It was known as web remoting or remote scripting. AJAX requests data from server in an asynchronous fashion in background without affecting the presentation layer.Hence Ajax interactions allow for a clear separation of presentation logic from the data. In Rich Internet Applications(RIA) , an HTML document acts as a template or container where content is injected, based on client events using XML data retrieved from a server-side component.The functioning of data exchange between web browser and server occurs with XMLHttpRequest object is used which is inhere Read more:AJAX
Simplifying Service Oriented Architecture 2008-04-11 23:46:05 What is SOA?Why SOA?What are the constituents of SOA?Who suits best for SOA?When to avoid implementation of SOA?How to avoid risks in SOA implementation?How SOA makes things better or even worse?
Read more:Service
, Oriented
, Architecture
How SOA makes things better or even worse? 2008-04-11 12:06:39 With all the hype that SOA has brought to organizations, they have to brainstorm whether this will do any good to their business anyway.The organizations first have to understand that SOA can not be implemented by introduction of certain software products or services but it is an architectural approach which has to analyze existing systems,IT resources,ever changing business processes and requirements and comes up with a set of business aligned services which can cost effectively fit very well for a consistent business functioning for years to come. As discussed in my previous blog , SOA projects can easily be put into red zone if all its constituents are not well planned,managed and executed.A change is like oxygen for an organization and SOA has to help businesses adapt with changing ti Read more:makes
, things
, better
How to avoid risks in SOA implementation? 2008-04-11 12:03:36 SOA project may go haywire if things are not planned,managed and designed properly.It is very important to know your customer's requirements,expectations and improved business processes in advance before starting any analysis and design exercise.A continuous communication with your client is must so that you can understand their business processes very well and should be able to identify problem areas with some concrete solutions in mind.If you have a suggestions related to business processes improvement then get an approval from your client on business requirements as they keep changing all the time.So scope of work is clearly defined to you and your customer with extensive project planning.If a customer does not see any qualitative improvement in complex business processes simpli
When to avoid implementation of SOA? 2008-04-11 11:58:50 SOA offers a change in perspective, a paradigm shift from object oriented to service oriented.As for almost a decade, most of the development is done using Object oriented technologies and that led to tight coupling many a times with vendor specific technologies like CORBA,DCOM or RMI.SOA offers to a new thinking of services rather visualizing in terms of objects which makes it independent of underlying technology. If SOA implementation in an organization is not well thought of,planned and micro-detailed then it may lead to disaster, waste of valuable resources of time and money.SOA may not be a good idea for enterprises which are not too big and complex in their business process and do not depend upon business processes of its suppliers and business partners.For instance, if an organisati
Who suits best for SOA? 2008-04-11 11:57:09 The IT infrastructure which includes various business critical systems of an enterprise are built over a long period of time.They cannot always be made with latest technologies as their is already investment being made in earlier systems.The organizations which breathe change like oxygen have to think new ways in order to integrate all its existing systems,new or legacy, in order to orchestrate its business process with its partners,suppliers and customers.The IT strategies of organizations change with mergers and acquisitions and leads to more vendor or application specific systems, sometimes repeat of an application by different vendor, in such a scenario whole IT landscape of an organization becomes quite complex. SOA has opened new vistas to re-orient business on disintegrating busine
What are the constituents of SOA? 2008-04-11 11:55:35 There has been lot of terms which have been surfaced to define constituents of SOA delivery process and specially IBM has been actively coining new terms in order to streamline how SOA based solutions be developed. Service-Oriented Analysis and Design (SOAD)Service-Oriented Modeling and Architecture (SOMA)Business-Driven Development (BDD) I will try to briefly describe and simplify these terms. There is no formal definition of SOAD as yet from IBM.SOAD takes a hybrid approach of Object Oriented Analysis and Design(OOAD),Enterprsie Architecture(EA) frmawork and Business Process Management(BPM) approaches for SOA based solutions development. As per Gartner, more than 60% mission critical applications of various enterprises will be built using SOA by 2008.So that's what whole hype all abou
Why SOA? 2008-04-11 11:53:40 With advent of IT revolution, it is information that people want and technology is a mean to supply it and with time it is provided at lower costs.So keeping the costs continuously low is a challenge.These days business houses have huge dependency on IT and it cannot be wiped out completely.It makes great business sense to save costs that incur on big investments that these organizations do on IT infrastructure for running their complex business processes. The existing systems in an organization are rarely thrown away and they are valuable asset for enterprise from business point of view.SOA leverages the benefits of integrating new systems with old legacy ones.It is instrumental in linking IT resources and put them to reuse.The cost effectiveness of this style of architecture focuses on s
What is SOA? 2008-04-11 11:48:21 SOA has become a de-facto standard for system development and integration of new with existing legacy solutions running and supporting complex business processes.SOA, as IT world has always a fancy term for any new technology,elaborates to Serivce Oriented Architecture, is not a new term and has been around with emergence of webservices.In order to understand SOA, we must first understand what a webservice means, which is sometimes referred as crux of SOA,not always though.A system does not necessarily need to use web services and all related standards to be "service-oriented." For example, some service oriented systems have been implemented using Corba,DCOM,RPC, Jini and REST.A webservice is defined by a set of processes over a network which is a manifestation of some physical entities li
Apache AXIS with IBM's WSAD/RAD 2008-04-17 11:36:07 All major IDEs from different Vendors support webservices using Apache
Axis.In this post my objective is to demonstrate a simple web service development and deployment using IBM
's Websphere Application Developer(WSAD)/Rational Application Developer(RAD).They both provide support for Apache Axis and can use Axis libraries as required for runtime environment for web services.In following heads all the steps involved are explained:Configure Axis as runtime for Web services in RAD -Start RAD/WSAD. Open a new workspace, and close the welcome screen.-In WSAD/RAD,go on menu, Window >Preferences >Web Services >Server and RuntimeDo the settings for Apache Axis runtime as shown in the Figure 1.Figure 1Create a new Web Project Now we have a plain java class and a web project. Next step is to create a
Webserivces With Apache Axis Continued... 2008-04-17 11:27:52 In continuation with my previous post,this post explores various ways of deploying a webservice using Apache
Axis and how stubs can be generated with tools provided in Apache Axis.Deploying A Webservice:Web services can be deployed in axis in two ways-JWS (Java Web Service) Files - Instant Deployment-Custom Deployment - Introducing WSDDJWS Deployment:-Copy the *.java file into your web directory, and rename it *.jws.-You're done!You should now be able to access the service at the following URL (assuming your Axis web application is on port 8080): automatically locates the file, compiles the class, and converts SOAP calls correctly into Java invocations of your service classCustom Deployment - Introducing WSDD:Axis uses *.wsdd files to deploy Web services. This is a Axis specific format for
How to register Web Services with UDDI4j? 2008-04-16 13:24:04 Here we go with a snippet of code to register a web service using UDDI4j****BEGIN****proxy.setPublishURL(uddiPublishingURI);AuthToken token = proxy.get_authToken(mUserName, mPassword);Vector entities = new Vector();BusinessEntity be = new BusinessEntity("", mBusinessEntityName);// set all related dataBusinessDetail bd = proxy.save_business(token.getAuthInfoString(), entities);Vector businessEntities = bd.getBusinessEntityVector();BusinessEntity returnedBusinessEntity = (BusinessEntity) (businessEntities.elementAt(0));mServiceKey = returnedBusinessEntity.getBusinessServices
().get(0).getServiceKey();****END****'mServiceKey' will be used to extract to get URL of a registered Service from a UDDI Registry,and here is another snippet which helps you in locating a service :****BEGIN****UDDIProxy
Webservices, Apache Axis Way 2008-04-16 13:14:04 AXIS,is a complete frame work for developing and assessing Web Services.The current stable version of Axis in use is 1.2,though Axis 2 is on the anvil of release.You can find more information and download information about Axis C++ and Java on their official website.Axis is essentially a SOAP engine.It is an implemetation of SOAP which provides abstarction from dealing with SOAP and WSDL directly.You can always write webservices without Axis but it will be a very tedious job then.Axis2 is SOAP 3.0 which is written from scratch,the intention is to create a more modular, more flexible, and higher-performing SOAP implementation (relative to Apache
SOAP 2.0).Axis provides a framework for constructing SOAP processors such as clients, servers, gateways, etc. Axis supports both Java and C++.But A
How to develop,test and maintain SOA based solutions? 2008-04-16 13:03:38 Most significant part of any develop
ment life cycle is Analysis and Design phase and SOA is also not an exception.IBM has been consistently working in direction to lay down systematic approaches to identify and realizes services for SOA.As I have discussed earlier, analysis and design part of SOA centers around three approaches SOAD,SOMA and BDD.If you want to recap these concepts then read my blog 'Constituents of SOA'.In this post, my focus will be to develop SOA using web services.I will talk about webservices in its underlying technologies and in next post, how Apache Axis works to create web services over SOAP and several tools to test webservices.I will take a step-by-step approach for creating one simple web service using Apache Axis meant for Java. Apache Axis also supports C++.The Read more:solutions
What is obfuscation? How this technique works in Java? 2008-05-13 01:31:51 Java code gets compiled in bytecode and getting this bytecode decompiled with readily available Java decompilers makes it unsafe. The code obfuscation is a technique with which Java code can be protected. A threat to reverse engineer Java code has been taken very seriously. As the language was designed to be compiled into bytecode which is portable and can get executed within its own runtime envir
Java Coding Standards : Layout 2008-05-17 03:04:00 In professional Java programming world, it is essential that your developed code should follow some coding standards as per guidelines set by your organization or your client is technical enough to send you those details. A question arises why do I need such a practice, answer is very simple. To make life easy for those who are going to maintain or enhance your code. A better documented, neat-clea Read more:Coding
, Standards
Java Coding Standards:Documentation 2008-05-23 23:19:29 A proper documentation of code ensures better maintainability and code management.Writing documentation may not be fun but it is necessary.The focus is practical tips, practices to be followed religiously while documenting code . When you are a beginner in coding world this seems to be a insignificant and time consuming exercise but as you grow in experience you know how important it is to follow Read more:Coding
, Standards
, Documentation