tag:blogger.com,1999:blog-188705372015-05-05T15:31:23.071+05:30Java Rocks!!!World of tricky Core Java Q and A Covering Object Oriented Analysis and Design, JVM Internals,Java Language Fundamentals,Datatypes,Keywords,Operators and Assignments,Identifies,Declarations and Modifiers, Conversion,Casting and Promotion, Flow control,Assertions,
Exception Handling and Garbage Collection,Objects and Classes), Basic Packages and their classes,JDBC,JFC Swing,Java Server Pages (JSP),
Servlets,EJB,JMS,JNDI etc and Open
source technologies like Struts,Hibernate,Spring etcjavapeoplenoreply@blogger.comBlogger203125tag:blogger.com,1999:blog-18870537.post-83609217502364141472011-08-10T03:34:00.001+05:302012-01-18T03:50:34.126+05:30How to add BASIC Authentication into HttpURLConnection?Here is one sample.<br /><br /> ...<br /> try {<br /> //Create connection<br /> url = new URL(targetURL);<br /> connection = (HttpURLConnection)url.openConnection();<br /> connection.setRequestMethod("POST");<br /> ...<br /> BASE64Encoder enc = new sun.misc.BASE64Encoder();<br /> String userpassword = username + ":" + password;<br /> String encodedAuthorization = enc.encode( userpassword.getBytes() );<br /> connection.setRequestProperty("Authorization", "Basic "+<br /> encodedAuthorization);<br /> ...<br /> //Send post data<br /> ...<br /><br /> } catch (Exception e) {<br /> ...<br /> } finally {<br /><br /> if(connection != null) {<br /> connection.disconnect(); <br /> }<br /> }<br /> }<br /> ...javapeoplenoreply@blogger.com1tag:blogger.com,1999:blog-18870537.post-10049628811730073022011-08-10T03:33:00.002+05:302011-12-09T23:34:50.440+05:30How to Use JDBC Java to Create Table?his example demonstrates how to create a table in JDBC in MySQL database.<br /><br />import java.sql.Connection;<br />import java.sql.DriverManager;<br />import java.sql.SQLException;<br />import java.sql.Statement;<br /><br />public class JDBCCreateTable {<br /><br /> private static final String DBURL = <br /> "jdbc:mysql://localhost:3306/mydb?user=usr&password=sql&" +<br /> "useUnicode=true&characterEncoding=UTF-8";<br /> private static final String DBDRIVER = "org.gjt.mm.mysql.Driver";<br /> <br /> static {<br /> try {<br /> Class.forName(DBDRIVER).newInstance();<br /> } catch (Exception e){<br /> e.printStackTrace();<br /> }<br /> }<br /><br /> private static Connection getConnection() <br /> {<br /> Connection connection = null;<br /> try {<br /> connection = DriverManager.getConnection(DBURL);<br /> }<br /> catch (Exception e) {<br /> e.printStackTrace();<br /> }<br /> return connection;<br /> }<br /><br /> public static void main(String[] args) {<br /> Connection con = getConnection();<br /> Statement stmt =null;<br /> String createString;<br /> createString = "CREATE TABLE `mydb`.`employees` ("+<br /> "`EmployeeID` int(10) unsigned NOT NULL default '0',"+<br /> "`Name` varchar(45) collate utf8_unicode_ci NOT NULL default '',"+<br /> "`Office` varchar(10) collate utf8_unicode_ci NOT NULL default '',"+<br /> "`CreateTime` timestamp NOT NULL default CURRENT_TIMESTAMP,"+<br /> "PRIMARY KEY (`EmployeeID`)"+<br /> ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; <br /> try {<br /> stmt = con.createStatement();<br /> stmt.executeUpdate(createString);<br /> } catch(SQLException ex) {<br /> System.err.println("SQLException: " + ex.getMessage());<br /> }<br /> finally {<br /> if (stmt != null) {<br /> try {<br /> stmt.close();<br /> } catch (SQLException e) {<br /> System.err.println("SQLException: " + e.getMessage());<br /> }<br /> }<br /> if (con != null) {<br /> try {<br /> con.close();<br /> } catch (SQLException e) {<br /> System.err.println("SQLException: " + e.getMessage());<br /> }<br /> }<br /> }<br /> }<br /><br />}javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-53000297135284666042011-08-10T03:31:00.001+05:302011-12-09T23:34:44.544+05:30How to read input from console (keyboard) in Java?There are few ways to read input string from your console/keyboard. The following smaple code shows how to read a string from the console/keyboard by using Java.<br /><br />public class ConsoleReadingDemo {<br /><br /> public static void main(String[] args) {<br /><br /> // ====<br /> BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));<br /> System.out.print("Please enter user name : ");<br /> String username = null;<br /> try {<br /> username = reader.readLine();<br /> } catch (IOException e) {<br /> e.printStackTrace();<br /> }<br /> System.out.println("You entered : " + username);<br /><br /> // ===== In Java 5, Java.util,Scanner is used for this purpose.<br /> Scanner in = new Scanner(System.in);<br /> System.out.print("Please enter user name : ");<br /> username = in.nextLine(); <br /> System.out.println("You entered : " + username);<br /> <br /> <br /> // ====== Java 6<br /> Console console = System.console();<br /> username = console.readLine("Please enter user name : "); <br /> System.out.println("You entered : " + username);<br /><br /> }<br />}<br /><br />The last part of code used java.io.Console class. you can not get Console instance from System.Console() when running the demo code through Eclipse. Because eclipse runs your application as a background process and not as a top-level process with a system console.<br /><br />javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-38580504360610358672011-08-10T03:17:00.001+05:302011-08-10T03:17:35.840+05:30Why we call start() method which in turns calls run method, why not we directly call run method ?In both the above examples, the run() method is the most important method in the thread classes, it is also the only method that we need to implement in both cases. Why it's only proper to call the start() method to start the thread instead of calling the run() method directly? Because the run() method is not a regular class method. It should only be called by the JVM. Writing thread classes is not about a single sequential thread, it's about the use of multiple threads running at the same time and performing different tasks in a single program. The JVM needs to work closely with the underneath operating system for the actual implementation of concurrent operations. This is how the performance can be improved, and all other benefits mentioned above can be achieved.
<br />
<br />You should not invoke the run() method directly. If you call the run() method directly, it will simply execute in the caller's thread instead of as its own thread. Instead, you need to call the start() method, which schedules the thread with the JVM. The JVM will call the corresponding run() method when the resources and CPU is ready. The JVM is not guaranteed to call the run() method right way when the start() method is called, or in the order that the start() methods are called. Especially for the computers have a single processor, it is impossible to run all running threads at the same time. The JVM must implement a scheduling scheme that shares the processor among all running threads. This is why when you call the start() methods from more than one thread, the sequence of execution of the corresponding run() methods is random, controlled only by the JVM.
<br />
<br />javapeoplenoreply@blogger.com2tag:blogger.com,1999:blog-18870537.post-8970218575137517232011-08-01T06:31:00.000+05:302011-08-01T06:33:05.992+05:30Java JDBC Transaction Isolation LevelsGenerally speaking, as the isolation levels become more restrictive, the performance of the system decreases because transactions are prevented from accessing the same data. If isolation levels are very restrictivein other words, if they are at the Serializable levelthen all transactions, even simple reads, must wait in line to execute. This can result in a system that is very slow. J2EE server that process a large number of concurrent transactions and need to be very fast will therefore avoid the Serializable isolation level where it is not necessary.<br /><br /><strong>Read Uncommitted </strong><br />The transaction can read uncommitted data (i.e., data changed by a different transaction that is still in progress). Dirty reads, nonrepeatable reads, and phantom reads can occur. Bean methods with this isolation level can read uncommitted changes.<br /><br /><strong>Read Committed</strong><br />The transaction cannot read uncommitted data; data that is being changed by a different transaction cannot be read. Dirty reads are prevented; nonrepeatable reads and phantom reads can occur. Bean methods with this isolation level cannot read uncommitted data.<br /><br /><strong>Repeatable Read</strong><br />The transaction cannot change data that is being read by a different transaction. Dirty reads and nonrepeatable reads are prevented; phantom reads can occur. Bean methods with this isolation level have the same restrictions as those in the Read Committed level and can execute only repeatable reads.<br /><br /><strong>Serializable</strong><br />The transaction has exclusive read and update privileges; different transactions can neither read nor write to the same data. Dirty reads, nonrepeatable reads, and phantom reads are prevented. This isolation level is the most restrictive.<br /><br />Note: J2EE Isolation level on connections used by CMP beans<br />In a EJB 2.x or EJB 3.0 module, when a CMP bean uses a new data source to access a backend database, the isolation level is determined by J2EE Application Server run time, based on the type of access intent assigned to the bean or the calling method. Other non-CMP connection users can access this same data source and also use the access intent and application profile support to manage their concurrency control.javapeoplenoreply@blogger.com1tag:blogger.com,1999:blog-18870537.post-50626432434740125902011-08-01T06:15:00.001+05:302011-08-01T06:19:42.886+05:30Interview TipsHello All, Today I came across very interesting site where we can find interesting interview tips for different types of interviews<br /><br /><a href="http://interviewtip.net/job-interview-tips/">Read more......</a>javapeoplenoreply@blogger.com2tag:blogger.com,1999:blog-18870537.post-1412420215033996332010-10-29T15:06:00.001+05:302010-12-24T14:41:59.953+05:30Struts / Java / J2EE Frequently-Asked Interview Questions<div style="FONT-SIZE: 13px; COLOR: #000000; DIRECTION: ltr; FONT-FAMILY: Tahoma"><br /><div dir="ltr"><span style="font-family:Tahoma;font-size:85%;color:#000000;"><h3 class="post-title entry-title"> </h3><div class="post-header"><div class="post-header-line-1"></div></div><div class="post-body entry-content"><strong>Are Struts's action classes Thread-safe?</strong><br />Yes. Action classes are based on "one-instance and many-threads". This is to conserve resources and to provide the best possible throughput.<br /><br /><strong>What are the various Struts Tag libraries?</strong><br />There are various struts tags. But the most-repeated tags are:<br />struts-bean.tld<br />struts-html.tld<br />struts-logic.tld<br />struts-nested.tld<br /><br /><strong>What is ActionMapping in struts?</strong><br />Action mapping defines the flow of one request. The possible sequence is<br />User -&gt; request -&gt; Form -&gt; Validation -&gt; Business Code -&gt; Forward -&gt; JSP -&gt; response -&gt; User.<br />The components involved are Action classes, Forms and JSP.<br /><br /><strong>What are the advantages of having multiple struts-config in the same application?</strong><br />The implementation with many struts-config is to organize the development work, so that many people may be involved and it is some organized way of doing things. But this would result in some compromise in performance(speed). Technically there is no any difference between single and multiple struts-config files.<br /><br /><strong>What are the ways in which resource file can be used in struts?</strong><br />Defining message resources in struts-config file.<br />Programmatically using resource files in Java classes or in JSP files.<br /><br /><strong>Explain the term 'architecture of the application'?</strong><br />Architecture is the set of rules (or framework) to bring in some common way of assembling or using J2EE components in the application. This helps in bringing consistency between codes developed by various developers in the team.<br /><br /><strong>Which is the architecture followed by struts?</strong><br />Struts follows MVC architecture.<br /><br /><strong>What are components corresponding o M, V and C in struts?</strong><br /><br />Model : The model represents the data of an application. Anything that an application will persist becomes a part of model. The model also defines the way of accessing this data ( the business logic of application) for manipulation. It knows nothing about the way the data will be displayed by the application. It just provides service to access the data and modify it. Here 'Form Bean' represents Model layer.<br /><br />View : The view represents the presentation of the application. The view queries the model for its content and renders it. The way the model will be rendered is defined by the view. The view is not dependent on data or application logic changes and remains same even if the business logic undergoes modification. JSP represents View Layer.<br /><br />Controller : All the user requests to the application go through the controller. The controller intercepts the requests from view and passes it to the model for appropriate action. Based on the result of the action on data, the controller directs the user to the subsequent view. Action classes (action servlets) represent Controller layer.<br /><br /><strong>Differentiate between the terms 'Design Patterns', 'Framework' and 'Architecture'.</strong><br /><strong>Design Pattern:</strong> The various solutions arrived at for the known problem. This helps to avoid re-inventing the wheel. The risk-free solution can be easily used by others. For example, singleton is the design pattern that you can use instantly to enfore one object per class. You do not need to think of this on your own.<br /><strong>Framework:</strong> A framework is a structure or set of rules, used to solve or address complex issues. It is basically a reusable designf for the J2EE applications. For example, Struts, JSF,etc., are the frameworks. You can use these frameworks based on the requirements of your application and each has its own set of advantages.<br /><br /><strong>Architecture:</strong> It is a design that describes how the various components in the application fit together. For example, MVC is an architecture which is helpful to define how the components interact within the application.<br /><br /><br /><strong>What is the difference between ActionForm and DynaActionForm?</strong><br />In action form, you need to define the form class that extends ActionForm explicitly, whereas you can define the form dynamically inside the struts-config file when using DynaActionForm.<br /><br /><strong>How can you use Validator framework in struts?<br /></strong>Validator Frameworks are helpful when the application needs server-side validation such that the particular set of validations occur very frequently within the same application. This avoids writing complex code in validation() method in every form bean. Using validator framework, there are different pre-written validations in place. You can customize these validations in XML file.<br /><br /><strong>What are client-side and server-side vaidations?</strong><br /><strong>Client-side validations:</strong> These are the validations that id done using javascripts. There is always a danger involved that the user can get through (crack-through) these validations. But for some simple validations, like converting lower-case to upper-case or date validations can be done, you can use javascripts.<br /><strong>Server-side validations:</strong> These are the validations done in server-side using Java components (Form bean or in business logics) where the user has no chance to crookedly get through the system.<br /><br /><strong>What are the advantages &amp; differences between using validate() method in form over validations using validator framework.</strong><br />Refer to the previous-answer.<br /><br /><strong>Define the terms authentication and authorisation.</strong><br />Authentication is the process/rule that validates if the user is allowed to access the system or not.<br />Authorization is the process/rule that validates if the user is allowed to access the particular part of the system or not. This occurs after user's successful authentication.<br /><br /><strong>What are the components provided in J2EE to perform authentication and authorization?<br /></strong>Authentication – RequestProcessor and/or Filter.<br />Authorization - DTO, JDO or Java or Action classes.<br /><br /><strong>Give the difference between between 'DispatchAction' and 'Action'.</strong><br />A DispatchAction contains various different methods other than the standard execute() method in Action classes. These methods are executed based on some request parameter. For example, you can code in such a way that three buttons (namely Insert, Delete, Update) buttons correspond to different methods such as insert(), delete() and udpate(). The submit button in JSP would have the property that has the value which matches to any one of the methods defined in DispatchAction class.<br /><br /><strong>What is pagination technique? How can you design them in struts?</strong><br />Pagination is the technique where the bulk of results are split into different pages and only the information where the user can conveniently see are displayed in a page. (Like in Goooooogle). This can be achieved in many ways, but the simplest method is to have a query string (say http://www.testwebsite?pageNumber=2) would lead to information corresponding to resultset rows from 11 to 20. Assuming that you want to display 10 related rows of information, you can set the formula as follows:<br /><em>Starting row = (pageNumber-1) * <number>+ 1 which is equal to 11.<br />Ending row = Starting row + <number>which is equal to 20.<br /></em><br /><strong>How can you populate the drop-down list using form properties?</strong><br />There are many ways for this. But the best method is to use <?xml:namespace prefix = html /><html:options>which defines collection that needs to be used to populate the drop-down list, the property to store the selected value and the collection that is used to display the labels (what we see in JSP page). For Example,<br /><br />html:options collection="form-collection-property"<br />property="form-property"<br />labelProperty="form-another-collection-property"<br /><br /><strong>What is the XML parser provided in struts? Can you use it for other purposes?</strong><br />'Digester' framework. Yes we can use for our applications to store and parse our application-related data.<br /><br /><strong>Difference between Struts 1.0 and 1.1</strong><br /><ul><li>Perform() method was replaced by execute() </li><li>DynaActionForms are introduced. </li><li>Tiles Concept is introduced </li><li>We can write our own Controller by Inheriting RequestProcessor</html:options></span></li></ul></div></div></div>javapeoplenoreply@blogger.com10tag:blogger.com,1999:blog-18870537.post-16519002784906711642010-10-29T15:02:00.002+05:302010-12-24T14:43:29.242+05:30Advanced J2EE Concepts - Implementing Internationalization in Struts<div style="FONT-SIZE: 13px; COLOR: #000000; DIRECTION: ltr; FONT-FAMILY: Tahoma"><div dir="ltr"><span style="font-family:Tahoma;font-size:85%;color:#000000;"><h3 class="post-title entry-title"><strong><u></u></strong> </h3><div class="post-body entry-content"><p><strong>How is 'Internationalization' implemented in struts?<br /></strong></p><p><strong><u>Default Internationalization (Detected based on Browser's settings):</u></strong></p><p>Internationalization is an important concept of making the application to be compatible with different geographical location and user-friendly with respect to their location by means of providing the information in their preferred language.<br /><br />In struts, it can be done quite easily. The application resource file name can be extended with underscore followed by locale.<br /><br />For example ,<br /><br />When your application contains the file "ApplicationResource_en.properties", it would mean that it supports english language. When another file "ApplicationResource_fr.properties" exists, it would mean the localization for 'French'. </p><p>The selection of file and the content is done and decided automatically by struts. When the browser's setting is found with French settings, then struts automatically retrieves the value for the specific key from the appropriate resource file. Similarly you can add multiple property files for various locale. </p><p>But please remember that you can have one property file name with different extensions like <span style="COLOR: rgb(0,0,153)"><strong>_en, _fr, _de</strong></span>, etc., If they differ, the internationalization will not work. Also that only one file (one time), is specified in struts-config.xml. Each property file must have the same key with different values as follows:</p><p>In <span style="COLOR: rgb(0,0,153)">ApplicationResources.properties_en</span>, you specify <span style="COLOR: rgb(0,0,153)">mainpage.welcome=Hi, You are welcome..</span></p><p>In <span style="COLOR: rgb(0,0,153)">ApplicationResources.properties_fr</span>, you specify <span style="COLOR: rgb(0,0,153)">mainpage.welcome=&lt; message in French &gt;<welcome></welcome></span></p><p><strong><u>Programmatic implementation of Internationalization (By manual selection)</u></strong></p><p>The localization can even be done programmatically by placing 'Locale' object in session.<br /><span style="COLOR: rgb(0,0,153)"><span style="font-size:78%;"><span style="font-size:85%;">session.setAttribute("org.apache.struts.action.LOCALE", new Locale("fr"));</span></span></span></p><p>For example, You can create links one for each country's localization in the main page. Each link leads to an action class with different query string such as</p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">&lt;A HREF="setCountry?lang=en" &gt; English &lt;A&gt;</span></span></p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">&lt;A HREF = "setCountry?lang=de"&gt; German &lt;A&gt;</span></span></p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">&lt;A HREF="setCountry?lang=fr"&gt; French &lt;A&gt;</span></span></p><p>When clicked, the action is called. Inside the action class you retrieve the lang parameter as follows</p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">String lang = request.getParamter("lang");</span></span></p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">if (lang.equals("fr")) </span></span></p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">session.setAttribute("org.apache.struts.action.LOCALE", new Locale("fr"));</span></span></p><p><span style="COLOR: rgb(0,0,153);font-size:78%;" ><span style="font-size:85%;">if (lang.equals("de"))<br />session.setAttribute("org.apache.struts.action.LOCALE", new Locale("de"));</span></span></p><p>-------------------------------------------------------------</p><p>Hope this explains the concept of internationalization.</span></p></div></div></div>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-27214858132524591412010-10-25T15:23:00.002+05:302010-12-24T14:44:07.496+05:30Six Interview Mistakes<div style="FONT-SIZE: 13px; COLOR: #000000; DIRECTION: ltr; FONT-FAMILY: Tahoma"><div class="post-73 post type-post hentry category-career category-interview-tips" id="post-73" sizcache="10" sizset="0"><div class="entry-head" sizcache="5" sizset="8"><p>It's tough to avoid typical interview traps if you're unsure what they are. Here are a half dozen to watch out for.</p><p class="normalheading"><strong>1. Confusing an Interview with an Interrogation.</strong></p><p class="normal">Most candidates expect to be interrogated. An interrogation occurs when one person asks all the questions and the other gives the answers. An interview is a business conversation in which both people ask and respond to questions. Candidates who expect to be interrogated avoid asking questions, leaving the interviewer in the role of reluctant interrogator.</p><p class="normalheading"><strong>2. Making a So-Called Weakness Seem Positive.</strong></p><p class="normal" sizcache="5" sizset="12">Interviewers frequently ask candidates, "<a class="internal_relative" href="http://interview.monster.com/articles/biggest/">What are your weaknesses</a>?" Conventional interview wisdom dictates that you highlight a weakness like "I'm a perfectionist," and turn it into a positive. Interviewers are not impressed, because they've probably heard the same answer a hundred times. If you are asked this question, highlight a skill that you wish to improve upon and describe what you are doing to enhance your skill in this area. Interviewers don't care what your weaknesses are. They want to see how you handle the question and what your answer indicates about you.</p><p class="normalheading"><strong>3. Failing to Ask Questions.</strong></p><p class="normal" sizcache="5" sizset="13">Every interview concludes with the interviewer <a class="internal_relative" href="http://interview.monster.com/articles/anyquestions/">asking if you have any questions</a>. The worst thing to say is that you have no questions. Having no questions prepared indicates you are not interested and not prepared. Interviewers are more impressed by the questions you ask than the selling points you try to make. Before each interview, make a list of five questions you will ask. "I think a good question is, 'Can you tell me about your career?'" says Kent Kirch, director of global recruiting at Deloitte. "Everybody likes to talk about themselves, so you're probably pretty safe asking that question."</p><p class="normalheading"><strong>4. Researching the Company But Not Yourself.</strong></p><p class="normal" sizcache="5" sizset="14">Candidates intellectually prepare by researching the company. Most job seekers do not research themselves by taking inventory of their experience, knowledge and skills. <a class="internal_relative" href="http://interview.monster.com/articles/assessing/">Formulating a talent inventory</a> prepares you to immediately respond to any question about your experience. You must be prepared to discuss any part of your background. Creating your talent inventory refreshes your memory and helps you immediately remember experiences you would otherwise have forgotten during the interview.</p><p class="normalheading"><strong>5. Leaving Your Cell Phone On.</strong></p><p class="normal">We may live in a wired, always-available society, but a ringing cell phone is not appropriate for an interview. Turn it off before you enter the company.</p><p class="normalheading"><strong>6. Waiting for a Call.</strong></p><p class="normal" sizcache="5" sizset="15">Time is your enemy after the interview. After you send a <a class="internal_relative" href="http://interview.monster.com/articles/notes/">thank-you email and note </a>to every interviewer, follow up a couple of days later with either a question or additional information. Try to contact the person who can hire you, and assume that everyone you met with has some say in the process. Additional information can be details about your talents, a recent competitor's press release or industry trends. Your intention is to keep everyone's memory of you fresh.</p></div></div></div>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-16809868580517449952010-10-25T15:01:00.000+05:302010-10-25T15:02:12.363+05:30Java Exceptions and Error Handling Interview Questions<div style="FONT-SIZE: 13px; COLOR: #000000; DIRECTION: ltr; FONT-FAMILY: Tahoma"> <div></div> <div dir="ltr"><font face="Tahoma" size="2"> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What do you mean by exception and error handling?</font></span></strong></p> <p class="MsoNormal">A: When a program encounters and un-expected situation from where it cannot continue the normal flow, it can break from the normal execution flow by throwing and exception or an error.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What is the difference between an Error and an Exception?</font></span></strong></p> <p class="MsoNormal">A: An Exception is an unexpected scenario from which the program can recover but an error means that the program has encountered an unrecoverable problem.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Can you give an example of an unrecoverable problem when error is thrown?</font></span></strong></p> <p class="MsoNormal">A: Yes, when a java program runs out of memory it is a problem from which the program cannot recover and OutOfMemoryError will be thrown.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Does it mean that when error is thrown, we cannot catch it and continue execution?</font></span></strong></p> <p class="MsoNormal">A: We can catch errors, but it is not advised to do that because when error happens it means that some unrecoverable problem has happened. Even if we catch the error, we cannot guarantee the stability of the application and something else might fail.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What are the different kinds of Exceptions?</font></span></strong></p> <p class="MsoNormal">A: Checked Exceptions and Unchecked Exceptions.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What are runtime Exceptions?</font></span></strong></p> <p class="MsoNormal">A: Un Checked Exceptions are also known as Runtime Exceptions.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What do you mean by Checked Exceptions?</font></span></strong></p> <p class="MsoNormal">A: Checked exceptions are those exceptions which have to be explicitly handled in the code.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Can we create our own checked exceptions?</font></span></strong></p> <p class="MsoNormal">A: Yes, we just have to extend the Exception class or any of its sub classes (except RuntimeException)</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: How can we create our own runtime exception?</font></span></strong></p> <p class="MsoNormal">A: We have to extend the RuntimeException class or any of its sub classes.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: How can we create our own Errors?</font></span></strong></p> <p class="MsoNormal">A: We have to extend the Error class.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What are the different approaches of Exception handling?</font></span></strong></p> <p class="MsoNormal">A:<span> </span>We can use Try Catch block or we can declare the exception in the method definition's throws clause</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Explain the difference between the two approaches of exception handling</font></span></strong></p> <p class="MsoNormal">A: We use the try catch clause where we want to process the exception and perform some action like displaying an error message. When an exception is caught using the catch clause, it will not be propagated to the caller.</p> <p class="MsoNormal">We declare the exception in the throws clause of the calling method when the exception has to be propagated to the caller and the exception is supposed to be handled by the caller.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What is finally?</font></span></strong></p> <p class="MsoNormal">A: Finally is also a block like catch block to be used with the try block. Control will come to finally block irrespective of whether exception was thrown or not.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What is the difference between catch and finally?</font></span></strong></p> <p class="MsoNormal">A: When a catch block is used, we have to mention what exception has to be caught in the catch clause; where as in finally we need not mention anything. Code in the catch block is executed only when the exception is thrown whereas the code in finally is executed irrespective of whether exception was thrown or not.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Can we have a try block without a catch block?</font></span></strong></p> <p class="MsoNormal">A: yes, then we must have a finally block. When try block is used, we must use either a catch block or a finally block or both.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What happens when we use only try and finally block without a catch block?</font></span></strong></p> <p class="MsoNormal">A: When catch block is not used, the exceptions that are thrown will not be caught and the exception will be propagated to the caller, but before the exception is propagated, the code in the finally block will be executed.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: When do you use a catch block and when do you use a finally block?</font></span></strong></p> <p class="MsoNormal">A: We use a catch block when we want to handle the exception scenario. We use a finally block alone when we want to do some cleanup but at the same time propagate the exception to the caller. We use a finally block together with a catch block when we want to do something irrespective of what exception is thrown.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: what will happen if we return from the try block, will the finally block get executed?</font></span></strong></p> <p class="MsoNormal">A:<span> </span>yes, after the return statement in the try block is executed, the statements in the finally block will be executed before the control goes to the calling method.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: What happens when we have a return statement in the try block as well as in the finally block.</font></span></strong></p> <p class="MsoNormal">A: when we have return statement both in try and finally blocks, then first the return statement of try block gets executed, the before the method returns, the statements in the finally block will get executed and since there is return statement in finally also, that will also get executed and the value that will be returned to the caller will be the value returned from the finally block.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: If I write System.exit (0); at the end of the try block, will the finally block still execute?</font></span></strong></p> <p class="MsoNormal">A: No.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Can I have more than one catch block following a try block?</font></span></strong></p> <p class="MsoNormal">A: yes,</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: what are the rules for having multiple catch blocks?</font></span></strong></p> <p class="MsoNormal">A:<span> </span></p> <p class="MsoListParagraphCxSpFirst" style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in"> &lt;!--[if !supportLists]--&gt;<span><span>1)<span style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal"> </span></span></span>&lt;!--[endif]--&gt;Each exception can be caught only once.</p> <p class="MsoListParagraphCxSpLast" style="MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in"> &lt;!--[if !supportLists]--&gt;<span><span>2)<span style="FONT: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal"> </span></span></span>&lt;!--[endif]--&gt;The catch block for sub class exceptions should come before e the catch block for parent class exceptions for example, FileNotFoundException extends IOException, so the catch block for FileNotFoundException should come before the catch block for IOException.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Suppose I have a class A that has a method X which throws FileNotFoundException. I have a class B that extends class A and the method X is overridden in B. In the ovverriden method X in class B can I throw IOException?</font></span></strong></p> <p class="MsoNormal">A: No, because FileNotFoundException is a subclass if IOException and in the overridden method X in class B we can throw only FileNotFoundException or any other exception that extends FileNotFoundException.</p> <p class="MsoNormal"><strong><span style="COLOR: #c00000"><font color="#000000">Q: Is the above rule logical?</font></span></strong></p> <p class="MsoNormal">A: yes, the above rule is logical because java supports runtime polymorphism and at runtime an object of type B can be assigned to a variable of type A because B extends A, and when the method X is called on the variable of type A, the compile only check that the calling method should either catch or declare the exception that method X in class A is throwing, and if the method X in class B throws IOException, and the caller is handling only FileNotFoundException, then the exception will escape unhandled.</p> </font></div> </div> <pre></PRE><p style="font-family:arial;color:grey" style="font-size:13px">This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.</p><PRE> </pre>javapeoplenoreply@blogger.com2tag:blogger.com,1999:blog-18870537.post-11056995297256916472010-10-25T14:40:00.001+05:302010-10-25T14:40:45.661+05:30What are Java Comparators and Comparables?<div style="FONT-SIZE: 13px; COLOR: #000000; DIRECTION: ltr; FONT-FAMILY: Tahoma"> <div dir="ltr"><font face="Tahoma" color="#000000" size="2">As both names suggest (and you may have guessed), these are used for comparing objects in Java. Using these concepts; Java objects can be <br> sorted according to a predefined order.<br> <br> Two of these concepts can be explained as follows.<br> <h2 class="post-subtitle2"><font size="4">Comparable</font></h2> A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its instances.<br> <br> <h2 class="post-subtitle2"><font size="4">Comparator</font></h2> A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class's instances. This comparator class must implement the java.util.Comparator interface</font></div> </div> <pre></PRE><p style="font-family:arial;color:grey" style="font-size:13px">This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.</p><PRE> </pre>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-76593359744041514842010-10-25T14:18:00.001+05:302010-12-24T14:46:13.018+05:30Advantages of Hibernate<div style="FONT-SIZE: 13px; COLOR: #000000; DIRECTION: ltr; FONT-FAMILY: Tahoma"><br /><div dir="ltr"><span style="font-family:Tahoma;font-size:85%;color:#000000;"><div class="entry-content"><ul><li><strong>Caching objects.</strong> The session is a transaction-level cache of persistent objects. You may also enable a JVM-level/cluster cache to memory and/or local disk. </li></ul><ul><li><strong>Executing SQL statements later,</strong> when needed. The session never issues an INSERT or UPDATE until it is actually needed. So if an exception occurs and you need to abort the transaction, some statements will never actually be issued. Furthermore, this keeps lock times in the database as short as possible (from the late UPDATE to the transaction end). </li></ul><ul><li><strong>Never updating unmodified objects.</strong> It is very common in hand-coded <a class="answerlink" href="http://www.answers.com/topic/jdbc?nafid=22">JDBC</a> to see the persistent state of an object updated, just in case it changed…..for example, the user pressed the save button but may not have edited any fields. Hibernate always knows if an object's state <em>actually</em> changed, as long as you are inside the same (possibly very long) unit of work. </li></ul><ul><li><strong>Efficient Collection Handling.</strong> Likewise, Hibernate only ever inserts/updates/deletes collection rows that actually changed. </li></ul><ul><li><strong>Rolling two updates into one.</strong> As a <a class="answerlink" href="http://www.answers.com/topic/corollary?nafid=22">corollary</a> to (1) and (3), Hibernate can roll two seemingly unrelated updates of the same object into one UPDATE statement. </li></ul><ul><li><strong>Updating only the modified columns.</strong> Hibernate knows exactly which columns need updating and, if you choose, will update only those columns. </li></ul><ul><li><strong>Outer join fetching.</strong> Hibernate implements a very efficient outer-join fetching algorithm! In addition, you can use <em>subselect</em> and <em>batch</em> pre-fetch optimizations. </li></ul><ul><li><strong>Lazy collection initialization.</strong> </li></ul><ul><li><strong>Lazy object initialization.</strong> Hibernate can use runtime-generated proxies (CGLIB) or interception injected through bytecode instrumentation at build-time. </li></ul><p>A few more (optional) features of Hibernate that your handcoded JDBC may or may not currently benefit from</p><ul><li>second-level caching of arbitrary query results, from HQL, Criteria, and even native <a class="answerlink" href="http://www.answers.com/topic/sql?nafid=22">SQL</a> queries </li><li>efficient 'PreparedStatement' caching (Hibernate <em>always</em> uses 'PreparedStatement' for calls to the database) </li><li>JDBC 2 style batch updates </li><li>Pluggable connection pooling </span></li></ul></div></div></div>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-83591954441182127122010-10-24T14:57:00.001+05:302010-10-24T14:57:59.908+05:30Multiple Resource bundle in struts.<div class="gmail_quote">I had got one requirement from client as I had to implement multiple resource bundles and define same key in both bundle.<br> <br>Example –<br> <br>Say I have ApplicationResources.properties which has all global level messages defined and another module specific property file. If because of some reason the key didn't find in module specific file then System should display message from my global (ApplicationResources.properties) file.<br> <br>I struggled a lot to find solution for the same and finally I found one.<br> <br>Keep both properties files in class path.<br>updated struts-config.xml file as below<br> <br>&lt;message-resources parameter=&quot;Account,ApplicationResources&quot; null=&quot;false&quot; /&gt;<br> <br>Create CustomeActionServlet and CustomMessageResources.javause &lt;bean:message&gt; tag in the jsp to display text <br>And the message will be render from all files. Download here.. </div><br> javapeoplenoreply@blogger.com1tag:blogger.com,1999:blog-18870537.post-6141462918735745222009-07-23T19:16:00.003+05:302010-12-24T14:44:52.232+05:30How to find unused code in Eclipse<span style="font-family:arial;font-size:85%;">Its easy to find unused code using eclipse editor .The java compiler detects unreachable code, unused variables, parameters, imports and unused private types, methods and fields.<br />The setting is on the Java > Compiler preference page.</span><img id="BLOGGER_PHOTO_ID_5361655053054522450" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 281px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_e7A8Ag097L4/Smhs3Q1-NFI/AAAAAAAAADE/fGcim0nIAdo/s320/Eclipse-unused-Code.bmp" border="0" /><br /><br /><div></div>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-10257817349489154782009-07-23T19:14:00.001+05:302010-12-24T14:45:26.759+05:30C to Java converter<span style="font-family:arial;font-size:85%;">While browsing I found very cool tool which converts C code to java code. I know everybody would be things how?? Need to know how?? <a href="http://www.soften.ktu.lt/~stonis/c2java/index.html">Read more….</a></span>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-71544297967334893412009-07-23T18:56:00.002+05:302009-08-01T23:23:26.911+05:30How to create a ZIP File<span style="font-family:arial;font-size:85%;">Java tip illustrates a method of creating a ZIP file. ZIP is a universal format used by many applications to compress their files. By using this option developer may give their user an option of compressing their files in ZIP format. Read <a href="http://www.java-tips.org/java-se-tips/java.util.zip/how-to-create-a-zip-file.html">more on....</a></span>javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-77398601753584041562009-07-23T18:48:00.000+05:302009-07-23T18:53:57.706+05:30Top 10 Things Need to Know About Java SE 6<span style="font-family:arial;font-size:85%;">Version 6 of the Java Platform, Standard Edition (Java SE), was released for general availability in December 2006. So here are the top 10 things you need to know about the release, if you're still hovering hesitantly over<br />Web Services <br />Scripting<br />Database<br />More Desktop APIs<br />Monitoring and Management<br />Compiler Access<br />Pluggable Annotations<br />Desktop Deployment<br />Security<br />The -lities: Quality, Compatibility, Stability<br /> Know more about above point on </span><a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html"><span style="font-family:arial;font-size:85%;">link</span></a><span style="font-family:arial;font-size:85%;">….</span>javapeoplenoreply@blogger.com2tag:blogger.com,1999:blog-18870537.post-89636121085011196452009-06-07T22:37:00.002+05:302009-06-07T22:43:20.116+05:30The J2EE Architect's Handbook<span style="font-family:arial;">This book is written for technical architects and senior developers tasked with designing and leading the development of J2EE java applications. This book will guide the architect through the entire process of delivering a project from analysis through application deployment providing numerous tips, tricks, and “best practices” along the way.<br />It is available in ZIP format.<br /></span><a href="http://www.theserverside.com/tt/books/DVTPress/J2EEArchitectsHandbook/index.tss"><span style="font-family:arial;">Download..</span></a><span style="font-family:arial;"> </span>javapeoplenoreply@blogger.com3tag:blogger.com,1999:blog-18870537.post-16586911189724333392009-05-30T15:36:00.001+05:302009-05-30T15:40:35.433+05:30Coding Standards - Part IV<strong>Error and Exception Handling </strong><br /><br />Does the code avoid catching Exception (as opposed to more specific exception types)? <br />Does the code avoid throwing an explicit Exception object? <br /><br />Does the code avoid having empty catch blocks? <br /><br />Do methods check for null / empty arguments using Asserts in the Service Layer?<br />"E.g. <br /> public void identifyUnadjustableCharges(List<ChargesDetail> chargesDetails) {<br /> Assert.notNull(chargesDetails,""Charges detail cannot be null."");<br /> Assert.notEmpty(chargesDetails,""Charges detail cannot be empty."");"<br /><br />Does the code use logging instead of System.out.println() or Throwable.printStackTrace()? <br /><br />Are log types (fatal, error, warn, info, debug and trace) used appropriately? <br /> <br /><strong>Comment Rules </strong><br />Is the amount of commenting appropriate?<br />A good rule of thumb is a ratio of comments to code of about 20-25%.<br />Commenting just for the sake of commenting should be avoided.<br /><br />Are all date comments in the format YYYY/MM/DD? <br /><br />Are all class members commented except for getters/setters? <br /> <br /><strong>Unit Test</strong> <br /><br />Do test cases use meaningful Input combinations?<br />Include boundary conditions and invalid conditions. Null inputs has to be tested<br /><br />Do test cases adequately cover functionality?<br />Test should exercise most of branches.80% code coverage is a good rule-of-thumb. <br />Is every method tested?<br />Simple getters and setters can be exempted. <br /><br />Are all test cases independent of one another? <br /><br />Is all test code under test folder?javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-59931827155321447922009-05-30T15:34:00.000+05:302009-05-30T15:35:59.738+05:30Coding Standards - Part-III<strong>Hibernate</strong> <br />Does the DAO extend Spring's Hibernate DAO support class? <br /><br />Does the DAO methods throw Spring's DataAccessException?<br />Like All DAO methods should throw Spring DataAccessException. Also, declare the throw in the DAO interface.<br /><br />Does the Hibernate code generate n+1 queries for 1 to many queries?<br />i.e. If code fetchs parent class along with its childern, it should only issue one query. Verify by viewing the logs.<br /><br />Does the HQL uses named parameters?<br /><br />Does the collection mappings have lazy initialization set to true?<br />All collections should lazy initialized; Verify by looking at the logs.<br /> <br /><strong>Struts</strong> <br /><br />Does the code use duplicate form submission for POST operations?<br />use saveToken and isTokenMethod in the action class<br /><br />Does the name of the action class conform with the naming conventions? <br /><br />Does the action class contain business logic?<br />Verify that most of the code is for page flow, validation, object conversion etc.<br /><br />Is the action scope set to "request" in the mapping? <br /> <br /><strong>JSP</strong><br /><br />Are labels and texts externalize to properties files? <br /><br />Does the code use JSTL?<br />Majority of the code should be written in JSLT. <br /><br />Are the html tages lower case?<br />All html tags should be lower case.<br /><br />JSP's that will be used for AJAX should not contain the HEAD and BODY tags.javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-4223930587060937452009-05-30T15:30:00.000+05:302009-05-30T15:31:44.330+05:30Coding Standards - Part II<strong>Naming: (mostly covered by checkstyle)</strong> <br /><br />Are class, variable, and method names descriptive?<br />Like Other than following naming convention, all names should be descriptive<br /><strong><br />Coding Standard </strong><br /><br />Is the code self-descriptive and easily understood?<br />Like Code should be self-descriptive and logically paragraphed.If a reviewer can not get general idea of a method in 30 seconds,<br />either the design or the comments should be updated<br /> <br />Does the code use if/else for mutually exclusive conditions rather than if/if?<br />like avoid using flat if while nested conditionals are more accurate<br /><br />When comparing a constant with a variable, is the constant's equals() method used?<br />like Avoid null object reference<br /><br />Are static final String constants used instead of string literals? <br /><br />Is StringBuilder used instead of appending Strings? <br /><br />Is StringBuilder used instead of StringBuffer? <br /><br />Are JDK 1.5 enhanced for loops used instead of using index on collections? <br /><br />Does the code use equals() instead of comparing references (==||!=)? <br /><br />Does the code check instanceof before a casting? <br /><br />Does the code check for null before accessing an object? <br /><br />Does the code use Spring for resource access? <br /><br />Are variables declared using an interface when available rather than a class? <br /><br />Does the code avoid making assignments to loop iterator variables?<br /><br />Assignment to loop variable makes the code difficult to read and maintain<br /><br />Does the code avoid using unnecessary return statements? <br /><br />Will all loops terminate whether or not an exception occurs?javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-88149343519016175242009-05-28T21:03:00.005+05:302009-05-30T15:56:29.954+05:30Coding Standards - Part ISome of you would be thinking why do need coding Standards. As a developer, I would like to highlight few points which will definatly convince every developer why we need to follow coding Standards. <br /> The best applications are coded properly. This sounds like an obvious statement, but by 'properly', I mean that the code not only does its job well, but is also easy to add to, maintain and debug. <br /><br /><strong>Why do need coding Standards?</strong><br />1)80% of the lifetime cost of a piece of software goes to maintenance. <br />2)Hardly any software is maintained for its whole life by the original author. <br />etc etc...<br /> Code conventions/Standards improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. <br /><br />1)Coding standards are great -- but how do you decide which standards you want to apply, and how they will be defined? When you formulate your ideal coding style, you should think about these points<br /><br />2)Can you actually read the code? Is it spaced out clearly?<br /><br />3)Do you separate blocks of code into 'paragraphs' so that different sections are <br /> easily defined? <br /><br />4)Are you using indentation to show where control structures (if, else, while and <br /> other loops) begin and end, and where the code within them is? <br /><br />5)Are your variable naming conventions consistent throughout the code and do they <br /> briefly describe that data that they'll contain? <br /><br />6)Are functions named in accordance with what they do? <br /><br />7)If you come back to the code in a few weeks or months, will you be able to work <br /> out what's happening without needing to look at every line?<br /><br />8)How are you commenting the work?<br /><br />9)Have you used complex language functions/constructs that are quicker to write but <br /> affect readability?javapeoplenoreply@blogger.com0tag:blogger.com,1999:blog-18870537.post-69252051546077197812009-05-10T15:41:00.004+05:302009-05-28T20:59:41.477+05:30Improving code quality with Eclipse plugins (Check-Style and PMD))<span style="font-family:arial;font-size:85%;">One of my primary goals when developing software is either preventing a defect from being introduced into a code base or limiting its lifetime; in other words, I try to find defects as early as possible. Obviously, the more I learn about how to write better code and learn how to effectively test software, the better I am at catching defects. But, I also like to have a safety net that can find potential defects. To achieve this we have lots of plug-in available on the Internet. I would suggest to used PMD as i found this is one of the most useful tool to improve the code quality as well as Its very easy to install. The plug-in which I found on Internet is check-Style, This is also one of the best tool I have ever used. Other than PMD and check-Style there lot other plug-in available, please find details for few as below<br /><a name="N100C3"></a><br />Table 1. List of code improvement plugins and installation URLs<br /><strong>CheckStyle :</strong> Coding standard analysis - <a href="http://eclipse-cs.sourceforge.net/update/">http://eclipse-cs.sourceforge.net/update/</a><br /><strong>Coverlipse :</strong> Test code coverage - <a href="http://coverlipse.sf.net/update">http://coverlipse.sf.net/update</a><br /><strong>CPD</strong> :Copy/Paste detection - <a href="http://pmd.sourceforge.net/eclipse/">http://pmd.sourceforge.net/eclipse/</a><br /><strong>JDepend:</strong> Package dependency analysis - <a href="http://andrei.gmxhome.de/eclipse/">http://andrei.gmxhome.de/eclipse/</a><br /><strong>PMD</strong> Coding standard analysis - <a title="http://pmd.sourceforge.net/" href="http://pmd.sourceforge.net/">http://pmd.sourceforge.net/</a></span>javapeoplenoreply@blogger.com2tag:blogger.com,1999:blog-18870537.post-63708529785635624512009-05-01T13:30:00.002+05:302009-05-01T16:07:49.302+05:30REST vs SOAP Webservices<div align="justify"><span style="font-family:arial;font-size:85%;">After long time I am updating my blog since, I was very busy with my new project. Today I got some free time so thought I will update my blog with technology which I am using in my project. this time I am working on RESTful webservices ...ummm I know what next is coming in your mind..... what is RESTFul webservice and how its different from the the SOAP right ??? so here we go......</span></div><div align="justify"><span style="font-family:arial;"><span style="font-size:85%;"><strong>REST -</strong> stands for "Representational State Transfer", this basically means that each unique URL is a representation of some object. You can get the contents of that object using an HTTP GET, to delete it, you then might use a POST, PUT, or DELETE to modify the object (in practice most of the services use a POST for this).</span></span></div><div align="justify"><span style="font-family:arial;"><span style="font-size:85%;"><strong>SOAP -</strong> stands for "Simple Object Access Protocol" was designed to be a platform and language-neutral alternative to previous middleware techologies like </span></span><a href="http://www.omg.org/docs/formal/04-03-12.pdf"><span style="font-family:arial;font-size:85%;">CORBA</span></a><span style="font-family:arial;font-size:85%;"> and DCOM</span></div><div align="justify"><span style="font-family:Arial;font-size:85%;"><strong>Pros and cons of SOAP </strong></span></div><div align="justify"><strong><span style="font-family:Arial;font-size:85%;">Pros :</span></strong></div><ul><li><div align="justify"><span style="font-family:arial;font-size:85%;">Langauge, platform, and transport agnostic </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Designed to handle distributed computing environments</span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors Built-in error handling (faults) Extensibility </span></div></li></ul><div align="justify"><span style="font-size:85%;"><strong>Cons:</strong> </span></div><ul><li><div align="justify"><span style="font-family:arial;font-size:85%;">Conceptually more difficult, </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">more "heavy-weight" than REST </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">More verbose Harder to develop, requires tools </span></div></li></ul><div align="justify"><strong><span style="font-family:Arial;font-size:85%;"></span></strong></div><div align="justify"><span style="font-family:Arial;font-size:85%;"></span></div><div align="justify"><span style="font-family:Arial;font-size:85%;"></span></div><div align="justify"><span style="font-family:Arial;font-size:85%;"><strong>Pros and cons of REST</strong></span></div><div align="justify"><strong><span style="font-family:Arial;font-size:85%;">Pros:</span></strong></div><ul><li><div align="justify"><span style="font-family:arial;font-size:85%;">Language and platform agnostic </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Much simpler to develop than SOAP </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Small learning curve, less reliance on tools </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Concise, no need for additional messaging layer </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Closer in design and philosophy to the Web </span></div></li></ul><div align="justify"><strong><span style="font-family:arial;font-size:85%;">Cons :</span></strong></div><ul><li><div align="justify"><span style="font-family:arial;font-size:85%;">Assumes a point-to-point communication model</span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Generaly not usable for distributed computing environment where message may go through one or more intermediaries </span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Lack of standards support for security, policy, reliable messaging, etc.</span></div></li><li><div align="justify"><span style="font-family:arial;font-size:85%;">Services that have more sophisticated requirements are harder to develop ("roll your own") Tied to the HTTP transport model</span> </div></li></ul>javapeoplenoreply@blogger.com2tag:blogger.com,1999:blog-18870537.post-12124189632327003362008-09-22T09:58:00.002+05:302008-09-22T10:03:13.520+05:30Hibernate Vs JDBC<span style="font-family:arial;font-size:85%;">Following link has very good explanation about hibernate and JDBC as well as it explains difference between hibernate and JDBC.</span><br /><a href="http://www.mindfiresolutions.com/mindfire/Java_Hibernate_JDBC.pdf"><span style="font-family:arial;font-size:85%;">http://www.mindfiresolutions.com/mindfire/Java_Hibernate_JDBC.pdf</span></a>javapeoplenoreply@blogger.com0