Saturday, 1 December 2012

How to access the particular class of package inside another package

Leave a Comment
Lets Consider a package  package1

import package1;
public class A    //This Class Must Be Public
{
    void display()
   {
      System.out.prinltn("InSide Class A");
   }



Lets Consider another package  package2

import package2;
class B   
{
  public static void main(String args[])
 {
    A obj=new A();
    obj.display();
 }  



Output:
InSide Class A
Read More...

Download Web Page As PDF File

Leave a Comment
Step 1: Copy URL From Address/URL Bar

Step 2: Open This Site http://www.web2pdfconvert.com/

Step 3: Paste Copied URL and Press Convert to PDF

Now You Have PDF File To Download.
Read More...

Send Mail Using GMAIL

Leave a Comment

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class SendMail {
  
       
        // Get the session object
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");

        Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(
                                "username@gmail.com", "password");// change
                                                                        // accordingly
                    }
                });

        // compose message
        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress("user@gmail.com"));// change
                                                                            // accordingly
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(
                    to)); 


           message.setSubject(sub);
            message.setText(msg);

            // send message
            Transport.send(message);

            System.out.println("message sent successfully");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }

  }
Read More...