Saturday, May 9, 2015

How to sort the object based on Id and Name in Java

If we have the List, Map or any other collection object we sort by using calling Collections.sort() method directly. But if we have our custom object we have to do some extra to sort our custom object. Assume that we have one Person Object like below

class Person{
    int id;
    String name;

    Setter…
    Getter…
}

Serialize and Deserialize the object in java.

Serialization is a process of converting an object into a sequence of bytes which can be persisted to a disk or database or can be sent through streams. The reverse process of creating object from sequence of bytes is called deserialization.

In this process there are three steps
1-    Create java class by implementing the Serializable class.
2-    Create SerializeDemo class to write a java object into file.
3-    Create DeserializeDemo class to read the java object from file.

How to download a file from server in java

To download a file from server is very easy task just get the file name and path and set the file name into response header (Content-Disposition) .
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

How to upload a file at server and store path in database in java.

To upload a file at server and storing a path in database we have to use JavaJoom Api. Add "uploadbean.jar" in your application and follow below steps –

How to send SMS in java.

To send a sms in java is very similar to send email in java. At the place of mail server (smtp host) we need to give some third party (which are providing the sms service) smtp host.
Many number of SMS provider in the market we can choose any of them. Here in my below 2 example I have choose two sms provider

1-    ipipi.com
2-    vianett.com

First example is using ipipi.com and second one is vianett.com.

Friday, May 1, 2015

How to send the mail in Java.

Sending mail in java is very easy just follow the below stpes-


Step 1- Create a property with smtp host, smtp port. Here I’m going the send the mail using gmail so I’m using smtp host as smtp.gmail.com and port is 465.

How to send the attachment mail in java

Sending mail in java is very easy just follow the below stpes-