Anonymous Classes in Java

A type of inner class that has no name that you define right in the middle of a method (where static init blocks and instance init blocks count as methods). You define it, and create an object of that type as a parameter all in one line. An anonymous class is defined and instantiated in a single succinct expression using the new operator.Used for creating simple delegate callback objects.These anonymous inner classes can access the static and instance variables of the enclosing outer class.
Instead of passing arguments to a constructor, your inner class methods can reach out and grab what they need directly from local variables in the enclosing method. The other technique is to use an instance initialiser block. You are only allowed one per anonymous inner class.
Syntax for Anonymous Classes
new class-name ( [ argument-list ] ) { class-body }

package Vinay; 
public class VinayMain
{ 
public static void main(String[] args) 
{ 
// Here is where the anonymous class is defined and instantiated // 
Runnable vinayrun = new Runnable() 
{
int Total = 0; 
public void run() 
{ 
for (int i=0; i<10000000; i++) 
{
Total++;
} 
System.out.println(Integer.toString(Total)); 
 } 
 }; 
vinayrun.run(); 
} 
 }

create an instance, named vinayrun , of a nameless (anonymous) class which implements the java.lang.Runnable interface.And we are calling the run mehtod of anonymous class through vinayrun object.

Drawback– The big drawback with anonymous classes is they can’t have explicit constructors. You can’t pass them any parameters when they are instantiated.

Benefits of Anonymous Classes
The key benefit of an anonymous class is encapsulation (or clutter reduction). An anonymous class is, in a sense, the ultimate in private object oriented encapsulation. It is defined exactly where it is needed, it can never be used anywhere else, and it has totally local scope.One final key benefit of anonymous classes is that they have access to all data and methods of their containing classes, including private members; meaning that for small highly localized tasks, they may require less initialization.

References –
http://ssmela.googlepages.com/AnonymousClassesinJava.pdf
http://mindprod.com/jgloss/anonymousclasses.html

Using JavaMail API to send an email in JAVA

We can send mail through JavaMail Api through java code.I have read somewhere and thought of sharing with everyone.
For using this code you need to JavaMail Api.

//get mail session

Properties props = new Properties();
props.put("mail.smtp.host","localhost");
Session session = session.getDefaultInstance(props);

// create the messge.
MimeMessage message = new MimeMessage(session);
message.setSubject("Vinay first Mail");
Message.setText("Vinay mail text ");

//address the message
InternetAddress addfrm = new InternetAddress("[email protected]");
message.setFrom(addfrm);
InternetAddress addto = new InternetAddress("[email protected]");
message.setRecipient(Message.RecipientType.TO,addto);

//send message
Transport.send(message);

Update

Send email in text and html format Text and HTML format

pimp it

Introduction of Javascript IDE- APTANA

Coding in JavaScript is always cumbersome.Programmer always find difficult debugging in JavaScript.There is one IDE which help javascript programmer.That is Aptana Studio.
Aptana Studio is an open source integrated development environment (IDE) for building Ajax web applications. It includes support for JavaScript, HTML, DOM, and CSS with code-completion, outlining, JavaScript debugging, error and warning notification and integrated documentation. Additional plugins allow Aptana Studio to be extended to support Ruby on Rails, PHP, Python, Perl[1], Adobe AIR, Apple iPhone and Nokia WRT (Web Runtime).
Aptana, Inc. is a company making web application development tools for Web 2.0 and Ajax for use with programming languages such as JavaScript, Ruby, PHP and Python. Aptana’s main products are Aptana Studio, Aptana Cloud and Aptana Jaxer.Aptana is both a set of plugins that may be installed into an Eclipse install, or installed as a standalone Rich Client App.If you’re starting fresh, only planning to do HTML/CSS/JS, or don’t want to deal with a large amount of plugins inside one install, then I recommend getting the Aptana standalone. (You can still install Eclipse plugins into it, but you’re starting off with only the plugins you need for web development).

Ajax Library Support
Aptana Studio ships with the following Ajax libraries, but more can be added or updated.
Adobe Spry
Ext
Aflax
Rico
Prototype
Mochikit
Yahoo! UI Library
Mootools
Dojo toolkit
jQuery
Script.aculo.us

PHP
The Aptana IDE provides support for developing PHP applications via the add-on PHP plugin. This includes:
built-in PHP server for previewing within Aptana Studio,
full code assist, code outlining & code formatting,
integrated PHP debugger,
built in Smarty,
type hierarchy view,
go to declaration,
integrated PHP manual (online or local).

RadRails
Aptana Studio supports Ruby on Rails development using RadRails, an open source plugin for the Ruby on Rails framework. This includes:

integrated Rails shell console,
default-install and config of Ruby interpreter, database and debugger,
code completion with type inferencing,
Code Assist for Ruby, CSS, JS, and HTML inside RHTML files,
type hierarchy view,
go to declaration,
call hierarchy,
full implementation of RDT (Eclipse’s Ruby Development Tools project).

Python
Aptana Studio provides support for Python in the form of the PyDev plugin. This provides color syntax hilighting, Code Assist, code outlining, debugging and integrated support for Python and Jython interpreters.

References – http://en.wikipedia.org/wiki/Aptana_Studio
www.aptana.com

pimp it