• Post Reply Bookmark Topic Watch Topic
  • New Topic

Logical Fonts -Spelling discrepencies  RSS feed

 
Robert Davis
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers:
In exploring the proper use of logical fonts, which are described as "Dialog", "DialogInput", "Serif", "SansSerif" and "Monospaced" I was presented with the question:
Assume all unseen code is correct. What will result from an attempt to compile and execute the following statement?

I expected the answer to be that the statement would not compile because of the spelling of "SanSerif", however to be sure I plugged it into an application and lo and behold it compliled and ran. A search of help from JBuilder9 and a review of Herbert Schildt's "Java 2: The Complete Reference - Fifth Edition" has shed no light on various spellings that are acceptable. At least in my environment, the following spellings all result in the same output:
"SansSerif" //Appears to be the standard spelling.
"SanSerif"
"San Serif"
"Sans Serif"
Can anyone give me an explanation. Particularly in regards to a proper response for a question like this on an exam.
TIA
Bob
[ January 21, 2004: Message edited by: Robert Davis ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, the compiler never looks inside String literals; any error due to misspelling has to happen at runtime. The compiler only checks types.
Second, I think you got lucky choosing SansSerif to do this test with. If the font family name or logical name isn't found, the javadoc for java.awt.Font suggests (read the whole thing) that "Dialog" is the default. Looking at {JDK}/jre/lib/font.properties on my machine, I see that the physical font for "Dialog" is LucidaSans, which is the same font for SansSerif. So misspelling SansSerif gets you the default, which is the same font!
Try misspelling "Serif" or "Symbol" and see what you get.
 
Robert Davis
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest:
Thank you for the prompt explanation. I suspected it was something like that but wasn't finding the right place for the answer. Is there and easy way (maybe a Java method) to find a machines default font?
Bob
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off the top of my head, I'd create a Font object using "Default" as the logical name, then call getFontName() on it (or getFontFamily() to get just the family name).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!