Java

M

michalfabisiak

Hello,

I am new to Java. I was asked to write the program that shows the
maximum value of Character with uasge of MIN_VALUE. Could You please
help me with that. Maybe You have got an example on how to use
Constatnt fields. I have problems with that.

Thanks
 
W

Wildemar Wildenburger

I am new to Java. I was asked to write the program that shows the
maximum value of Character with uasge of MIN_VALUE. Could You please
help me with that. Maybe You have got an example on how to use
Constatnt fields. I have problems with that.

Sorry, I don't really understand what it is you want to do. I suggest
you include the smallest possible version of your program that will
compile and still shows the behavior you have a question about. Then it
will become clearer what it is that you want and what can help you.

Sidenote: Be aware that by the way you asked your question, one could
assume that this is a homework assignment. People generally don't like
being asked to do other people's homework, so you could get some heat.
If you show that you have put some effort into trying to find a solution
and ask a specific question about your approach, you will (presumably)
get better response.

regards
/W
 
O

Owen Jacobson

Hello,

I am new to Java. I was asked to write the program that shows the
maximum value of Character with uasge of MIN_VALUE. Could You please
help me with that. Maybe You have got an example on how to use
Constatnt fields. I have problems with that.

Consider that char values are unsigned two-byte quantities and all
operations on them are performed modulo 2**16.

For further explanation, talk to your prof.
 
J

Jeff Higgins

michalfabisiak wrote
Hello,

I am new to Java. I was asked to write the program that shows the
maximum value of Character with uasge of MIN_VALUE. Could You please
help me with that. Maybe You have got an example on how to use
Constatnt fields. I have problems with that.

Thanks

The documentation for the java.lang.Character class
can be found at this link:

<http://java.sun.com/javase/6/docs/api/java/lang/Character.html>

The table titled 'Field Summary' contains a list of the public
fields of the Character class. These are all declared
public static final - in effect 'constant fields'.

Because these fields are declared static you will not need
a Character instance to use them.

char c = java.lang.Character.MIN_VALUE;
 
L

Lew

Jeff said:
The documentation for the java.lang.Character class
can be found at this link:

<http://java.sun.com/javase/6/docs/api/java/lang/Character.html>

The table titled 'Field Summary' contains a list of the public
fields of the Character class. These are all declared
public static final - in effect 'constant fields'.

Because these fields are declared static you will not need
a Character instance to use them.

char c = java.lang.Character.MIN_VALUE;

Because Character is in the java.lang package, you will not need a package
reference to use it.

char c = Character.MIN_VALUE;
 
J

Jeff Higgins

Lew wrote
Because Character is in the java.lang package, you will not need a package
reference to use it.

char c = Character.MIN_VALUE;

Oops! Thanks for the correction.

michalfabisiak, I apologise for the misinformation.
Please use the corrected syntax given by Lew.
 
S

Stefan Ram

Jeff Higgins said:
michalfabisiak, I apologise for the misinformation.

Your first answer was correct, because it will always work
under Java SE. The »java.lang.« can be omitted only if there
is no »Character.class« in the classpath. For example, when

class Character {}

is being added to a source file, this source file will still
be perfectly legal Java, and your first solution will still work.

It will not work anymore, when »java.lang.« is being omitted.

When you do not know, whether someone has »Character.class« in
his classpath or might add this later, the general answer uses
»java.lang.Character« or »import java.lang.Character;« at the
start of the compilation unit.
 
L

Lew

Stefan said:
Your first answer was correct, because it will always work
under Java SE. The »java.lang.« can be omitted only if there
is no »Character.class« in the classpath. For example, when

class Character {}

is being added to a source file, this source file will still
be perfectly legal Java, and your first solution will still work.

It will not work anymore, when »java.lang.« is being omitted.

When you do not know, whether someone has »Character.class« in
his classpath or might add this later, the general answer uses
»java.lang.Character« or »import java.lang.Character;« at the
start of the compilation unit.

That is not correct.

Classes are retrieved from the classpath based on the fully-qualified name
(FQN). Unless the class is also "java.lang.Character", this situation will
not occur, and if it is, using the FQN obviously is no use anyway.

So ignore all that about the classpath.

We are assuming that your class is not in the default package, and that your
classpath does not include any classes in the default package. Such a
situation is pathological and to be avoided anyway. (It's especially
pathological to craft a classpath that includes classes in the default package
that have the same simple name as API classes.)

Just feel free to omit the "java.lang" package, or include it if you really
want to.
 
L

Lew

Lew said:
So ignore all that about the classpath.

We are assuming that your class is not in the default package, and that
your classpath does not include any classes in the default package.
Such a situation is pathological and to be avoided anyway. (It's
especially pathological to craft a classpath that includes classes in
the default package that have the same simple name as API classes.)

Actually, even that is not an issue:
The Java launcher, java, initiates the Java virtual machine.
The virtual machine searches for and loads classes in this order:
* Bootstrap classes - Classes that comprise the Java platform,
including the classes in rt.jar and several other important jar files.
Thus,
# It is relatively difficult to accidentally "hide" or omit the bootstrap classes.

So ignore all that about the classpath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top