Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old August 31st, 2010, 12:37 AM
Registered User
Join Date: Aug 2010
Location: toronto
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default java and unicode confusion

trying out an example in this book (apologize for all the nested ifs):
public class LetterCheck {
 public static void main (String args[]){
  char symbol='A';
  symbol= (char)(128.0*Math.random());

  if (symbol>='A')
   {if (symbol<='Z')
     {System.out.println("Char is a capital letter: "+symbol+" - "+(double)(symbol));}
     {if (symbol>='a')
       {if (symbol<='z') 
         {System.out.println("char is a lowercase letter: "+symbol+" - "+(double)(symbol));}
         {System.out.println("Char is greater than a but not a letter: "+symbol+" - "+(double)(symbol));}
       {System.out.println("Char is between Z and a: "+symbol+" - "+(double)(symbol));}
  else {System.out.println("Char is less than A: "+symbol+" - "+(double)(symbol));}}}
the console output is writting non-printable characters like 21 (NAK) in some symbol that i cant find on any ASCII table. im just wondering what agent specifically is responsible for this.

also, when i save my source code in wordpad with a filetype of unicode text document it doesnt compile. if java supports unicode why is this even happing?

i really want to understand completely the issues here, so if you know of any links that would enlighten me with a full explanation i would greatly appreciate it. im sure this has been asked before, i just cant find the answer.

thanks so much!
Reply With Quote
  #2 (permalink)  
Old October 25th, 2010, 12:04 PM
Registered User
Join Date: Oct 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

The last bits
         {System.out.println("Char is greater than a but not a letter: "+symbol+" - "+(double)(symbol));}
       {System.out.println("Char is between Z and a: "+symbol+" - "+(double)(symbol));}
  else {System.out.println("Char is less than A: "+symbol+" - "+(double)(symbol));}}}
You should not print the symbol as it will probably contain a control character which will mess you display up
Remove all the "+symbol+" bits
You also seem to have a misunderstanding about casting (double)(symbol) bits
println & indeed anything expecting a String type will perform a toString() if it can
Also casting is between numeric types only, it has nothing to do with String!

Do not use Wordpad, either use notepad or try some other simple text editor, wordpad is a mini wordprocessor (I use Notepad++ from sourceforge)
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Confusion with terminology... vb89 XML 5 May 7th, 2010 06:36 AM
Errata confusion morganstein BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 0 October 10th, 2008 05:11 PM
Class' Confusion dpkbahuguna Beginning VB 6 4 September 20th, 2006 11:16 PM
Some confusion in these code hpatel_it ASP.NET 1.0 and 1.1 Basics 0 August 30th, 2006 08:19 AM
.net Confusion reyboy General .NET 1 December 29th, 2004 07:35 AM

All times are GMT -4. The time now is 02:56 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.