File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes what does this command mean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what does this command mean" Watch "what does this command mean" New topic

what does this command mean

sriveena nori

Joined: Jul 22, 2008
Posts: 1
char ch=(char)-1;
why should we subtract 1from char and assing it to char
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42954
Welcoem to JavaRanch.

There's no subtraction here. The number "-1" is cast to a "char" - which is a Java data type. The cast is necessary because generally an integer number can't be assigned to a char. The interesting question is which character is being assigned here; can you guess which one it is, or which character code it has?
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171
You are converting the int -1 to char

[edit]to slow...[/edit]
[ July 22, 2008: Message edited by: Manuel Leiria ]

Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
subject: what does this command mean