Monday 22 July 2013

What are Wrapper classes in java?





Java uses primitive types ( int, char, double etc.) to hold the basic data types supported by the language. Sometimes it is required to create an object representation of these primitive types as there are collection classes that deal only with objects. One needs to wrap the primitive type into a class.
Example: int a=1;    //Primitive data type int 

                 Integer  I  = new Integer(1);    //Wrapper class Integer for int primitive data type

To satisfy this need, java provides classes that correspond to each of the primitive types as:
All byte, Short, long, double use Byte, Short, Long, Double class as wrapper respectively similarly char has Character and boolean has Boolean wrapper class. Thus, they are commonly referred to as type wrapper.
So we can define type wrapper is classes that encapsulate a primitive type within an object.

Difference between Array.sort() and Collections.sort() with example



Difference between Array.sort() and Collections.sort() with example

Program to sort an Array with Arrays.sort() method of util package
import java.util.Arrays;
public class demoCollection1
{

   public static void main(String[] args)
                {

                   String emp[] = {"Saurav","Rahul","Sachin","Prasad","Mongia"};
                    System.out.println("The Array before Sorting");
           for(int i=0;i<5;i++)
           {
              
                System.out.println(emp[i]);
           }
          Arrays.sort(emp);  //This will sort the arrays contents
          System.out.println("The Array after Sorting");
          for(int i=0;i<5;i++)
           {

                System.out.println(emp[i]);
           }
                }
}



Program to sort an ArrayList with Collections.sort() method of util package

import java.util.*;
public class demoCollection2
{
    public static void main(String s[])
    {

        ArrayList al  = new ArrayList();
        al.add("fffff");
        al.add("bbbbb");
        al.add("ddddd");
        al.add("ccccc");
        al.add("aaaaa");
        System.out.println("ArrayList before sorting");
        System.out.println(al);
        Collections.sort(al);
        System.out.println("ArrayList after sorting");
        System.out.println(al);
    }

}

The upper two program can sort array and arraylist on the basis of single values but Lists are meant to store objects and they can have multiple properties so if need to sort list on the basis of some other properties than we need to use Compareable and Comparator interfaces.

Difference between Procedure and Function in oracle pl/sql



Difference between Procedure and Function

  • Usually functions are used to perform a specific computational task and procedures are used to perform or implement some business logic.
  • Procedure may or may not return value but function should always return one value.
  • We can call functions in select statement (That’s why we can use them in the script for creating views also) whereas for calling procedure we have to write a PL/SQL block in PL/SQL.
  • We can call Stored Procedure within function. We can also call function within stored procedure.

Wednesday 10 July 2013

Small Core Java Client/Server Chat Project with code

 Client/Server Chat Messenger Project Code

Please follow the below link to download the project code
https://docs.google.com/file/d/0B9oM-lfxf9F9WXhOdDdYMEpHWlE/edit?usp=sharing





                                                         Project Details with Screenshots
In this project we have built a simple Client Server chat application with GUI. The chat process will involve at least two or more machines on a LAN. We can use this chat application on single machine also by opening two Netbean/CMD instances and running server program on one instance and client program on other instance. Basically it works on the concept of one Server program for listening to a particular port for messages and one Client program for sending the messages on a particular port of a particular IP(IP can be localhost or IP of other machine ).
The functionality of two programs are as follow:

Server Program:

  • ·         This program listens to a particular port for incoming messages and shows them to users.
  • ·         Client running on any Machine can connect to the this server program by giving  address(IP) and port of this system.
  • ·         Receive the incoming messages and show them in server window to users.

Client Program:

  • ·         Connect to the server machine by giving the IP and port of the server machine.
  • ·         Send the message typed by the user to server machine .

  Software Used:

  • ·         JDK1.6

Technology Used:

  • ·         JFrames, Socket Programming, IO Package



                                                        Project Screenshots

Client Program GUI :-




Server Program GUI :- 

Command to run Server Program:-
  1.    First install java in your system
  2.   Then copy the downloaded files from the link given above to the desired location on your computer.
  3.  Then run the command as in below screenshot




For Client Side: