Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4237878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:49:54+00:00 2026-05-21T02:49:54+00:00

After years of Java develoment, I was shocked to learn that the compiler doesn’t

  • 0

After years of Java develoment, I was shocked to learn that the compiler doesn’t check if the package name really is the one corresponding to the Java source file’s path.

You can write this:

package abcd; 
class Xyz {
}

and it will compile even is Xyz.java is located in efgh folder. I get a warning while editing the file in Netbeans, but that’s about it. In fact, this had led to a bug that was very difficult to spot: http://netbeans.org/bugzilla/show_bug.cgi?id=197320

Any way to get warnings or errors anyway?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:49:55+00:00Added an answer on May 21, 2026 at 2:49 am

    With gnu-find, you can search a whole project. cd to the project source root, and then:

    find PROJECT -type f -name "*.java" -exec ./pmatchd.sh {} ";"
    

    You need the pmatchd.sh – script:

    #!/bin/bash
    #
    dir=$(dirname $1)
    d=${dir//\//.}
    headline=$(head -n1 $1) 
    p=${headline#package }
    if [[ $d";" != $p ]]
    then 
        echo "mismatch: " + $d " " + $p + " " + $1
    fi
    

    If you like it, you will move it to a location in the path, not in the $PWD.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After programming with C# and Java for many years I finally decided to learn
After years of ASP.NET development I'm actually quite surprised that I can't seem to
After some years of experience in the field, it seems to me that the
Using Getting back up to speed on Java after 8-10 years as a starting
I'm about to jump into Java development again after a number of years. The
After five years of professional Java (and to a lesser extent, Python) programming and
after some years in Java and C# now I'm back to C++. Of course
I'm new to Java after working for a few years in PHP and I'm
I'm after a book to learn about the internals of the Java virtual machine.
I'm an experienced Java programmer that for the last two years have programmed for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.