Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login

# Fundamentals !

Jenny Wallace
Greenhorn

Joined: Oct 04, 2000
Posts: 10
1. I am not able to access Float.MAX_VALUE and Float.MIN_VALUE

float largestFloat = Float.MAX_VALUE;
System.out.println(largestFloat);
The error message issued is :
No variable MAX_VALUE defined in class Float .
2. Unable to use the static method sqrt of StrictMath class
in java.lang package . Why ?

System.out.println(StrictMath.sqrt(25));

Error issued :
Undefined variable or class name :StrictMath

3. \u0041 is unicode value of 'A' .
If I want to get to 'B' or 'C' from \u0041 ,how do I do it?

4. Cud anyone explain the way in which a signed integer is
stored in bits for the negative range of the datatype ?
I am having trouble understanding this .

int i=1;
i=i<<31 ; // this gives -2147483648

The result confused me . Please throw some light !
Tom Patrick
Ranch Hand

Joined: Oct 24, 2000
Posts: 30
I can answer your last question. The << is shifts bits to the left filling in the "blanks" with zero's. When you shift the "1" (which has only 1 "1" bit in the LSB (least significant bit)) 31 times you move that "1" bit from the LSB to the MSB (most significant bit). The MSB is used to determine the sign of a number so by placeing a "1" in that spot you make the number negative. The reason you get the number -2147483648 is due to the following:
Shifting a bit 1 spot to the left is the same as multiplying a number by 2. So if i = 1 and you i << 1 you get 2 (1 * 2 = 2) and so on. If we were dealing in purely non negative numbers then a binary 1:
00000000 00000000 00000000 00000001
shifted 31 times would look like:
10000000 00000000 00000000 00000000
which is the decimal number 2147483648. You can test this by shifting i 30 times and seeing if you get a number that when multiplied by 2 will give you the above result.
And since the most significant bit in java represents a negative number when its a "1" you get -2147483648.
Long winded but I hope it helped you.
Eric Edwards
Ranch Hand

Joined: Feb 12, 2000
Posts: 60
Originally posted by Jenny Wallace:
1. I am not able to access Float.MAX_VALUE and Float.MIN_VALUE

float largestFloat = Float.MAX_VALUE;
System.out.println(largestFloat);
The error message issued is :
No variable MAX_VALUE defined in class Float .
2. Unable to use the static method sqrt of StrictMath class
in java.lang package . Why ?

System.out.println(StrictMath.sqrt(25));

Error issued :
Undefined variable or class name :StrictMath

3. \u0041 is unicode value of 'A' .
If I want to get to 'B' or 'C' from \u0041 ,how do I do it?

4. Cud anyone explain the way in which a signed integer is
stored in bits for the negative range of the datatype ?
I am having trouble understanding this .

int i=1;
i=i<<31 ; // this gives -2147483648

The result confused me . Please throw some light !

Try this for question #1:
float a = java.lang.Float.MAX_VALUE;
System.out.println(a);
Hope this helps!
Allen Alchian
Ranch Hand

Joined: Oct 11, 2000
Posts: 83
Maybe I'm missing your point on question 2, but the code will run if you use the following...
System.out.println(Math.sqrt(25));
And, for your first question, I used your code on my system and it ran fine, giving the response:
3.4028235E38

Allen
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Hope you got your answers from above, the only way I could reproduce your first error was to put it in my class named Float.
3. \u0041 is unicode value of 'A' .
Right, where 41 is the hex value of 'A'. So 'B' is \u0042 etc. An ascii table will show you all the hex values. I use ultraEdit as a text editor and the ascii table is built in
Jenny Wallace
Greenhorn

Joined: Oct 04, 2000
Posts: 10
1 . Thanks ! That was a silly one ! I had a class named Float
in my directory .
2. I have used Math.sqrt() .
But why am I not able to invoke StrictMath.sqrt() ?

3. For the unicode display , I dont know if my question is little too far fetched . But if I want to display the unicode
characters from one value successively to a particular value .
How do I it ?
What I am asking is : how to reach \u0042 from \u0041
If I try
System.out.println("\u0041+\u0001") ;
//this doesnt give B
4. Thanks for the explanation .
I guess I got what I was asking for . I happened to read this also .
http://www.wmin.ac.uk/~ettingj/se101/Lect03.html

So with a byte using its 8 bits as example the storage goes thus:
1 : 0000 0001
2 : 0000 0010
:
:
127 : 0111 1111
-128 : 1000 0000
-127 : 1000 0001
:
:
-2 : 1111 1110
-1 : 1111 1111

Eric Edwards
Ranch Hand

Joined: Feb 12, 2000
Posts: 60
Originally posted by Jenny Wallace:
1 . Thanks ! That was a silly one ! I had a class named Float
in my directory .
2. I have used Math.sqrt() .
But why am I not able to invoke StrictMath.sqrt() ?

3. For the unicode display , I dont know if my question is little too far fetched . But if I want to display the unicode
characters from one value successively to a particular value .
How do I it ?
What I am asking is : how to reach \u0042 from \u0041
If I try
System.out.println("\u0041+\u0001") ;
//this doesnt give B
4. Thanks for the explanation .
I guess I got what I was asking for . I happened to read this also .
http://www.wmin.ac.uk/~ettingj/se101/Lect03.html

So with a byte using its 8 bits as example the storage goes thus:
1 : 0000 0001
2 : 0000 0010
:
:
127 : 0111 1111
-128 : 1000 0000
-127 : 1000 0001
:
:
-2 : 1111 1110
-1 : 1111 1111

What is StrictMath. I never heard of it and can't locate it in any of my Java books.
Thanks.
Jenny Wallace
Greenhorn

Joined: Oct 04, 2000
Posts: 10
I found StrictMath class in java.lang package in
JavaTM 2 Platform, Standard Edition, v 1.3 API Specification
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Jenny,
public class PrintHex
{
public static void main(String[] args)
{
int i = Integer.parseInt( "0041", 16 );
i += 1; // For 'B'
char[] c = { (char)i };
String str = new String( c );
System.out.println( str );
}
}
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 515

3

Jenny,
steve

example 1 - storting value in a char, incremeting value

example 2 - adding values within the scope of a method invocation

[This message has been edited by Steve Fahlbusch (edited October 26, 2000).]
[This message has been edited by Steve Fahlbusch (edited October 26, 2000).]
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Jenny,
Do you have JSK 1.3 installed? If yes, the code you gave should work correctly or you could try the fully qualified name: java.lang.StrictMath.sqrt(25).
If you have an earlier JDK installed it won't work; could not find it in the 1.2 class libraries.
Hope that helps.
------------------
Jane

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Jenny Wallace
Greenhorn

Joined: Oct 04, 2000
Posts: 10
2. Thanks !
That was what I was trying to output - the characters by managing the unicode list in the program.
4. Yes ! I have JDK1.2.2 installed in my machine .
Infact,I installed this from the links given in the Sun's (Your First cup of java ) tutorial . That was a sensible pointing out !
Well, Thanks everybody for ur time and patience .
Jenny

I agree. Here's the link: http://aspose.com/file-tools

subject: Fundamentals !