Converting Objects and Simple Variables

One of the most common tasks you'll need to accomplish in Java is to convert information from one form into another. There are several types of conversions you can do:

  • Converting an object into another object

  • Converting a simple variable into another type of variable

  • Using an object to create a simple variable

  • Using a simple variable to create an object

Simple variables are the basic data types you learned about during Hour 5, “Storing and Changing Information in a Program.” These types include int, float, char, long, and double.

When using a method or an expression in a program, you must use the right type of information that's expected by these methods and expressions. A method that expects a Calendar object ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.