Java

Java is a set of computer software and specifications developed by Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers.

Spring Logo

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Hibernate Logo

Hibernate Framework

Hibernate ORM is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Sunday, March 16, 2014

java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException

Problem: The problem is we are missing to add the Spring Transaction jar file to class path.

Solution: Add the spring-tx- x.x.RELEASE.jar to the class path. here x.x is spring current version you are using.

Thursday, February 20, 2014

Case Insensitive Sorting Example in Oracle11g


Step1: Create Employee table 
create table employee(id int, name varchar(20));
 
Step2: Insert values to Employee table
insert into employee values(1,'Ranga');
insert into employee values(2,'rAnga Reddy');
insert into employee values(3,'Raja');
insert into employee values(4,'raJa Reddy');
insert into employee values(5,'raja');
insert into employee values(6,'Reddy');
insert into employee values(7,'ranga');
 
Step3: Select the Employee values with out sorting
select * from employee;
------------------------------------------- 
ID NAME
1 Ranga
2 rAnga Reddy
3 Raja
4 raJa Reddy
5 raja
6 Reddy
7 ranga
 
Step4: Select the Employee values with sorting 
select * from employee order by name;
------------------------------------------- 
ID NAME
3 Raja
1 Ranga
6 Reddy
2 rAnga Reddy
4 raJa Reddy
7 ranga
5 raja

 
Step5: Select the Employee values with case insensitive sorting 
select * from employee order by upper(name);
------------------------------------------- 
ID NAME
5 raja
3 Raja
4 raJa Reddy
7 ranga
1 Ranga
2 rAnga Reddy
6 Reddy
 
Click here to Run and Test the above example in online.


Friday, February 14, 2014

Formatting source code on Blogger


The following are the few sites to format a source code on blogger.
  1. http://hilite.me/
  2. http://formatmysourcecode.blogspot.in/
  3. http://markup.su/highlighter/

Java program to check if number is Armstrong or not.


/**
* @file : ArmstrongExample.java
* @description :
*/

/**
A number is called as ARMSTRONG number if,sum of cube of every digit present in the number is equal
to the number itself then that number is called as armstrong number.For example the 153 is a armstrong
number because 1^3 + 5^3 + 3^3 =153. 
 
Some of the Armstrong number are 0, 1, 153, 370, 371, 407
 
*/

package com.ranga.collections;

import java.util.Scanner;

/**
* Java program to check if number is Armstrong or not.
* @author: ranga
* @date: Feb 13, 2014
*/
public class ArmstrongExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Number: ");
int num = scanner.nextInt();
boolean isArmstrong = isArmstrong(num);
if(isArmstrong) {
System.out.println(num +" is Armstrong");
} else {
System.out.println(num +" not Armstrong");
}
}
private static boolean isArmstrong(int num) {
int number = num;
int sum = 0;
do {
int den = num % 10;
sum = den * den * den + sum;
num = num / 10;
} while(num != 0);

if(number == sum) {
return true;
}
return false;
}
} 
 
Output: 
Enter Number: 
141
141 not Armstrong

Enter Number: 
153
153 is Armstrong


Explanation:
Assume Number is 153
 
Step1: 
 
Initially
number = 153
sum = 0

after entering while loop

den = 153 % 10 = 3
sum = 3 * 3 * 3 + 0(sum) = 27
num = 153 / 10 = 15
 
next do while check the do while condition i.e num != 0 = 15 != 0 = true

Step2:

Now sum = 27
    num = 15
 
den = 15 % 10 = 5
sum = 5 * 5 * 5 + 27(sum) = 125 + 27 = 152
num = 15 / 10 = 1
 
next it will check condition i.e num != 0 = 1 != 0 = true
 
Step3:
 
Now sum = 152
    num = 1
 den = 1 % 10 = 1
 sum = 1 * 1 * 1 + 152(sum) = 1 + 152 = 153
 num = 1 / 10 = 0
next it will check do while condition i.e num != 0 = 0 != 0 = false
 
Now program exits the while loop...
 
then we are comparing the number == sum i.e 153 == 153
 
 
 

Sunday, February 2, 2014

New Features in Spring Framework 4.0:

New Features in Spring Framework 4.0:

The Spring 4.0 is the latest major release of Spring framework which the support for Java 8, JEE 7, REST WebServices and HTML 5 supports.
  • Removed Deprecated Packages and Methods - In Spring Framework 4.0 all deprecated packages, classes and methods have been removed.
  • Java 8 support - Spring Framework 4.0 provides support for several Java 8 features such as expression of callbacks using lambdas, JSR 310 Date and Time API, and parameter name discovery.
    • Auto-wiring based on generic types.
    • @Description annotation has been added.
    • @Conditional annotation is introduced that can conditionally filter the beans.
    • @Ordered annotation and Ordered interface are supported for ordering the Beans.
    • Now programmers can write custom annotations that expose specific attributes from the source annotation.
    • The @Lazy annotation can now be used on injection points, as well as on @Bean definitions.
    • CGLIB-based proxy classes no longer require a default constructor. Support is provided via the objenesis library which is repackaged inline and distributed as part of the Spring Framework. With this strategy, no constructor at all is being invoked for proxy instances anymore.
  • General Web Improvements - The following general improvements have been made to Spring’s Web modules:
  • WebSocket, SockJS, and STOMP Messaging
    • A new spring-websocket module provides comprehensive support for WebSocket-based, two-way communication between client and server in web applications. It is compatible with JSR-356, the Java WebSocket API, and in addition provides SockJS-based fallback options (i.e. WebSocket emulation).
    • A new spring-messaging module adds support for STOMP as the WebSocket subprotocol to use in applications along with an annotation programming model for routing and processing STOMP messages from WebSocket clients. As a result an @Controller can now contain both @RequestMapping and @MessageMapping methods for handling HTTP requests and messages from WebSocket-connected clients.
  • Testing Improvements -
    • Almost all annotations in the spring-test module (e.g., @ContextConfiguration, @WebAppConfiguration, @ContextHierarchy, @ActiveProfiles, etc.) can now be used as meta-annotations to create custom composed annotations and reduce configuration duplication across a test suite.
    • Active bean definition profiles can now be resolved programmatically, simply by implementing a custom ActiveProfilesResolver and registering it via the resolver attribute of @ActiveProfiles.