Solved

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

Posted on 2004-08-29
10
211 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android development question 2 80
Convert from a json string array to a Java object 3 64
Java program running SQL query 5 48
Java Inheritance super keyword use 8 38
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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 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