Solved

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

Posted on 2004-08-29
10
195 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

776 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