Skip to main content

Posts

Log4j - Email errors using Gmail

Most of the small projects doesn't have a dedicated person to monitor log file all the times, and its handy to send these errors as email to an email list. Pros Never miss an error. Delete Emails which you want to ignore because of invalid inputs or connectivity issues etc. Proactively identify bugs and fix them. Email list is handy i.e. multiple person can receive emails. If you have different modules in your project and different teams work on them, adding a Labels to your log can by handy since most of the Email Servers can Label emails and redirect them to different folders. Cons    Sending email from code takes few seconds, workaround is the create Logger wrapper which logs in a separate thread. log4j.properties log4j.rootLogger=ERROR, gmail log4j.appender.gmail=org.apache.log4j.net.SMTPAppender log4j.appender.gmail.SMTPProtocol=smtps log4j.appender.gmail.SMTPUsername=username@gmail.com log4j.appender.gmail.SMTPPassword=password log4j.appen...

Data Types in Java

Session 1 - Data Types in Java What is Data ?  Most of you have shopped online and this is what a typical purchase looks like     You select a product which has a Price, Tax, Quantity     You pay using your Credit Card by entering Name, CC Number, Expiration Date, Billing    Address, Zipcode Words above in Bold are data. What is then Data Type ?    Can we say  Price, Tax, Quantity  is of type Number because we can apply Arithmetic (+, -, /, *, %) Operations on them, i.e. we multiply Price &  Quantity and than add Tax . Similarly Your Name, Address are text because it doesn't make sense to have Arithmetic Operation on them and in Java we call them String. Supported Data Types in Java   String   -  Text   double  - Real Numbers i.e. 33.2, 20.0 etc   int         - Non-Real Numbers i.e. 10, 30, 3453 etc Typical Java Programs using the above Data Types ...

How I teach Java in 1hr 5 sessions

I know a lot of people can disagree with this but I am trying to keep it simple and as only my own opinion. It took me more than 5 yrs to design this syllabus to help beginners learn and get motivated to program in Java. When I started teaching I use to take 10-15 days to teach java and I can clearly see on participants faces that they were not confident even after spending so much time with them. However recently I was able to successfully use a shorter And I am sure this won't be the final one and it will change a lot after few more batches. And the only way I do this is by focusing on important concepts and cutting dumb one's in a language to accomplish my objectives. Session 1   Data Types (int, double, String )   Class Notes   Operators (Arithmatic - +,-,*,/ )   Functions   Homework -  Write 50 functions and execute them from main method              Write functions with 0 or more input parameters ...

How to Schema Validate Metro SOAP Request

@SchemaValidation does the trick checkout the sample code below package com.palm.appstore.wsc; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.WebParam; import com.sun.xml.ws.developer.SchemaValidation; /** * * @author Intesar Mohammed */ @WebService(serviceName = "Echo") @SchemaValidation public class Echo {     /** This is a sample web service operation */     @WebMethod(operationName = "hello")     public String hello(@WebParam(name = "no") int txt) {         return "Hello " + txt + " !";     } } Valid Request <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsc="http://wsc.appstore.palm.com/">    <soapenv:Header/>    <soapenv:Body>       <wsc:hello>          <no>33</no>       </wsc:hello>    </soapenv:Body...

Enterprise Application's Logical Layers and where to manage Transactions

Recently I came across an application which manage transaction's at Dao layer that means there is no proper transaction management and if an exception occurs during runtime will leave inappropriate data in database. Consider this simple Architectural layers Brief description of each block starting from the bottom. DB1 .. DBn → Databases, an application sometimes refers to multiple databases and simple application has one. Dao Layer →  Encapsulates logic to add, update, delete and read data from Databases using JPA, Hibernate or JDBC. Entity/Dto → Simple Pojo classes which encapsulate database entities WebServices Client → Another Integration Layers like Dao which communicates with other systems via SOAP, JMS etc. Service Layer → This layer contains business logic which encapsulate the data (Dao & Webservices client) they operate on and provide hardened interfaces as the only way to access their functionality. This approach reduces side effects and allows...

Reverse Engineer UML from Maven project

I am a Netbeans user and after they discontinued UML plugin I started looking at other options which will work with my Maven projects and found this open source tool UMLGraph which does a good job but only lacks in proper documentation. Good thing about this tool is, It works as a Maven plugin so all my UML gets automatically updated with any changes to code. Setup is very straight forward and takes less then a minute. Step 1 Install   Graphviz     Is an open source graph visualization software.    Note : Only install in a non-space directory (i.e "Program Files" won't work)    Website :  http://www.graphviz.org/    Download link :  Windows download Step 2     http://www.umlgraph.org/  Is the Maven plugin which does the job        Setup UMLGraph plugin to your pom.xml      <project>    ..      <build> ...

Simple Reverse Lookup Enum in Java

Documentation inline with the code. import java.util.EnumSet; import java.util.HashMap; import java.util.Map; /**  *  * @author Intesar Mohammed  *  *  Reverse Enum Lookup example using Map and EnumSet  */ public enum Status {      WAITING(0),     READY(1),     SKIPPED(-1),     COMPLETED(5);        /**     *    code or your required variable can be of any type     */       private int code;     private Status(int code) {         this.code = code;     }        private static final Map<Integer, Status> lookup =                    new HashMap<Integer, Status>();        /**      * Stores all Enum's ...