//flex table opened by JP

Click to See Complete Forum and Search --> : java question


maurob
05-05-2003, 09:04 PM
i have a little bit of trouble understanding the difference...what is the difference between a float variable and a float object in java? i just need a little brief explination to clear some frustrating thoughts.
thanks

DocEvi1
05-06-2003, 05:52 AM
to my mind they are the same thing. for instance,

String s = "bob"; is the same as
String s = new String();
s = "bob";

. It is just Java recognises these "special" cases and removes the need to initialise them properly.

Stefan

qball
05-06-2003, 10:00 PM
what is the difference between a float variable and a float object in java?



...to my mind they are the same thing...


The difference is actually very important. The difference is one is primitive datatype (float variable) and the other is an Object (float object).

I know, your asking what is a "float object"....


The Float class wraps a value of primitive type float in an object. An object of type Float contains a single field whose type is float.

In addition, this class provides several methods for converting a float to a String and a String to a float, as well as other constants and methods useful when dealing with a float.


from:
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Float.html

The difference between primitive datatypes and Objects can be shown by using int and Integer, though float/Float work the same way...


int i =99;
Integer I = new Integer(i);
System.out.println("Primitive i=" + i);
//this is basically call toString()...
System.out.println("Object I=" + I);

//compile error, so comment out...
int val = i*I;
//no compile error
int val = i*I.intValue();
System.out.println("Primitive val=" + val);

//try this with an int!
String s = "99";
System.out.println("String s as int =" + Integer.parseInt(s));
val = val*Integer.parseInt(s);
System.out.println("Primitive val=" + val);


Integer, not only Object, but also Class with some useful Static methods for data conversion. int just lowly ole datatype...

DocEvi1
05-08-2003, 10:20 AM
just goes to show my Uni course is going well :p

Actually, looking back at the post / question I should have known that one :rolleyes: Oops.

Stefan

Eric Legge
05-25-2003, 11:52 AM
I was under the impression that Java could be used to create stand-alone applications, but I have yet to seen one.

Why?

What's the point of learning a fairly complicated language like Java just to be able to write web applets?

C# - which is very similar - can be used for applications, so why is anyone bothering with Java?


Eric,
http://www.legge40.freeserve.co.uk/BuyerBeware.htm

DocEvi1
05-25-2003, 12:16 PM
java is cross platform relying on the java interface (dependant on machine). There are plenty of java apps about, most of the IDE's for java are actually programmed in java but almost everyone of them is slow and clunky.

I don't really have a choice about the language we learn, tis a shame but apparently java will start to come to the front in the near future and be the programmers choice. Don't really see it unless they speed it.

Stefan

qball
05-25-2003, 09:32 PM
I was under the impression that Java could be used to create stand-alone applications, but I have yet to seen one.
Why?
What's the point of learning a fairly complicated language like Java just to be able to write web applets?
C# - which is very similar - can be used for applications, so why is anyone bothering with Java?


Either you live under a rock, or have not been looking for java apps. Try:

http://www.eclipse.org/
http://www-3.ibm.com/software/info1/websphere/index.jsp
http://www.apache.org/

The first 2 are "slow and clunky IDEs" used by billions...

Doubt you could look at most commercial websites without some form of java program/app.

Why bother with java?

it's FREE.
it's established and used ubiquitously.
it works.

Why bother with C#?

it's not FREE.
it's proprietary to winders.
IS another lame attempt for MS to do something they haven't or can't...