Solved

I am puzzled what "class Hello" is different from "class HELLO"

Posted on 2004-08-29
10
187 Views
Last Modified: 2010-03-31
My OS is WIN2000 Server

case 1:
filename:D:\Hello.java
public class Hello {
    public static void main(String[] args) {
            System.out.println("Hello,world!");
      }
}
D:\>javac Hello.java  --correct
D:\>javac HELLO.java  --correct
D:\>javac HeLLo.java  --correct

case 2:
filename:D:\Hello.java
public class HELLO {
    public static void main(String[] args) {
            System.out.println("Hello,world!");
      }
}
D:\>javac Hello.java  --error
            Hello.java:1: class HELLO is public, should be declared in a file named HELLO.ja
            va
            public class HELLO {
                     ^
            1 error
D:\>javac HELLO.java  --correct
D:\>javac HeLLo.java  --error
            HeLLo.java:1: class HELLO is public, should be declared in a file named HELLO.ja
            va
            public class HELLO {
                     ^
            1 error

The first is not case-sensitive,but the second is case-sensitive.
Why?
I wish you help me,thx~~~~~:)
0
Comment
Question by:candelaboy
10 Comments
 
LVL 92

Accepted Solution

by:
objects earned 25 total points
ID: 11928444
Java is case sensitive, Windows is not.
0
 
LVL 8

Expert Comment

by:thomas908
ID: 11928743
When u declare a class as public, the name of the class should be same as the file name.
0
 
LVL 8

Expert Comment

by:thomas908
ID: 11928757
In the first case both tha file name and public class name are same, so the is no problem.
As far as writing
D:\>javac Hello.java  --correct
D:\>javac HELLO.java  --correct
D:\>javac HeLLo.java  --correct

is concerned, u are writing javac commands from prompt and as objects mentioned that doesn;t make any difference because windows is not case sensitive.

But in the second case the name of file and public class name are different. Because it is java case does make a difference. If a class is public its name should be same as file name.Other way of doing it is to delete the public keyword and it'll work fine but it is not recommended
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:candelaboy
ID: 11928897
But why it is normal when javac below?The file name and the class name are different,but "javac HELLO.java" is correct.
------------------
filename:D:\Hello.java
public class HELLO {
    public static void main(String[] args) {
          System.out.println("Hello,world!");
     }
}
D:\>javac HELLO.java  --correct
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 25 total points
ID: 11928965
Correction you all: MSWindows IS case-sensitive, but very tolerant when accessing a file by name.
MSDOS was not.
It is not only JAVA that has problems with misspelled cases in filenames.
;JOOP!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11928977
Bottomline: to make sure it works on every platform, stick to the rule that the class-name and file-name should be the same, with regards to case.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12341156
Yep.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now