What are the data type conversions available in Java?

November 25th, 2008 by uCertify Leave a reply »

Java provides two kinds of data type conversions, namely automatic and explicit. Automatic conversion takes place when the following two conditions are fulfilled:

  • The two types are compatible.
  • The destination type is larger than the source type.

When these two conditions are met, widening conversion takes place, i.e., a narrow data type is promoted to a wider one. For example, the value of byte type will be promoted to int, as int is wider than byte in width. However, in many cases, an automatic conversion cannot be performed. For example, an automatic conversion cannot be performed to convert int to byte, as int is wider than byte. In such cases, conversion is performed explicitly. The general form to perform such type of narrowing conversion is as follows:

(target-type) value

Like this article? Share it with others
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.