iwebie
HOME MOVIES TV SHOWS SPORTS GENERAL
 RSSPRIVACY
 

Java Data Type Conversions
Posted by admin on July 4th, 2008

Watch over 100,000 movies and TV shows on your PC

Below is a program to demonstrate simple Java Type conversions with examples. You will notice the following converstions;

  • Java String to Primitive Data Type
  • Java Primitive Data Type to String
  • Use of Wrapper classes to support the conversion

[sourcecode language='java']
public class JavaTypeConversions {

public static void main(String args[]) {

// ASCII code to String Conversion
int i = 74;
String iStr = new Character((char) i).toString();
System.out.println(”Ascii Code : ” + i + “\t”
+ “Converted to String : ” + iStr);

// decimal to binary Conversion
// Similarly you can convert it into a HexString using
// Integer.toHexString
int j = 74;
String bStr = Integer.toBinaryString(j);
System.out.println(”Decimal Value : ” + j + “\t” + “Binary String : ”
+ bStr);

// double to String Conversion
// Similarly you can convert from float to String using Float.toString
// Similarly you can convert from Integer to String using
// Integer.toString
double k = 74.50;
String dStr = Double.toString(k);
System.out.println(”Double Value : ” + k + “\t”
+ “Converted to String : ” + dStr);

// Char to Ascii Conversion
char l = ‘J’;
int m = (int) l;
System.out.println(”Char Code : ” + l + “\t” + “Converted to Ascii : ”
+ m);

// HexaDecimal to Integer
int n = Integer.valueOf(”A8DA3″, 16).intValue();
System.out.println(”Hexadecimal Code : A8DA3\t”
+ “Converted to Ascii : ” + n);

// String to double
// You can also do Double.parseDouble(”str”)
String oStr = “128″;

double p = Double.valueOf(oStr).doubleValue();
System.out.println(”String :” + oStr + “\t” + “Converted to double : ”
+ p);

// int to hexadecimal

int q = 17;
System.out.println(”int : “+q+”\t Converted to Hex is : ” + Integer.toHexString(i) );

}
}
[/sourcecode]

Bookmark Article
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Propeller

Leave a Reply

Most Popular

Watch over 100,000 movies and TV shows on your PC
Recent Posts

  • Watch Crazy on the Outside Online Free
  • Watch It’s Complicated Full Video Online
  • Watch Leap Year Free Stream Online
  • Watch Manchester United vs Birmingham Live Stream
  • Watch Avatar Online Stream
  • Watch Nine Online Video
  • Watch Crazy Heart Full Stream
  • Modern Family Season 1 Episode 11 | Watch Modern Family s01e11 Up All Night Full Episode
  • Burnley vs Arsenal EPL | Watch Burnley vs Arsenal Live Stream
  • Watch The Princess and the Frog Online Free
Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
Powered by WordPress