Search

Girish Kumar Shakya

Personal Blog

Month

October 2015

OFFER OF THE DAY : GET JAVA CERTIFIED AT JUST 10$

“Java Programming from Scratch” will gives you a complete overview on Java Programming. Java is a general – purpose computer programming language that is concurrent, class-based,object-oriented and platform independent language. Java is everywhere from small devices to Smart phones like Android,Blackberry and has highest paying jobs for Java developers in programming Industry.

discountButton

Advertisements

Certification : Android Advance Programming II

100% Discount for 1 Day Only

Get Certified with Advance Android Programming Level II , and learn advance concept to create Android Application from scratch. In this course you will learn how to convert your imagination into programming. you will learn key concept first in Java and then will learn Complete Android Programming with 15+ projects. All the essential topic is covered in this course with full detail.

click Link to Join

http://lavit.online/course/?courseid=advanceandroid

SELF – PACED :ANDROID APP DEVELOPMENT CERTIFICATION TRAINING

certificationCoin

AndroidProgrammingFreeCourse

Lavit Online Training : How to grasp most from self-paced

Join me on Blab for discussing How to have most from Self – Paced learning

blabselfpaced

Send Mail Using Java Mail API

java-mail-send-01 Sending mail using JavaMail API is quite easy in Java application, if you are creating console based, desktop or web based Java application, JavaMail API is very easy to integrate and help you to send not only text but also Hyper Text messages.

To work with JavaMail API you will need to download javamail-1.4.7  zipped file, after extracting it you will need following files in your java project library.

  • mail.jar
  • dsn.jar
  • gimap.jar
  • imap.jar
  • mailapi.jar
  • pop3.jar
  • smtp.jar

Now, lets create a simple class SendMail.java

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
*
* @author girish
*/
public class SendMail {
private String username;
private String password;
private String to;
private String msg;
private String subject;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getTo() {
return to;
}

public void setTo(String to) {
this.to = to;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public void send_mail() throws MessagingException{
Properties props = new Properties();//create an instance of properties
props.put(“mail.smtp.auth”, “true”); // set smtp to true
props.put(“mail.smtp.starttls.enable”, “true”);// enables starttls
props.put(“mail.smtp.host”, “smtp.gmail.com”);// add a host name, here i am using                                                                                                //gmail
props.put(“mail.smtp.port”, “587”);// smtp port for gmail is 587

// create Session instance from getInstance() static method

                   Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

// create message instance using MimeMessage(session)
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));// set the recipient to
message.setSubject(subject);//set the subject
//message.setText(msg);// this is commented if you enable you can only send text                                                              message
message.setContent(msg,”text/html”);// setContent method is used to send HTML                                                                                   //formated messages
Transport.send(message);// Using static send() method of Transport class

System.out.println(“Done”);

}

public static void main(String args[]){//main method

SendMail sm=new SendMail();
sm.setUsername(“<your gmail username>”);
sm.setPassword(“<your gmail password>”);

sm.setMsg(“Testing message for JavaMail API”);
sm.setSubject(“LAVIT : ONLINE PROGRAMMING TRAINING ACADEMY”);
sm.setTo(“clairvoyant.1947@gmail.com”);

try {
sm.send_mail();
System.out.println(“Mail send successfully!!”);
} catch (MessagingException ex) {
System.out.println(“ERROR SENDING “+ex.getMessage());
}
}//end of main method
}//end of class

Keep in mind using

message.setText(msg); // used to send simple text message
message.setContent(msg,”text/html”);//used to send message embedded with HTML Tag

now you can use this complete class with any of other project , this will helpful for any type of Java Application

Thanks and Regards

Girish

Founder, Lavit Online Training Academy

for more visit : LAVIT ONLINE TRAINING ACADEMY  

TRY IT and ENJOY

Java APIs for XML Registries

jaxr

JAXR_NEW

For more Join Lavit Online Training Academy

javaprogramming

Java Refresher Part I

Declarations and Access Control

Java Refresher

Class A template that describes the kinds of state and behavior

that objects of its type support.

Object At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object which is an instance of that class. That object will have its own state, and access to all of the behaviors defined by its class.

State (instance variables) Each object (instance of a class) will have its own unique set of instance variables as defined in the class. Collectively, the values assigned to an object’s instance variables make up the object’s state.

Behavior (methods) When a programmer creates a class, she creates methods  for that class. Methods are where the class’ logic is stored. Methods are where the real work gets done. They are where algorithms get executed, and data gets manipulated.

Identifiers and Keywords

Java Refresher

Identifiers

All the Java components we just talked about—classes, variables, and methods need names. In Java these names are called identifiers.

Example:-  Animal , employeeName, setName(String name)

Keywords

Like all programming languages, Java has a set of built-in keywords. These keywords must not be used as identifiers.

Example :- int , long, if ,else, while, float, double, Integer,Double

Inheritance

Java Refresher

Inheritance

Central to Java and other object-oriented languages is the concept of inheritance, which allows code defined in one class to be reused in other classes.

Example :- a Car superclass class could define general methods common to all automobiles, but a Ferrari subclass could override the accelerate() method.

Interfaces

Java Refresher

Interfaces

A powerful companion to inheritance is the use of interfaces. Interfaces are like a 100-percent abstract superclass that defines the methods a subclass must support, but not how they must be supported.

Example:-

interface Animal

{

 void eat();

}

class Cow implements Animal

{

void eat()

{

System.out.println(“Vegitarian”);

}

Identifiers & JavaBeans

Legal Identifiers

1)     Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!

2)     After the first character, identifiers can contain any combination of letters,currency characters, connecting characters, or numbers.

3)     In practice, there is no limit to the number of characters an identifier can contain.

4)    You can’t use a Java keyword as an identifier.

5)    Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.

Legal Identifiers

Examples of legal and illegal identifiers follow, first some legal identifiers:

int _a;

        int $c;

        int ______2_w;

        int _$;

        int this_is_a_very_detailed_name_for_an_identifier;

     The following are illegal (it’s your job to recognize why):

      int :b;

      int -d;

      int e#;

      int .f;

      int 7g;

Complete List of Java Keywords

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Sun’s Java Code Conventions

Classes and interfaces

The first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase (a format that’s sometimes called “CamelCase“). For classes, the names should typically be nouns. For example:

Dog

Account

PrintWriter

       For interfaces, the names should typically be adjectives like

          Runnable

Serializable

Methods

The first letter should be lowercase, and then normal camelCase rules should be used. In addition, the names should typically be verb-noun pairs. For example:

         getBalance

doCalculation

setCustomerName

Variables

        Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds good to us. Some examples: buttonWidth;accountBalance;

Constants

        Java constants are created by marking variables static and

       final. They should be named using uppercase letters with underscore characters as separators:

            MIN_HEIGHT

for more download ppt:  Java_PPT

Welcome to our Online Programming School

logo2“Programming is usually taught by Example ”

Learn Programming language at your own pace. A complete online school for Geeks.

lavit

Enroll and get access to a complete online programming school

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: