This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Data Type Conversion Just beginning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Data Type Conversion Just beginning" Watch "Data Type Conversion Just beginning" New topic
Author

Data Type Conversion Just beginning

Lauren Summers
Greenhorn

Joined: May 19, 2012
Posts: 1
Hi everyone,

Im just beginning Java Programming and have read up a little and been doing tutorials well i'll just cut to the chase here.

I have done a simple tutorial which involves an Applet and adds or subtracts two numbers depending on the button clicked.
There is just a small part of the tutorial which isn't explained very well and thats where the conversion from float to string takes place. I just have a question. (Ill post the entire program below everything)

My question is why is what is happening here?



I understand "msg1 = txt1.getText();" is assigning whatever I type into my first text field to my string variable "msg1" but what is actually happening on the next line? Is this line, "Float num1 = new Float(msg1);", saying take my float from num1 and put it in my string variable msg1? And once in there convert it to a String with this line "msg1 = Float.toString(num1);"?


Thanks to anybody who can understand that question! I really appreciate the help!
Below is the entire program!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65


This line uses the Float constructor to create a new Float object referenced by num1. The value of the Float is the conversion of msg1 to numeric. msg1 itself is unaffected.

See the Javadoc for java.lang.Float (⇐ click that) for more info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3574
    
  14

Welcome to CodeRanch, Lauren!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Data Type Conversion Just beginning
 
Similar Threads
AWT
applet gui issues
Please help me for Applet Communications!
Focus problem with setModal in JDialog
Lining up JTextFields next to JLabels