Wednesday, February 4, 2009

Convert decimal integer to hexadecimal number


/*
Convert decimal integer to hexadecimal number example.
This example shows how to convert int to hexadecimal number using
toHexString method of Integer wrapper class.
*/


public class ConvertIntToHexExample {
public static void main(String[] args) {
int i = 32;
String strHexNumber = Integer.toHexString(i);
System.out.println("Convert decimal number to hexadecimal number example");
System.out.println("Hexadecimal value of " + i + " is " + strHexNumber);
}
}
/*
Output would be
Convert decimal number to hexadecimal number example
Hexadecimal value of 32 is 20
*/

Convert decimal integer to octal number

/*
Convert decimal integer to octal number example.
This example shows how to convert int to octal number using
toOctalString method of Integer wrapper class.
*/
public class ConvertIntToOctalExample {
public static void main(String[] args) {
int i = 27;
String strOctalNumber = Integer.toOctalString(i);
System.out.println("Convert decimal number to octal number example");
System.out.println("Octal value of " + i + " is " + strOctalNumber);
}
}

/*
Output would be
Convert decimal number to octal number example
octal value of 27 is 33
*/

Convert binary number to decimal number

/*
Convert binary number to decimal number example.
This example shows how to convert binary integer number
to decimal integer number using valueOf method of Integer
wrapper class.
*/
public class ConvertBinaryToDecimalNumber {
public static void main(String[] args) {

String strBinaryNumber = "111000";
/*
* to convert binary number to decimal number use,
* int parseInt method of Integer wrapper class.
*
* Pass 2 as redix second argument.
*/
int decimalNumber = Integer.parseInt(strBinaryNumber,2);
System.out.println("Binary number converted to decimal number");
System.out.println("Decimal number is : " + decimalNumber);
}
}

/*
Output would be
Binary number converted to decimal number
Decimal number is : 56
*/

Convert octal number to decimal number

/*
Convert octal number to decimal number example.
This example shows how to convert octal number
to decimal number using valueOf method of Integer
wrapper class.
*/
public class ConvertOctalToDecimalNumber {
public static void main(String[] args) {
String strOctalNumber = "33";

/*

* to convert octal number to decimal number use,
* int parseInt method of Integer wrapper class.
*
* Pass 8 as redix second argument.
*/
int decimalNumber = Integer.parseInt(strOctalNumber,8);
System.out.println("Octal number converted to decimal number");
System.out.println("Decimal number is : " + decimalNumber);
}
}

/*
Output would be
Octal number converted to decimal number
Decimal number is : 27
*/

Convert hexadecimal number to decimal number

/*
Convert hexadecimal number to decimal number example.
This example shows how to convert hexadecimal number
to decimal number using valueOf method of Integer
wrapper class.
*/

public class ConvertHexToDecimalExample {
public static void main(String[] args) {


String strHexNumber = "20";

/*
* to convert hexadecimal number to decimal number use,
* int parseInt method of Integer wrapper class.
*
* Pass 16 as redix second argument.
*/


int decimalNumber = Integer.parseInt(strHexNumber, 16);
System.out.println("Hexadecimal number converted to decimal number");
System.out.println("Decimal number is : " + decimalNumber);
}
}

/*
Output would be
Hexadecimal number converted to decimal number
Decimal number is : 32
*/

Tuesday, February 3, 2009

Create ASP Applications

Download The e-book to Configure ASP application Step-Step-By

Download

Send Mail Using Java

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

public class Main
{
String d_email = "sender email address",
d_password = "Sender passowrd",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "recivers email address",
m_subject = "mail subject",
m_text = "mail body text.";

public Main()
{
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

SecurityManager security = System.getSecurityManager();

try
{
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);

MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
Transport.send(msg);
}
catch (Exception mex)
{
mex.printStackTrace();
}
}

public static void main(String[] args)
{
Main blah = new Main();
}

private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(d_email, d_password);
}
}
}


Download Jar

Sunday, February 1, 2009

Apache Maven



Introduction

Maven, a Yiddish word meaning accumulator of knowledge, was originally started as an attempt to simplify the build processes in the Jakarta Turbine project. There were several projects each with their own Ant build files that were all slightly different and JARs were checked into CVS. We wanted a standard way to build the projects, a clear definition of what the project consisted of, an easy way to publish project information and a way to share JARs across several projects.

The result is a tool that can now be used for building and managing any Java-based project. We hope that we have created something that will make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project.

Maven's Objectives

Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features
Create Maven Project In Eclipse

To create maven project follow the steps which is given in below URL

URL:
http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html

Code Serach Engine

Codase - Source Code Search Engine DocJar: Search Open Source Java API


Google Code

http://code.google.com/

koders
http://www.koders.com/

CodeBase
http://www.codase.com/

Docjar
http://www.docjar.com/

About Cobertura


Reference URL: http://cobertura.sourceforge.net/
http://mojo.codehaus.org/cobertura-maven-plugin/index.html
Download SRC: http://cobertura.sourceforge.net/download.html

About Coberture

If you've ever written unit test cases for any program language, you know how important it is to ensure that your test cases execute each line of code. This is called code coverage. The more your unit test cases exercise the logic in your application code, the less likely it is that a bug slips through your unit test cases. On a large code base (common to most applications these days), it's hard to judge how effectively your coverage statistics. There are various tools to help quantitatively measure the coverage of your unit test cases. Such vendor tools that accomplish this are Parasoft's JTest, and Quest's JProbe. But who wants to buy software? I've been trying out this open source code coverage measurement tool called Cobertura. So far I've only been using the ant tasks in combination with HTML reports. The reports it produces are really nice and informative, even allowing you to drill down into each class such that you can view the source and actually see the number of times each line of code was called from your test suite. Alternatively, red highlighting will call those lines with no coverage to your attention. There's also a command line interface if you choose to execute it outside of your build. Check it out here:

http://cobertura.sourceforge.net/


What is Cobertura?

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.


Features

* Can be executed from ant or from the command line.
* Instruments Java bytecode after it has been compiled.
* Can generate reports in HTML or XML.
* Shows the percentage of lines and branches covered for each class, each package, and for the overall project.
* Shows the McCabe cyclomatic code complexity of each class, and the average cyclomatic code complexity for each package, and for the overall product.
* Can sort HTML results by class name, percent of lines covered, percent of branches covered, etc. And can sort in ascending or decending order.

Sample Report



Example: Steps to How to configure Cobertura

Download