Are there non-public classes in Java SDK?

Or are ALL classes in all packages of the Java SDK public?
I have looked in the sources spot checking and didn't find a non public (default) class.
If all classes are public, why?
There exists a means in Java language to define a class as default ("class MyClass" instead of "public class MyClass") visibility. So why isn't it used by Java SDK (if this is really true)?

I dont know what language you're programming in.
If you don't specify
public class
or
private class
the class is "protected".
Read the spec.If you read the spec, you'll see that, with respect to a class:
(per section 6.6.2) Classes from outside the package the class lives in that extend the class have access to protected members.
(per section 6.6.5) Classes from outside the package this thing lives in that extend this class do not have access to default members.
Relevant part of section 6.6.5 (Example: Default-Access Fields, Methods, and Constructors) is:
If none of the access modifiers public, protected, or private are specified, a class member or constructor is accessible throughout the package that contains the declaration of the class in which the class member is declared, but the class member or constructor is not accessible in any other package.
This is default access, not protected access
Lee

Similar Messages

  • Question about access non-public class from other package.

    Hi, everyone!
    Suppose class A and class B are in the same java file of package pkg1
    -- A.java. So, A is a public class and B is a non-public class.
    If I want to access class B from another class class C and class
    C is in package pkg2. When compiling, an error occurs indicating
    that class B is not visible to class C.
    So, If I defined serveral classes in one java file and I want to
    access every class from other package. How should I do?
    (I think in one java file, there should be only one public class and
    only the public class can be accessed from other package.)
    Thanks in advance,
    George

    So, If I defined serveral classes in one java file and
    I want to
    access every class from other package. How should I
    do? As you already seem to know, there is at most one public class allowed per source file (at least, with javac and most popular compilers). So if you want more than one public class, you will need to use more than one file...

  • Public main method in a non-public class

    Hi,
    It is said that main method in a java class must be public so that it can be invoked by JVM. This works even if the class itself has default modifier.
    But while programming, any method (be it public) of a class with default access modifier from one package can't be accessed by classes from other packages. For example,
    1. Consider class A in package a.
    package a;
    class A {
    public void methA() {}
    2. Now consider class B in pakage b.
    package b;
    class B {
    void methB() {
    // Here it can't access class A and its method methA()
    So how does JVM invoke the main method of a class with default access modifier. Assume that the class is in some package a.b.c
    Regards,
    Amit

    Hi,
    Maybe this can also be beneficial for you.
    Standalone applications don't necessarily have init and start methods. They must have a public static void main routine to start things off. The main routine typically creates some object of the master class. It can't use any non-static variables or methods in the class with the implied this, since there is no this object. It typically quickly returns. Then the event loop processing starts. Even the static main method must live inside some public class, or at least in the top class, the first class and the class for whom the source file is named. There are no such thing as standalone static methods in Java. The signature of the main class must look exactly like this. Cut and paste it to be sure:

  • If we are migrating from JRC to CR Java SDK, do we need RAS or any server

    Current situation
    e already have lots of clients running our product. We are using JRC to show the reports. Reports are designed in Crystal Reports Designer and hosted in the J2EE application servers. No modification/updating of these reports are needed from the client side. No need to create either full or part of the reports on the fly.
    Only thing we do on the report other than just calling the viewerSDK to view, is: we read the parameters from the (designed/hosted) report to do parameter prompting in our own custom JSP. We went to create our own JSP to prompt for report parameters, because, using JRC SDK, for some reason we were unable to get dynamic (drop-down) parameter showing the list of values. These dynamic parameters are list of values, user choose one. So these parameters are linked to a command with simple SQL like (select col1, col2 from table1).
    Current API ???
    I think we have this free JRC SDK. We have a directory called crystalreportviewers115 in our product deployment plus some JARS like (CrystalReportEngine.jar, CrystalCommon.jar, CrystalCharting.jar, CrystalExporters.jar, CrystalExportingBase.jar, CrystalDatabaseConnectors.jar, CrystalFormulas.jar, CrystalQueryEngine.jar, CrystalReportingCommon.jar, rasapp.jar, rascore.jar, ReportViewer.jar, etc) in our appserver j2ee classpath.
    Now there are two choices:
    1. Let crystal report viewer handle itself the parameter prompting; Then, I do not know if it is possible with this free JRC SDK or anything else that is open source. If it is possible with some upgrading can you please let me know some tips to goahead.
    2. Finding a way to read the parameter details like the SQL command, etc, so that we can show it in our JSP. I do not know if we still need to upgrade to a different version of SDK.
    I tried looking for a different or newer SDKs... It is confusing with  things CR for Eclipse, CR Java SDK, etc. Do not know which direction to go!!!
    Can someone guide me please.

    CR Java SDK consists of JRC + Veiwers Java SDK.
    CR Eclipse 2.0 is latest IDE in which CR 2008 features are integrated.
    There are different set of JRCs for different versions of Crystal Reports. But for CR 2008 there is no separate JRC has been launched yet, instead CR4E 2.0 Java SDK has been launched which is free.
    For more details about CR4E 2.0 please check out this link
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/90f635e1-d0c4-2b10-559d-802a95c0d456
    Thanks,
    Tej

  • Why only 1 public class in java file

    In any java file, why do we have only one public class whose name is same as the java file name?

    Jasmit1986 wrote:
    Thanx for the link db. But in the link it is explained why we have the name of the java file same as the class name.
    My doubt is that why can't we have more than one public class in a java fileTo keep things simple and less confusing. There's really no good reason to have multiple public classes in one file, so this just enforces the "best practices" idea.

  • Are there non-breaking hyphens in Pages '09?

    In some programs, like Adobe InDesign, you can do a find and replace for "regular" hyphens and replace them with non-breaking hyphens. Is this an option in Pages? I don't see anything like that described in the Help file.
    Thanks,
    Richard

    as I insert the character it seems to alter line interspacing from the previous line.
    That may indicate that the font you are using does not contain 2011, so another font with different vertical metrics gets used instead. You can see which fonts contain this character by selecting it in Character Viewer and looking in the Font Variation pane there.

  • Are there any traning classes for the I-Pod Touch

    On basic usage.

    You can refer to the iPod touch user guide found in Safari/Bookmarks.
    There are also many websites, such as this one that offer full lessons on your device.

  • Are there any ipod classes or phone support besides apple?

    Like many people I'm trying to get dvd movies to watch on my ipod. I've looked up and down this board for two days which has been somewhat helpful but I have yet to be able to rip my dvd and put it on my ipod. I'm sick of wasting entire days on this problem. I would happily pay for a class or some phone support besides apple which does not support this problem. What the f#!k I've already spent a fortune in time with no end in site. Also it would be nice to get the hang of all the features without having to suffer through the frustrating of having to figure it out one post at a time. I think I would just sell my ipod if it wasnt a gift.

    The IPOD was designed and is sold to support video content available through the Apple Store. Apple never said they would support every video converting program made by anyone trying to make a buck or freeware that confuses 98 percent of its users. Getting videos on the IPOD is not hard. For a 40 dollar investment, you won't even need to search on any web site for your answer. And flash the company even has a trial to download and flash they have been in business for over 5 years and have made convertors to support over 265 different devices and lastly they have an actual support site manned by folks that designed the programs. I do understand your frustration, but when you look in the wrong places for so long you will get frustrated. The product is great! And does what it was advertised to do!

  • Are there iPad MINI CLASSES at Genius Bar

    I have just got an iPad Mini for Xmas.  I already have a IPad.  I have never had any Apple Store Genius Bar classs, howver I know that they do make these available for other Apple hardware/software programs.  I life in Seattle.  Does our Alderwood Mall Apple Store offer sessios for those or us that want a structured class.  Thank you for help with this matter.
    Sheryl Harris
    [email protected]
    206-852-3985 iPhone cell phone number

    Start here:
    http://www.apple.com/retail/alderwoodmall/
    Remember an general class on iPads or iOS will answer many of
    your questions. It need not be a class specifically for iPad mini.
    If no classes fit your need, check the other Seattle locations.

  • Why is the name of java file is same as public class?

    hello friends
    why we need to assign same name to .java file as the name of public class in .java file? while its not necessary for the class having no modifier?

    This question has been asked several times. Serch the forum.
    x

  • Two public classes in one source file

    Can anyone please explain what is the exact reason why the java source file name should be same as the only allowed public class name in the source file. Answer only if you know the correct answer. No gusses please. I read the other postings on this topic. None of the answers were correct.

    One reason is that some RISC processor architectures
    (like those Sun uses mostly) have hierarchical memory
    architectures. This hierarchy is divided into global
    modules and local (global-accessible) submodules. The
    advantage of this is that the processor needs lesser
    memory access "points" (handles), as the modules
    delegate CPU calls to the submodules.
    The java compiler can utilize this and increase
    performance by loading the entire source files into
    the memory and assign them a CPU handle (the module
    ID). It'll be later used for linking, e.g. The public
    class in a file will be loaded as a module and gets
    the handle, all other non-public classes in that file
    will be submodules.
    If there is no public class, a generic module will be
    used, so that's no problem. But if there are multiple
    public classes, you'd end up with several modules and
    just one handle to assign, thus having ambiguity. The
    CPU won't be able to address the correct module.
    This all only applies to RISC CPUs, but for obviuos
    cross-platform compatibility reasons it was added to
    the standard - it doesn't hurt the other
    architectures, but helps those with hierarchical
    memory management.Thanks, but the rooster explanation makes more sense to me.
    Now could someone please express it a la Majinda?

  • Public class SodaCan{ etc

    Here is the link to ANOTHER student + 'pls do my hwk Q/' and clearly a beginner who wanted to do a bit of comp calc/maths
    http://forum.java.sun.com/thread.jsp?forum=54&thread=301814
    Flame me if you will ... BUT:
    but it seemed to be a VERY MESSY way to teach java. If it were me then I would show them ...something like this firstmain() {
    declare doubles ddVOL, ddSURF;
    parse doubles x, y;
    ddVOL = Math.PI(formula with x, y);
    ddSURF = Math.PI(formula with x, y);
    DecimalFormat method();
    S.o.println(for ddVOL and ddSURF);
    } and cls
    ~ 8 lines, or so, of actual code.From what I saw of the code the student did paste, I don't think she or he has been taught how to do the above or could do the above - sorry, NOT just the indidividual - maybe the whole class (an assumtion). So to my questions:
    Why start with such laborious java, surely this is confusing for a beginner?
    This sort of procedural coding (see link pls), for me, came MUCH later. I just started implementing it without being aware of it and if you are to be a programmer, then this is what you do (I think ...). There are at least 4 types of student;-
    ONE: losers (forget them)
    TWO: They just want to get through the course and the 'scrape through' well we've met them here regularly enough (forget those ones)
    THREE: You pass, you do OK and in your work you need to implement and adapt a bit of script now and again, then I don't think the SodaCan would have helped you in any way.
    FOUR: and if you have any sort of interest or aptitude (or BOTH preferably), then you'll go on to be programmer of sorts and sooner or later you will return variables from your constructors/functions whether a boring lecturer confuses the hell out of you in the first few weeks of the course or not.
    Isn't there an argument for keeping it simpler than this ... or have I just lost the plot somewhere?
    (this is from a former teacher btw, so I am on the side of the confused student - IF they approach the question in the right way)

    Back to the original point, I agree that having a bunch of void methods doesn't really make much sense, but I think also that nearly every introductory text does this. Perhaps to make "engaging" examples such as RoachPopulation. But you're right, there's no excuse since returning references from methods isn't really significantly more advanced than what they're trying to do (arguably it's easier to grasp).
    To be honest, I really liked the concept of the RoachPopulation class, so I tried it out (I'm learning Java too, after all). I was pleased that I didn't make too many mistakes, one notable one is that the wait() method, which is a final method of java.lang.Object, isn't overrideable. So I renamed it, but you would think that the teacher would have known this...
    class RoachPopulation {
        int numRoaches;
        // constructor -- feed num of roaches as arg
        public RoachPopulation(int numRoaches) {
            this.numRoaches = numRoaches;
        // wait -- the roach population doubles!
        // a better name would be "populationDoubles", in fact
        // when I tried to compile this program, the compiler warned me that
        // wait() cannot be overridden from java.lang.Object !!
        public void populationDoubles() {
            this.numRoaches = this.numRoaches * 2;
        // spray -- kill some roaches
        // this should really be called "beSprayed"
        public void spray() {
            this.numRoaches = (int) (this.numRoaches * 0.9);
        // getRoaches -- how many are there?
        public int getRoaches() {
            return this.numRoaches;
        // main
        public static void main(String[] args) {
            // start a new roach family
            RoachPopulation roachmotel = new RoachPopulation(10);
            // loop three times
            for (int i = 0; i < 3; i++) {
                // breed!!
                roachmotel.populationDoubles();
                // attack!!
                roachmotel.spray();
                // survey the damage
                int numRoaches = roachmotel.getRoaches();
                // battle report
                System.out.println("Number of roaches after iteration "
                                    + i + ": " + roachmotel.getRoaches());
            if (roachmotel.getRoaches() > 10) {
                System.out.println("\n\n\nTHERE'S NO STOPPING THEM!!!");
    }

  • Why a public class name and file name same?

    All of us know that, a public class should be declared in a file which has the same name of that class. What is the underlying concept behind this..Can someone give a clear explanation?
    Thanx..
    Sandeep Joseph
    Paragon Solutions
    [email protected]

    Another issue, it was said that the file must be named
    after the class to find the class's code when
    compiling dependent classes. Doesn't this apply to
    non-public classes too (with the dependent class being
    located in the same package)?This applies to all top-level classes ...
    You can define multiple classes in one file though:
    class A {
    class B {
    }It's perfectly valid to have both classes defined in the same file (named A.java if A is the first class to be defined in that file).
    You will get a compiler warning as soon as you reference a non-top-level class from a class that is defined in another file, though.

  • Why do we need public classes?

    I read that a public class is more visible than a default (non-public) class as the latter is merely "package-visible". However, it appears that even if a class (c in package p) is not declared to be public, it can still be accessed by:
    1) p.c
    2) import p.c
    So what is the use of declaring a class to be public? Why can't we just write:
    class c {...}
    every time for every class without the modifier public.
    Can someone show me an example that illustrates the difference between a public class and a default class?

    I read that a public class is more visible than a
    default (non-public) class as the latter is merely
    "package-visible". However, it appears that even if a
    class (c in package p) is not declared to be public,
    it can still be accessed by:
    1) p.c
    2) import p.c
    How does that appear so?
    Trying to do it the compiler says that "p.c is not public in p; cannot be accessed from outside package" and does not generate a class file.

  • Are there other iLearning discussion forums?

    I've just been asked to help install/deploy iLearning in a Linux environment. The purchase hasn't happened yet so I'm not aware of/nor have access to any detailed iLearning installation guide, but if possible i'd like to get a head start since I am not familiar with Oracle products (I've been developing primarily with PHP/MySQL).
    Are there any publicly available installation documents for iLearning on a Linux platform?
    Anyone else here using iLearning on Linux and care to share their experiences?
    Also, since this forum is pretty quiet, are there more active discussion forums covering iLearning?
    many thanks in advance!

    The install guide for Oracle iLearning is available through Metalink, our customer support web site.
    There is a forum on metalink as well as a discussion forum on our Oracle iLearning customer site:
    http://ilearning.oracle.com
    Click Self-Register
    When asked for the site name, enter "ilearning"
    Create your account
    Perform a search in the catalog for "Forum"
    Subscribe to the Oracle iLearning Product Information forum.
    There is not very much activity there either however, but as questions are asked the product management team attempts to answer them or other customers may respond as well.
    Thanks!
    Scott

Maybe you are looking for

  • Problems with installation SAP Netweaver ABAP 7.0

    Hello, can someone give me an adice on installing SAP NetWeaver ABAP 7.0 trial version, please? After installing the application server and SAP management konsole and stopping the application server following message pops up. The same message pops up

  • Why is the capacity of my ipad 28gb

    why is the capacity of my ipad 28gb

  • Unable to connect to Oracle 9i from Forms 6i

    Hi, I have Oracle 9.2.0 (Personal edition) and Forms 6i installed on a Win2K PC. I am able to connect to the DB from SQLPLUS. But, I am unable to connect to the DB from Forms 6i. Can anyone suggest where am I going wrong and what is that I need to do

  • Safari problems with iPhone4

    i keep getting this problem when i use safari on my iphone 4 and it happens on both wifi connections and 3G connections. i will be viewing a site example wikipedia, and then i will click on a link on the page to view more info on the topic and it wil

  • IOS 5.0.1 Update - Battery Problems

    My iPod touch 4 battery life keeps dropping too quickly, after updating it to iOS 5.0.1, the update released a few days ago. Why does this happen? The iPod had a fairly consistent battery before this update, so I am sure that this is not beacuse of t