Monday, May 21, 2012

Difference between Java SE/EE/ME?

JavaSE = Standard Edition. This is the core Java programming platform. It contains all of the libraries and APIs that any Java programmer should learn (java.lang, java.io, java.math, java.net, java.util, etc...).
JavaEE = Enterprise Edition. From wikipedia: "The Java platform (Enterprise Edition) differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular components running on an application server." In other words, if your application demands a very large scale, distributed system, then you should consider using JavaEE. Built on top of JavaSE, it provides libraries for database access (JDBC, JPA), remote method invocation (RMI), messaging (JSM), web services, XML processing, and defines standard APIs for Enterprise JavaBeans, servlets, portlets, JavaServer Pages, etc...
JavaME = Micro Edition. This is the platform for developing applications for mobile devices and embedded systems such as set-top boxes. JavaME provides a subset of the functionality of JavaSE, but also introduces libraries specific to mobile devices. Because JavaME is based on an earlier version of JavaSE, some of the new language features introduced in Java 1.5 (eg. generics) are not available.
If you are new to Java, definitely start with JavaSE.
I would also recommend using Eclipse instead of Komodo IDE, since this is the most widely used editor within the industry. Because it has built in support for Java, you will benefit from all the usual advantages of using an IDE: code assist, syntax highlighting, auto compile, etc...
Good luck!

http://stackoverflow.com/questions/2857376/difference-between-java-se-ee-me

Saturday, May 19, 2012

Thursday, May 17, 2012

Can’t start Mysql error 1067

If you install under windows system, sometime it will suddenly unable to start the service,
i face this issue quite a few times already, finally i found a solution for it,
1st step check the error, under your installation path for mysql, check the data/mysql.err, it the error showing you something like this ..
050213 20:43:37 InnoDB: Starting shutdown…
050213 20:43:40 InnoDB: Shutdown completed; log sequence number 0 1051715
050213 20:43:40 [Note] C:Webmysqlbinmysqld-nt: Shutdown complete
this should be the log file having problem !
2nd step remove the ib_logfile0 or ib_logfile1 in the same folder
3rd step restart the mysql …
da da da … mysql service is running again

http://imknight.net/development/cant-start-mysql-error-1067/

Sunday, May 13, 2012

Difference between commit and flush in Hibernate

Commit will make the database commit
- Flushing is the process of synchronizing the underlying persistent
store with persistable state held in memory.
ie. it will update or insert into your tables in the running
transaction, but it _may_ not commit those changes (this depends on
your flush mode). When you have a persisted object and you change a
value on it, it becomes dirty and hibernate needs to flush these
changes to your persistence layer. It may do this automatically for
you or you may need to do this manually, that depends on your flush
mode, check http://www.hibernate.org/hib_docs/v3/api/org/hibernate/FlushMode.html
for further details on which flush mode is the right one for you.

http://www.coderanch.com/t/218534/ORM/java/Difference-between-commit-flush-Hibernate

How does Hibernate detect dirty state of an entity object?

Hibernate uses a strategy called inspection, which is basically this: when an object is loaded from the database a snapshot of it is kept in memory. When the session is flushed Hibernate compares the stored snapshot with the current state. If they differ the object is marked as dirty and a suitable SQL command is enqueued. If the object is still transient then it is always dirty.
Source: book Hibernate in Action (appendix B: ORM implementation strategies)
It's important to notice however that Hibernate's dirty-checking is independent of the methods equals/hascode. Hibernate does not look at these methods at all (except when using java.util.Set's, but this is unrelated to dirty-checking, only to the Collections API) The state snapshot I mentioned earlier is something similar to an array of values. It would be a very bad decision to leave such a core aspect of the framework in the hands of developers (to be honest, developers should not care about dirty-checking). Needless to say that equals/hascode can be implemented in many ways according to your needs. I recommend you to read the cited book, there the author discuss equals/hascode implementation strategies. Very insightful reading.
EDIT: fixed typos
http://stackoverflow.com/questions/5268466/how-does-hibernate-detect-dirty-state-of-an-entity-object

Saturday, May 12, 2012

Using Command Design pattern

public interface Command {
   public void execute();
}
For the most part, commands are immutable and contain instructions that encapsulate a single action that is executed on demand. You might also have a RuntimeCommand that accepts instructions upon execution, but this delves more into the Strategy or Decorator Patterns depending on the implementations.
In my own opinion, I think it's very important to heed the immutable context of a command otherwise the command becomes a suggestion. For instance:
public final class StopServerCommand implements Command {
    private final Server server;

    public StopServerCommand(Server server) { this.server = server; }

    public void execute() {
        if(server.isRunning()) server.stop();
    }
}
public class Application {
    //...
    public void someMethod() {
        stopButton.addActionListener(new ActionListener() {
            public void actionPerformed(Event e) {
                 stopCommand.execute();
            }
        });
    }
}
I personally don't really like commands. In my own experience, they only work well for framework callbacks.
If it helps, think of a command in a metaphorical sense; a trained soldier is given a command by his/her commanding officer, and on demand the soldier executes this command.
http://stackoverflow.com/questions/2015549/using-command-design-pattern

Factory Pattern. When to use factory methods?


I like thinking about design pattens in terms of my classes being 'people,' and the patterns are the ways that the people talk to each other.
So, to me the factory pattern is like a hiring agency. You've got someone that will need a variable number of workers. This person may know some info they need in the people they hire, but that's it.
So, when they need a new employee, they call the hiring agency and tell them what they need. Now, to actually hire someone, you need to know a lot of stuff - benefits, eligibility verification, etc. But the person hiring doesn't need to know any of this - the hiring agency handles all of that.
In the same way, using a Factory allows the consumer to create new objects without having to know the details of how they're created, or what their dependencies are - they only have to give the information they actually want.
public interface IThingFactory
{
    Thing GetThing(string theString);
}

public class ThingFactory : IThingFactory
{
    public Thing GetThing(string theString)
    {
        return new Thing(theString, firstDependency, secondDependency);
    }
}
So, now the consumer of the ThingFactory can get a Thing, without having to know about the dependencies of the Thing, except for the string data that comes from the consumer.
http://stackoverflow.com/questions/69849/factory-pattern-when-to-use-factory-methods