Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

class naming and package naming

 
Ranch Hand
Posts: 40
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I was going through the naming conventions in the packages topic of SCJP 6 of K&B book

According to wat i read and wat i understood if we are working in some organization name for the Package will be first the domain name comes first and then the company name
For ex.Package name will be like com.geeksanonymous.steps.client

Then the class name will be com.greeksanonymous.steps.client.utilities according to him

but i just checked in compiler by writing program it's giving error in the class name part for using " . ".Y its so ? is that wrong?

And one more thing according to the the legal identifier rules the identifier must not contain " . " symbol know .But the name of the package and class name comes under identifier only . Is i am correct ?

please clarify me

Thank you
 
Rancher
Posts: 1090
14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code here?

Post all the lines in the code including the package statement.

Class names or any identifier name in Java cannot have a ".".

You might want to refer to the API docs for more information on
the rules ( what is legal ) and conventions for creating class names and identifier names.
 
Chan Ag
Rancher
Posts: 1090
14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fully qualified name of a class, example java.lang.Object, can contain a dot.
But do not confuse it with the class name, i.e the .class file name.
java and lang in the case of java.lang.Object are subdirectories in which the file Object is present.

But the file (Object.java ) name, cannot have a dot ( qualified classnames are not allowed ).
That means you can't have a file called abc.def.java, meaning you can't declare
the following class --


 
Ranch Hand
Posts: 1183
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Day,

Naming Conventions speaks to that...

Regards,
Dan
 
Sreevathsa Ramesh
Ranch Hand
Posts: 40
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chan Ag wrote:Can you post the code here?

Post all the lines in the code including the package statement.

Class names or any identifier name in Java cannot have a ".".

You might want to refer to the API docs for more information on
the rules ( what is legal ) and conventions for creating class names and identifier names.



Thanks for your reply.

The below paragraph which i have highlighted is taken from the K&B book where i found some doubt.

Java is a package-centric language; the developers assumed that for good organization and name scoping, you would put all your classes into packages.They were right, and you should. Imagine this nightmare: Three different programmers, in the same company but working on different parts of a project, write a class named Utilities. If those three Utilities classes have not been declared in any explicit package, and are in the classpath, you won't have any way to tell the compiler or JVM which of the three you're trying to reference. Sun recommends that developers use reverse domain names,appended with division and/or project names. For example, if your domain name is geeksanonymous.com, and you're working on the client code for the TwelvePointOSteps program, you would name your package something like com.geeksanonymous.steps.client.That would essentially change the name of your class to com.geeksanonymous.steps.client.Utilities. You might still have name collisions within your company, if you don't come up with your own naming schemes, but you're guaranteed not to collide with classes developed outside your company (assuming they follow Sun's naming convention, and if they don't, well, Really Bad Things could happen)

The dark red which i had done is the paragraph which is in the K&B

The dark blue part which i highlighted is the package name .In that my doubt is the name of the package come's under identifier or not? if identifier we cant use " . " as i learnt from the legal identifier rules and one more thing if its identifier if i use any number like com.geeksanonymous.steps.1client it is giving error.Y is that wrong according to identifier rules we can use number in between

Coming to class name which i have marked in green how can they use " . "?

Please help me over this .

I am struck with this

if i am wrong in understanding the sentence please tell me the correct one

Hoping for your response

Thanks
 
Sreevathsa Ramesh
Ranch Hand
Posts: 40
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Drillich wrote:Good Day,

Naming Conventions speaks to that...

Regards,
Dan


Thanks for your information ..

Please look to the post which i have done ..and clarify my doubt

Thanks
 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To create a class called com.geeksanonymous.steps.client.Utilities (in the way that text means) you don't do this:

You do this:
So the '.' does not appear in the declared class name.
 
Sreevathsa Ramesh
Ranch Hand
Posts: 40
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:To create a class called com.geeksanonymous.steps.client.Utilities (in the way that text means) you don't do this:

You do this:
So the '.' does not appear in the declared class name.



Thanks alot ..It helped me alot

Now i got it clear with what that sentence is about.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic