Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p><strong>Packages</strong> provide <strong>logical</strong> namespace to your classes..</p></li> <li><p>And these packages are stored in the form of directory levels (they are converted to nested <strong>directories</strong>) to provide <strong>physical</strong> grouping (namespace) to your classes..</p></li> </ul> <p>Also, note that the <code>physical</code> namespace has to be in accordance with the <code>logical</code> namespace.. You <strong>can't</strong> have your class with <code>package com.demo</code>, under directory structure : - <code>\com\demo\temp\</code>, <strong>it has to be</strong> under <code>\com\demo\</code>, and this directory is added to the <strong>classpath</strong> so that your classes is <strong>visible</strong> to JVM when it runs your code..</p> <p>Suppose you have following directory structure: - </p> <blockquote> <p>A<br/> |<br/> +-- Sample.java(contains <strong>Demo</strong> class under <strong>package B</strong>)<br /> |<br/> +-- Outer.java(contains <strong>Demo</strong> class - no package)<br /> |<br/> +--B<br/> | &nbsp;&nbsp;&nbsp;| <br/> | &nbsp;&nbsp;+-- Demo.class <br/> | <br/> +--C <br/> | &nbsp;&nbsp;&nbsp;| <br/> | &nbsp;&nbsp;+-- Abc.class <br/> |<br/> +-- Demo.class<br/></p> </blockquote> <p>Suppose, your class <code>Abc.class</code> and <code>Demo.class</code> (under directory A), isn't define under any package, <strong>whereas</strong> your class <code>Demo.class</code> (under directory B) is defined under <code>package B</code>. So, you need to have two directories in your classpath: - <code>\A</code>(for two classes: - <code>Demo.class</code> and <code>B.Demo.class</code>) and <code>\A\C</code>(for class <code>Abc.class</code>)..</p> <ul> <li>Classes under different package can use same name. That is why there won't be any conflict between the two <code>Demo.class</code> defined above.. Because they are in different <code>packages</code>. That is the whole point of dividing them into <code>namespaces</code>.. This is beneficial, because you will not run out of unique names for your classes..</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload