Solved

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

Posted on 2004-08-29
10
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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 …

688 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