Posts

Sentimental Analysis : PART 1

Sentimental Analysis refers to identify, extract, quantify, and study affective states and subjective information. It helps to identify public emotion about certain topics/products. Humans are fairly intuitive when it comes to interpreting the tone of a piece of writing, but teaching a machine to identify emotion is tough. A negative sentence can be assumed by machine as positive.  For example, In case of sarcastic sentence "I have lost my watch again. That's brilliant", humans can easily tell that it's a negative emotion framed in sarcasm but machine can assume that it's a positive sentence without knowing the context. Applying the contextual information, machine can identify it to be negative emotion. Sentimental Analysis helps to gain insight from social data and to understand the consumer attitude and act accordingly.  VOC(Voice Of The Customer) applications are primarily used by companies to determine what a customer is saying about a product o
Basics of DataSource : Datasource is a name given to the connection set up to a database from a server . DataSource is an alternative to DriverManager for getting the connection .  We should prefer database connections getting from  a DataSource instead of a DriverManager. Using a Datasource you need to know only the JNDI name. The JNDI style is typical when using an application server or a web container Java Example for configuring and accessing a DataSource : -------------------------------------------------------- 1)  Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context in server.xml   <Resource name="jdbc/myoracle" auth="Container"               type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"               url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"               username="scott" password="tiger" maxActive="2

Arrays.sort() and Collections.sort() NullPointerException

While sorting an array by using Arrays.sort()  or using Collections.sort() for sorting a list you can encounter a NPE (NullPointerException) . You might be thinking what went wrong ? So one of element in the array which have been  passed for sorting contains the null element. Similar with the list case also .So check for a null entry in your array or list before passing to these methods as parameter. Example 1 : String[] strarr={"abc", "def" , null}; Arrays.sort(strarr); Output 1: -------- Exception in thread "main" java.lang.NullPointerException at java.lang.String.compareTo(String.java:1167) at java.lang.String.compareTo(String.java:92) at java.util.Arrays.mergeSort(Arrays.java:1144) at java.util.Arrays.sort(Arrays.java:1079) at Test.main(Test.java:7) Example 2: List strlist=new ArrayList (); strlist.add("abc"); strlist.add("def"); strlist.add(null); Collections.sort(strlist); Output 2: ----------

HIbernate CRUD operations

Below are some of the DB operations performed in Hibernate . First we need to get the SessionFactory  object . We can get the object like this SessionFactory factory= new AnnotationConfiguration().configure(hibernate.cfg.xml).buildSessionFactory(); 1) Insert : Session session=factory.openSession(); Employee emp=new Employee("empID","empName"); session.save(emp); 2) Delete: Session session=factory.openSession(); Employee emp=session.createCriteria(Employee.class).add(Restrictions.eq("empID","123")).uniqueResult(); session.delete(emp); 3) Update: Criteria criteria = session.createCriteria(Employee.class).add(Restrictionss.eq("id", 1)); Employee emp = (Employee) criteria.uniqueResult(); emp.setSalary(5000); session.update(emp); 4) Select: Session session=factory.openSession(); List empList=session.createCriteria(Employee.class).add(Restrictions.eq("company","Google")).list(); // Will get the li

RESTful WebService Tutorial

Representational State Transfer  ( REST ) is a style of  software architecture  for  distributed  systems such as the  World Wide Web . REST has emerged as a predominant  Web service  design model. We will be building a REST application using Apache tomcat , Jersey , Eclipse . Below is the code for making a dummy application for Restful WebService using Jersey. To begin with first set up all the jars required for the application.  Click the below link to download all the jars. https://sites.google.com/site/balonideepak/lib.zip?attredirects=0&d=1 After that  create a client for making a hit to the app. Create a class like JerseyGetClient.java and paste the below code inside it : import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource.Builder; public class JerseyGetClient { public static void main(String arg[]

JDBC versus ODBC and other APIs

At this point, Microsoft's ODBC (Open DataBase Connectivity) API is probably the most widely used programming interface for accessing relational databases. It offers the ability to connect to almost all databases on almost all platforms. So why not just use ODBC from Java? The answer is that you  can  use ODBC from Java, but this is best done with the help of JDBC in the form of the JDBC-ODBC Bridge, which we will cover shortly. The question now becomes, "Why do you need JDBC?" There are several answers to this question: ODBC is not appropriate for direct use from Java because it uses a C interface. Calls from Java to native C code have a number of drawbacks in the security, implementation, robustness, and automatic portability of applications. A literal translation of the ODBC C API into a Java API would not be desirable. For example, Java has no pointers, and ODBC makes copious use of them, including the notoriously error-prone generic pointer "void *"

Thin & OCI Drivers

Oracle provides two main types of drivers. The OCI driver. The OCI (type 2) driver consists of java wrappers to the low-level Oracle Call Interface (OCI) libraries used by utilities like SQL*Plus to access the database server. The OCI driver offers potentially better performance that the thin driver. It however requires the OCI libraries to be installed on the local machine. The "thin" driver. Also referred to as type 4 driver, the thin driver is a pure Java implementation of Oracle's networking protocol (Net8). Being self-contained, it may be used on any machine with--or without Oracle installed--or even distributed with application classes in an applet.