File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes :rolling: Innovative functions !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ":rolling: Innovative functions !!!" Watch ":rolling: Innovative functions !!!" New topic
Author

:rolling: Innovative functions !!!

raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135


The above code compiles & runs fine.


live
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please tell us the point you are trying to make.
Moving into Java In General (Beginner)....
[ March 07, 2007: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100


Now it doesn't compile. Shows errors as follows:




RAGHU<br /> <br />"When the going gets tough, the tough get going"
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hey, I'm surprised that compiled at all. I can't tell if you were confused by it or amused for the same reason I was surprised - class names are not reserved words.

For example:

defines a method with a single argument of type String and name String.

This line

is looking for a method with two String arguments like

with two arguments of type String, named one and two.

One can write pretty silly looking programs in REXX, too. It has no reserved words, only keywords in context. This says "5" three times:

Not a recommended style.

[ March 07, 2007: Message edited by: Stan James ]
[ March 07, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100


Now it compiles.

output is:


Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100

Originally posted by Stan James:
I can't tell if you were confused by it or amused for the same reason I was surprised - class names are not reserved words.


Isn't this a kind of a drawback of java which eats into the readability of the code? An example is the class shown in this thread


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Originally posted by Rao Raghu:
Isn't this a kind of a drawback of java which eats into the readability of the code?


I would say that it would reflect badly on the author of such code more so than the language itself.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16



[My Blog]
All roads lead to JavaRanch
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The way we usually avoid that is: class names start with a capital letter, variable names do not. So something like

Class class = Class.getClass();

is perfectly clear.

Time shifting compilers are very difficult so only the most advanced languages prevent you from making a variable name match the name of a class that you haven't written yet. They also warn if you write a bug that will be found later. Tony could probably fill us in on those.

Ok, it's not quite 4/1.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Class class = Class.getClass();
Not quite. You have forgotten that "class" is a keyword (and reserved work).
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Right you are. I really hate seeing variables named clazz and clzzzz so I should have remembered that.
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100

Originally posted by Stan James:
class names start with a capital letter, variable names do not


This is just a convention. Even otherwise the class will compile and run fine. We are not bound in any way to follow the convention. The bottom-line is 'why should the language allow us to use class names as variable names in the first place?'



Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Rao Raghu:


This is just a convention. Even otherwise the class will compile and run fine. We are not bound in any way to follow the convention. The bottom-line is 'why should the language allow us to use class names as variable names in the first place?'





The language allows us to do all sorts of things that are unhelpful, bad, dangerous, difficult to maintain, stupid, pointless, confusing etc. This is true of all programming languages. As Bear has already said, this really reflects badly on the programmer not the language. If you give someone a hammer and he uses it to hit himself on the head, is it the hammer's fault he's able to hurt himself?
[ March 12, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100

Originally posted by Paul Sturrock
If you give someone a hammer and he uses it to hit himself on the head, is it the hammer's fault he's able to hurt himself?


I got your point , Paul.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: :rolling: Innovative functions !!!
 
Similar Threads
Khalid's question on Inner class
i need a simple programs
abstract
"super" question (Mughal 6.6)
Overriding