Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

Java

Thread view: 
michalfabisiak@gmail.com - 28 Dec 2007 20:27 GMT
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
Wildemar Wildenburger - 28 Dec 2007 20:46 GMT
> 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
Owen Jacobson - 28 Dec 2007 22:22 GMT
On Dec 28, 12:27 pm, michalfabis...@gmail.com 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.

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.
Jeff Higgins - 28 Dec 2007 23:01 GMT
michalfabisiak wrote
> Hello,
>
[quoted text clipped - 4 lines]
>
> 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;
Lew - 29 Dec 2007 02:23 GMT
> The documentation for the java.lang.Character class
> can be found at this link:
[quoted text clipped - 9 lines]
>
> 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;

Signature

Lew

Jeff Higgins - 29 Dec 2007 11:38 GMT
> Jeff Higgins wrote:
>>
[quoted text clipped - 4 lines]
>
> char c = Character.MIN_VALUE;

Oops!  Thanks for the correction.

michalfabisiak, I apologise for the misinformation.
Please use the corrected syntax given by Lew.
Stefan Ram - 29 Dec 2007 14:57 GMT
>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.
Lew - 29 Dec 2007 15:24 GMT
>> michalfabisiak, I apologise for the misinformation.
>
[quoted text clipped - 13 lines]
>   »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.

Signature

Lew

Lew - 29 Dec 2007 15:28 GMT
> So ignore all that about the classpath.
>
[quoted text clipped - 3 lines]
> 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:
<http://java.sun.com/javase/6/docs/technotes/tools/findingclasses.html>
> 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.

Signature

Lew

Roedy Green - 09 Jan 2008 12:09 GMT
>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.

see
http://mindprod.com/jgloss/constant.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.