Solved

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

Posted on 2004-08-29
10
177 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
Comment Utility
Java is case sensitive, Windows is not.
0
 
LVL 8

Expert Comment

by:thomas908
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:candelaboy
Comment Utility
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
Comment Utility
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:mayankeagle
Comment Utility
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
Comment Utility
Yep.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countAbc challenge 9 49
@SBGen Method 3 25
advertisement module in core php 4 79
eclipse java  build path 6 18
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

743 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

8 Experts available now in Live!

Get 1:1 Help Now