What is top level class declaration in java?

What is top level class declaration in java?

The declaration of a class that's not nested inside any other class.

Similar Messages

  • Declaring top level classes instead of subclasses

    I seem to have misunderstood something very basic.
    It's always better, where possible, to declare the top-level class instead of the sub-class, right?
    Ok, then why do I have the following problem?
    I declare, from the JavaMail API the following:
    Message theMessage = new MimeMessage(session);instead of declaring directly the subclass like this:
    MimeMessage theMessage = new MimeMessage(session);but when I use a method which is only found in the MimeMessage class I get a compile error.
    [javac] 189.           theMessage.setSubject(subject, "iso8859_1");
    [javac] <-------------------------------->
    [javac] *** Error: No match was found for method "setSubject(java.lang.String, java.lang.String)".
    Have I really misunderstood something so basic?? Surely the compiler knows that theMessage is an instance of MimeMessage??
    Any clear explanation to explain why I get this compile error would be gratefully received. I have been faithfully declaring top-level classes instead of subclasses in my code, but if the compiler doesn't let you do so, then what's the point?

    Ok, my confusion was started by an article on the
    Collection classes which stated that:
    Map theMap = new HashMap(); was better
    programming practice.
    Yep.
    But the Map class is an Interface, right? - Whereas
    Message is a normal class with subclass MimeMessage.
    I think that's where my confusion started.Well, this isn't really a class vs. interface difference. It goes to which class (or interface) is the "highest" (closest to Object) and still has all the public interface you need.
    There are cases where you'll declare a variable to be of a base class type like Message.
    You just need to get into the habit of separating the left side of the = from the right side. On the left, you put the bare minimum that completely meets your needs. You say, "I need a List" or "I need a Map" or "I need a SortedMap" (a subinterface of Map) or "I need a Message" or "I need a MimeMesage".
    Then, on the RHS =, you decide which particular class best implements the public interface that you said you need (by declaring it on the LHS). "For my Map, I'll use a HashMap." "For my Message, I'll use a MimeMessage." "For my MimeMessage, I'll use a MimeMessage".

  • What makes a class a "top-level" class?

    1.
    2.    public static int getThis() {
    3.      int x = 4;
    4.      int y = 5 * x;
    5.      return y;
    6.    }
    7.  }
    8.
    9.  public class NetGro extends ToNet {
    10.    public static void main(String args[]) {
    11.      int z = getThis();
    12.      System.out.println("Z = " + z);
    13.    }
    14.  }At line 1 of this program, ToNet "can only be declared as public or the default of no modifier" (not private or protected) because it's a "top-level class." What makes ToNet a "top-level class?"

    A class or interface is 'Top-Level' if it is not nested inside another class or interface.
    Otherwise the class would not be visible... Private and Protected for classes and interface only make sense within another class or interface as inner classes or interfaces.
    Hope that helps...

  • Top level class ?

    hi,
    i am preparing the sun certified java progammer, there's some questions involving "top level class", i don't understand what is a top level class ? can anyone give me some information about it ? is it a class at the top of a package hierarchie like class Object ????
    thanks for your help

    hi,
    i am preparing the sun certified java progammer,
    there's some questions involving "top level class", i
    don't understand what is a top level class ? can
    anyone give me some information about it ? is it a
    class at the top of a package hierarchie like class
    Object ????No. See
    http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#26783
    Jim S.

  • How to create top level classes

    what is the meaning of top level classes. and how to create toplevel classes.

    http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000188.html

  • Release memory for nested top-level classes

    Hello experts.
    I have a top-level class which consists of several static methods. Inside such a method I create several new instances of a nested top-level class inside my original class. Later I want to release one of these instances i.e. destroy instance and free memory. How can I do that?
    Thanks.

    sure, but I do not see any references to this nested top-level class. With "Releasing" I mean something like directly assigning a NULL value to the nested top-level clas in order to enable GC.
    But as I said there are no references and while monitoring the memory I see that the GC does not collect some memory. (I know that GC is not reliable, but after ten attempts of this scenario the memory allocation is equal the whole time).
    I guess the GC does not work with classes, but the classloader. But how can I control releasing memory in this scenario?
    Any further hints?

  • What are top-level workitems

    what are top-level workitems,i could see this check box in swwl tcode

    Any single task is a top-level item, and in addition any workflow work items that are not subworkflows are top-level items. It is explained <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/15/7fbf2e2e18d411b1320060b03c6bfb/content.htm">at help.sap.com</a>
    All work items are of course found in SWWIHEAD - not just the top-level items. Since both single tasks (type B or W) and multistep tasks (type F) can be top-level items you must identify them by their lack of a parent item. Specify WI_CHCKWI = (initial), that will return only top-level items.

  • Multiple top level package declarations

    The "Programming Adobe ActionScript 3.0" states in chapter 4 "ActionScript Language and Syntax", "Packages and Namespaces", "Creating Packages" that you can declare at the top level of a package multiple variables, functions, and namespaces in addition to a single class as long as only one is declared "public".
    However, in Flash when I declare a public class and any other variable or function either with the "internal" attribute or no attribute, I get this error:
    5006: An ActionScript file can not have more than one externally visible definition: test.function1, test.Test
    The package code is as follows:
    package test
        internal function function1():String
            return "Function1()";
        public class Test
    The same thing happens if I replace the function with an internal variable declaration. According to the manual, any declaration with the "internal" attribute should not be externally visible outside the package. Only the "public" class declaration should be externally visible.
    Can anyone clue me in as to why I get this error?

    That is not the situation described by the quoted manual section that I am trying to recreate.
    It clearly says:
    "In ActionScript 3.0, you use the package statement to declare a package, which means that you can also declare variables, functions, and namespaces at the top level of a package. You can even include executable statements at the top level of a package. If you do declare variables, functions, or namespaces at the top level of a package, the only attributes available at that level are public and internal, and only one package-level declaration per file can use the public attribute, whether that declaration is a class, variable, function, or namespace."
    The data properties and class you have decleared are outside the package within the ActionScript file, and not at the top level of a package. The "public" attribute is not available outside the package at all.
    What I wish to know is why the quoted internal declarations at the top level of the package generate the quoted error.
    However, I am beginning to believe that the documentation is in error and that what it is actually describing IS the situation you just described. When the manual says "top level of the package", it really means "top level of the ActionScript file outside the package", and when it says "the only attributes available at that level are public and internal", it really mans "the only attribute available outside the package declaration is internal. At the top level of the package, only one declaration may be made, it must have the same identifier as the ActionScript file name, and it can have either the public or internal attribute. Code within the same file but outside the package declaration can not access an internal declaration in the package declaration."
    Actually, the whole paragraph would need to be re-written to clarify the issue and to unambiguously distinguish between "top level of a package" and "top level of an ActionScript file outside the package declaration".
    As a concrete example - two ActionScript files:
    MCTest.as is saved in the same directory as MCTest.fla, and the document class of MCTest.fla is set to "MCTest".
    package
        trace("MCTest package code.");
        import flash.display.MovieClip;
        import test.Test;
        public class MCTest
        extends MovieClip
            trace("MCTest class code.");
            function MCTest()
                trace("Created Class MCTest: " + Test.StaticMessage);
    trace("MCTest outside package code");
    Test.as is saved in a sub-directory called "test".
    package test
        trace("test.Test package code");
        public class Test
            public static const StaticMessage:String = "Test: Hello World!";
            trace("test.Test class code");
    var myField:String = "myField";
    function myFunction():String
        return "myFunction";
    trace("test.Test outside package: " + myField + ", " + myFunction() + ", " + test.Test.StaticMessage);
    The resultant trace output is:
    MCTest class code.
    MCTest package code.
    MCTest outside package code
    test.Test class code
    test.Test package code
    test.Test outside package: myField, myFunction, Test: Hello World!
    Created Class MCTest: Test: Hello World!
    It is interesting to note that the package and outside package code are executed AFTER the class code.
    That seems to make more sense. You can only declare one class, variable, function, or namespace at the top level of a package with the same identifier as the file name, public or internal, and you can include executable code. At the top level of the ActionScript file outside the package declaration, you can only declare internal classes, variables, functions, and namespaces, and you can include executable code, none of which are within the package nor have access to any package internal declarations.
    The problem, therefore, would seem to be an incorrect manual. Does anyone actually know if this is accurate and the intended behavior?

  • Protected top-level classes - what do you think about?

    See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6310261

    What is subpackage? Is it like below?
    it.is.my.package.*; //the package
    it.is.my.package.subpackage.*; //the subpackage
    Exactly.
    If it is, well, I like the idea. It would improve the
    java. I�ve already had some idea like that. I
    thought: "Why don�t exist relations between packages
    in Java?".Sun claims there is no relationship, but assertions you can enable or disable for the package and all subpackages with one command.
    If you like this idea, please vote for this RFE.

  • First class object in java

    What is a First class object in java?

    1. Shatabdi is a train that runs in India.
    2. First class is the only way to travel in indian
    trains. second snd third class, while cheap, means
    you ride in very uncomfortable conditions.
    3. paan is also known as betel nut. It is a bitter
    nut and green leaf that is chewed as some people find
    it refreshing. What results is copious amounts of
    saliva that is red. To get rid of the saliva, chewers
    of paan spit resulting in red stains wherever that
    saliva happens to land. It is a common site to see
    paan being sold on the railway platform by vendors and
    the attendant red stains on the walls at the ends of
    said platforms. Utterly gross.
    As for me being Indian? hmmm.....either that or yo be havin a lot of free time at your job at sisal plantation in deepest India.
    that way you get to travel a lot, mix with the people, get your impressions ....
    |:-)

  • System level classes

    What are System level classes? Why are they called so?

    Never heard of them. Who said they'd exist?

  • [svn:fx-trunk] 9924: Empty design layers with id' s are now persisted and declared as top level properties.

    Revision: 9924
    Author:   [email protected]
    Date:     2009-09-02 09:11:03 -0700 (Wed, 02 Sep 2009)
    Log Message:
    Empty design layers with id's are now persisted and declared as top level properties.
    QE notes: None
    Doc notes:  None
    Bugs: SDK-22904
    Reviewer: Paul
    Tests run: Checkin
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22904
    Modified Paths:
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/InterfaceCompiler.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/analyzer/SyntaxAnalyzer.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/builder/DocumentBuilder.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/dom/DocumentNode.java
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/mxml/rep/MxmlDocument.java

    I seem to have fixed it by putting <div  class="clearfloat"></div> after the navigation bar?

  • What is the top hierarchical class in abap

    What is the top hierarchical class in abap ? in java we have the class Object, that is on top of all the rest.
    Is there a similar class in ABAP ?
    Thanks

    Hi,
    Well actually there is a difference. In Java 'Object' is an actual class which is the root for all other classes (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html). While in ABAP 'type ref to object' only means it is a reference to a class instance. An actual root class like Object in Java does not exist.
    Only for exception classes there is  a root: CX_ROOT...
    Regards, Gerd Rother

  • Issue with having to declare fixed width for my top level floated LI in horizontal menu

    Hi and thanks for taking a look at my problem:
    I am having trouble getting my sub menus to display correctly in IE.
    Originally i didn't declare a fixed width for my top level li and it displayed perfectly in all browsers except IE.
    If i don't declare a fixed width for my floated floated elements, IE treates the top level li as the same width as the ul they contain (which I don't want). So I declared a width for the ul.MenuBarHorizontal li to be 80px, which is close to the minimum width that i want to use for the top level list items. However, in actual fact, the top level list items all have individually declared widths in the classes they are assigned.
    How can i re-write the html or CSS so that the browser, mainly IE, reads the correct widths for the top level ist li??
    Here is a link to the page with the problem
    Thanks in advance if anyone can help me out.

    Hi Beth,
    thanks so much for your repsonse.
    I will take your notes and advice and see if i can apply it to the actual page i was referring to. It seems you were now looking at a completely different page with a different (albeit spry) horizontal menu.
    Again, i truly appreciate your time and advice.
    Thanks!

  • How to access variables declared in java class file from jsp

    i have a java package which reads values from property file. i have imported the package.classname in jsp file and also i have created an object for the class file like
    classname object=new classname();
    now iam able to access only the methods defined in the class but not the variables. i have defined connection properties in class file.
    in jsp i need to use
    statement=con.createstatement(); but it shows variable not declared.
    con is declared in java class file.
    how to access the variables?
    thanks

    here is the code
    * testbean.java
    * Created on October 31, 2006, 12:14 PM
    package property;
    import java.beans.*;
    import java.io.Serializable;
    public class testbean extends Object implements Serializable {
    public String sampleProperty="test2";
        public String getSampleProperty() {
            return sampleProperty;
    }jsp file
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.sql.*,java.util.*"%>
    <html>
    <head>
    <title>Schedule Details</title>
    </head>
    <jsp:useBean id="ConProp" class="property.testbean"/>
    <body>
    Messge is : <jsp:getProperty name="msg" property="sampleProperty"/>
    <%
      out.println(ConProp.sampleProperty);
    %>
    </body>
    </html>out.println(ConProp.sampleProperty) prints null value.
    is this the right procedure to access bean variables
    thanks

Maybe you are looking for

  • How to include animation files into muse test site on business catalyst?

    Hi there I am trying to publish a site created in muse to the business catalyst test website service for a client to review in the website i created an animation that i have inserted as an HTML snippet (ie copied relevant code into "INSERT HTML" The

  • Setting the id names in a datatable

    is there a way to control the names of the id fields of individual elements in a datatable? I need to call a website I have no control over. This website is expecting variable to be in the http request using 'POST'. The variables names are VARCNT0,VA

  • Server-side naming service functionality

    Dear all, I have this problem on my JCA connection: ###Exception #1#com.sap.engine.services.jndi.persistent.exceptions.NamingException: Error getting the server-side naming service functionality during getInitialContext operation. at com.sap.engine.s

  • How to properly detect object not found in query?

    Generally, we'd prefer to catch the unchecked exceptions which JDO throws in response to database operations that go awry. That said, there's one in particular that's bothering us: The most important and common one of these which we'd like to know ab

  • How can we open a file by clicking on a button "open"  in a pplet

    Hello all,,, I got some code to open a file in jre witout applets ....but i'm in need to open a file (for exmple to open a .txt file in text editor or notepad automatically by clicking on a button); Help me out... Thank you...