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, April 14, 2013

How to Install Oracle 11g XE on Linux Fedora 17/18


Installing Oracle Database 11g XE on Fedora 17/18

[Oracle 11g Logo]

The following are the steps to install a Oracle 11g in fedora.

Step1:  Downloading the Software

Download the oracle-xe-11.2.0-1.0.x86_64.rpm.zip file from follwing url

Step2: Extracting the content

Extract the zip into any location. Here i am extracting the above zip into following location.

[ranga@ranga Disk1]$ pwd

/home/ranga/install/Disk1
[ranga@ranga Disk1]$ ls
oracle-xe-11.2.0-1.0.x86_64.rpm  response  upgrade
[ranga@ranga Disk1]$ 

Step3: Install libaio

[root@ranga Disk1]#  yum install libaio

Step4: Installing the oracle by using rpm command.

[root@ranga Disk1]# rpm -i oracle-xe-11.2.0-1.0.x86_64.rpm
Preparing... ########################################### [100%] 1:oracle-xe ########################################### [100%] Executing post-install steps... You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.

Your installation done but u need configure

Step5: Configuring the database

[root@ranga Disk1]# /etc/init.d/oracle-xe configure

Oracle Database 11g Express Edition Configuration ------------------------------------------------- This will configure on-boot properties of Oracle Database 11g Express Edition. The following questions will determine whether the database should be starting upon system boot, the ports it will use, and the passwords that will be used for database accounts. Press <enter> to accept the defaults. Ctrl-C will abort. Specify the HTTP port that will be used for Oracle Application Express [8080]: 9090 Specify a port that will be used for the database listener [1521]: Specify a password to be used for database accounts. Note that the same password will be used for SYS and SYSTEM. Oracle recommends the use of different passwords for each database account. This can be done after initial configuration: Confirm the password: Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y Starting Oracle Net Listener...Done Configuring database...Done Starting Oracle Database 11g Express Edition instance...Done Installation completed successfully.

In the above configuration, i am given port number is 9090 by default 8080 and database listener is same and you need to enter SYS or SYSTEM password. If you want while booting it self starting the database your giving 'y' in boot option. Finaly your database configured successfully. This installation created under /u01 directory. 

Starting the Database manually : 


To start the database manually, run this command as root user:
# /etc/init.d/oracle-xe start
or
# /usr/lib/oracle/xe/app/oracle/product/11.2.0/server/bin/lsnrctl start

Stopping the Database manually:
To stop the database manually, run the following command as root user:
# /etc/init.d/oracle-xe stop

Un Install the Oracle 11g: 

Step1: First you need to check which oracle version is installed.
[ranga@ranga ~]$ rpm -qa | grep oracle
oracle-xe-11.2.0-1.0.x86_64
Step2: Uninstall the oracle by using rpm -e with which version it is installed.
[ranga@ranga ~]$ rpm -e 
oracle-xe-11.2.0-1.0.x86_64

Thursday, March 28, 2013

Setting the Classpath in Intellij IDEA

Setting the Classpath in Intellij IDEA:
Way1 :
  1. Open Project Structure (either Ctrl+Alt+Shift+S or File > Project Structure)
  2. Select "Modules" on the far left under Project Settings
  3. Select the module in question in the middle pane
  4. Arrange the order of the dependencies lists. One of the dependencies will be <Module Source> Which ever is listed first will be the one IDEA will give preference to. So if you want the local instance of Foo to be used, make sure <Module Source> is above the dependency.
screenshot.png
Way2:
  1. Right click on any directory in your IntelliJ project, select "Mark Directory As...", and choose "Source Root". 
  2. That director folder will change color from yellow to blue; IntelliJ considers all those directories to be in your CLASSPATH.

Friday, December 28, 2012

Encode and Decode Example in Java

This post demonstrates the how to encode and decode the String data.

package com.ranga;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
* This class is used to encode and decode the string data.
* @author Ranga Reddy
* @version 1.0
*/

public class EncodeAndDecodeExample {
private static final String data = "Hello, I am Ranga Reddy. ";

public static void main(String[] args) {

String encodedData = getEncodedData(data);
System.out.println("Encoded Data: " + encodedData);

String decodedData = getDecondedData(encodedData);
System.out.println("Decoded Data: " + decodedData);
}

private static String getDecondedData(String encodedData) {
try {
return URLDecoder.decode(encodedData, "UTF-8");
} catch (UnsupportedEncodingException exception) {
throw new RuntimeException("Does not support UTF-8");
}
}

private static String getEncodedData(String data) {
try {
return URLEncoder.encode(data, "UTF-8");

} catch (UnsupportedEncodingException exception) {
throw new RuntimeException("Does not support UTF-8");
}
}
}

Output:
Encoded Data: Hello%2C+I+am+Ranga+Reddy.+
Decoded Data: Hello, I am Ranga Reddy.

Saturday, October 27, 2012

Spring MVC Hello World Example

In this post, we are going to see how to implement Spring MVC HelloWorld example.
Step 1:
The initial step is to create Dynamic Web Project in eclipse. To create a new Dynamic project in Eclipse IDE select File -> Dynamic Web Project.
Step 2:
After that New Dynamic Project Window will appear on the screen and you will enter the web application name in the Project name text box. Enter SpringHelloWorld in the Project Name and then click Next button.

Step 3:
Add Spring Web MVC jar files.
spring-webmvc.jar
spring.jar
commons-logging.jar
Step 4:
Now we will created a index.jsp in project's WebContent  folder. In the jsp file we will create a new hyperlink "Click Here" that will be linked to hello.do page.  The code of index.jsp is:
index.jsp

<html>
<head>
<title>Spring Demo</title>
</head>
<body>
<a href="hello.do">Click Here</a>
</body>
</html>
Step 5:
Now we will configure the DispatcherServlet in web.xml file. The DispatcherServlet will be configured to process all the request ending with *.do
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SpringHelloWorld</display-name>
<description>Hello world Application</description>
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Step 6:
Now we will create a new xml file called controller-servlet.xml in the WEB-INF folder of the web application. This is the main configuration file for the Spring MVC.
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
Then we will define the url mapping with the Controller bean as shown below:

<property name="mappings">
<props>
<prop key="/hello.do">helloController</prop>
</props>
</property>
Finally we will define the Controller bean as shown below:
<bean id="helloController" class="com.ranga.HelloWorld"> </bean>
controller-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.do">helloController</prop>
</props>
</property>
</bean>
<bean id="helloController" class="com.ranga.HelloWorld" />
</beans>
Step 7:
After that we will creates the controller class in the project src folder. This will be used as the controller for the hello.jsp request. The code of the  HelloWorld.java calss is:

HelloWorld.java

package com.ranga;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HelloWorld implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
System.out.println("HelloWorld");
String str = "Hello World!";
return new ModelAndView("hello.jsp", "message", str);
}
}
Step 8:
After that we will create a hello.jsp in the WEB-INF folder. The WEB-INF/hello.jsp code is:
hello.jsp

<%@page isELIgnored="false" %>
${message}
Step 9:
To run the example select Run -> Run As -> Run On Server from the menu and then run the application on tomcat server. Eclipse will start Tomcat server and deploy the application on the Tomcat. Ellipse will also open the application in it internal browser as shown below:
Click on the "Click Here" link to test the application. It should display the "Hello World!" message as shown below.

Friday, October 19, 2012

Eclipse IDE Tutorial

Please find the following site(s) it is very useful for beginners and experienced people.

  • http://www.vogella.com/tutorials/Eclipse/article.html
  • https://www.eclipse.org/
  • http://www.tutorialspoint.com/eclipse/