Hi. I'm new to java programming. I have some questions:

1) Does every java source code's class name (the name after the class keyword, e.g. class Hello) has to be started with an uppercase character?

2) Does the java source code's file name (e.g. Hello.java) has to be exactly the same with its class name (e.g. class Hello)? Can the class name started with an uppercase character and the java source code's file name started with a lowercase character?

Help me..

Hi. I'm new to java programming. I have some questions:

1) Does every java source code's class name (the name after the class keyword, e.g. class Hello) has to be started with an uppercase character?

2) Does the java source code's file name (e.g. Hello.java) has to be exactly the same with its class name (e.g. class Hello)? Can the class name started with an uppercase character and the java source code's file name started with a lowercase character?

Help me..

1) No, it's not required, but it's convention to have all class names start with a capital letter. You can have a class called hello in a file called hello.java, then compile it and get hello.class and it'll run fine. But again, the naming convention is to start it with a capital letter, so you should to make your code more readable to other programmers. But the compiler doesn't care.

2) Yes. Class hello and class Hello are two different classes. Class hello should be in a class called hello.java. Class Hello should be in a class called Hello.java. Case counts.

[edit]
For number 2, this only applies for PUBLIC classes. You could have a class called hello in a file called Hello.java, but class hello couldn't be public.
[/edit]

thank you so much. :)

Hi. I'm new to java programming. I have some questions:

1) Does every java source code's [B]class name[/B] (the name after the [I]class[/I] keyword, e.g. [I]class[/I] [B][I]Hello[/I][/B]) has to be started with an uppercase character?

2) Does the java source code's file name (e.g. Hello.java) has to be exactly the same with its class name (e.g. class Hello)? Can the class name startedth an uppercase character and the java source code's file name start with a lowercase character?

Help me..

Dear Friend,

               Java filename should start with a capital letter. And it must match the name you have given to the class. If you have given the name, for example:

class Sample {
// Body
}

Then the .java must be saved with the name "Sample.java". This is a must. We mormally give java programs the name of the class as its title. The first alphabet of the Java classes are written in capital letter. It is a universally accepted rule. It is better you follow it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.