Skip to main content

Posts

Hibernate Notes

  The Hibernate project has the structure as shown in the figure as above. We need one hibernate.cfg.xml file for hibernate configuration which handles connection pulling and other stuff like driver name, username of the database, password of the database, and the following properties.. Hibernate.cfg.xml <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory>   <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver</property>   <property name="hibernate.connection.url"> jdbc:mysql://localhost/hibernatetutorial </property>   <property name="hibernate.connection.username"> root </property>   <property name="hibernate.connection.password"></pr...

Dependency Injection (DI)

The first reference to what would eventually become Dependency Injection appeared in 1994 in a paper by Robert C. Martin called "The Dependency Inversion Principle". In "The Dependency Inversion Principle" (or DIP ), the author states the three defining factors of "bad code": It is hard to change because every change affects too many other parts of the system (Rigidity) When you make a change, unexpected parts of the system break (Fragility) It is hard to reuse in another application because it cannot be disentangled from the current application (Immobility) According to Martin, interdependency causes these coding problems (we'll call them RFI for Rigidity, Fragility, and Immobility). To fix RFI issues in your OO code, DIP has two basic rules:   1. High level modules should not depend upon low level modules, both should depend upon abstractions. In other words, high level modules – which contain your business logic and all of the important meat of your...

Spring Light weighted Framework

Strategies Loose coupling with dependency injection Declarative programming with AOP Boilerplate reduction with templates Minimally invasive and POJO-oriented Spring Keywords Spring Web Flow BlazeDS Integration Spring-WS Spring Security Spring-DM DmServer Bundlor TcServer Spring Batch Spring Integration Spring LDAP Spring IDE / STS Spring Rich Client Spring .NET Spring BeanDoc Groovy/Grails

MVC Design Patterns

Context MVC is an architectural pattern that is used when developing interactive application such as a shopping cart on the Internet. Problem User interfaces change often, especially on the internet where look-and-feel is a competitive issue. Also, the same information is presented in different ways. The core business logic and data is stable . Solution Use the concept of dividing the concerns to divide the application into three areas Model :- Encapsulates the core data and the functionality View :- Encapsulates the presentation of the data there can be many views of the common data Controller:- accepts input from the user and makes request from the model for the data to produce a new view The model represents the structure of the data and the operations that can be performed on that data. The view represents the data that is in a presentable format. The controller translates the user action like mouse events, submit, keystrokes, words spoken with user input to call the call t...

Variable arguments

You can use a construct called  varargs  to pass an arbitrary number of values to a method. You will most commonly see varargs with the printing methods; for example, this printf method: public PrintStream printf(String format, Object... args)   allows you to print an arbitrary number of objects. It can be called like this: System.out.printf("%s: %d, %s%n", name, idnum, address);   or like this System.out.printf("%s: %d, %s, %s, %s%n", name, idnum, address, phone, mail); or with yet a different number of arguments.  

Overloading of Methods

The Java programming language supports  overloading  methods, and Java can distinguish between methods with different  method signatures . This means that methods within a class can have the same name if they have different parameter lists You cannot declare more than one method with the same name and the same number and type of arguments, because the compiler cannot tell them apart. The compiler does not consider return type when differentiating methods, so you cannot declare two methods with the same signature even if they have a different return type.   Note:   Overloaded methods should be used sparingly, as they can make code much less readable.  

Copying arrays using System class method

The  System  class has an  arraycopy  method that you can use to efficiently copy data from one array into another: public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) The two  Object  arguments specify the array to copy  from  and the array to copy  to . The three  int  arguments specify the starting position in the source array, the starting position in the destination array, and the number of array elements to copy. The following program,  ArrayCopyDemo , declares an array of  char  elements, spelling the word "decaffeinated". It uses  arraycopy  to copy a subsequence of array components into a second array:   class ArrayCopyDemo { public static void main(String[] args) { char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',              'i',...