Class and package names

I'm novice in Java, but not novice in programming. So, it is not a problem to understand and to write simple samples, but it is still hard to create a good package structure and give good names for classes.
For example now, I started writing simple standalone application, which will be run by cron and will communicate with 2 webservices. I will receive data(reports) from one webservice, and will send this data to another one. From the very beggining, I have a poblem about structure of roject and naming. Is it ok, to make only one class, with name for example ReportApp? Or better create one class for communicating with first service, another - with second, and main class will call methods of this classes? Also package name... I think it is good, when from package you see, that i is service, or xml.util etc. How can I show in package name that it is batch standalone application? Can somebody explain what names for classes and packages he'll use for such task, please.

Descriptive names are nice....
For packages, a standard method is a domain name for your company or organization:
com.widgetsRus.service.
com.widgetsRus.ui.
com.widgetsRus.util.
As for class names, just descripe what the class is for. ReportServer, ReportClient, Report (interface), AbstractReport (implements Report), StatusReport (extends AbstractReport), etc...
As for creating a class for this and that, or separate classes, that's a design issue, but typically, it's easier to maintain things if they are kept in smaller classes with related functionality.

Similar Messages

  • Testing class and package name legality

    Hi all. Does the API provide a way of testing if a given class and package name is correct? I have to model a UML diagram tool. Right now, I'm doing it like this:
         public boolean canHaveAsNameStrict(String name){
              return(!name.startsWith("([0-9])+") && name.matches("([a-zA-Z_0-9])+"));
         }for a package, but this may be incmoplete etc. Also, are the brackets ([...]) and the + sign delimeters or part of the match? (I copied this code from an exercise solution, in which they were not mandatory to the solution)

    Beware - the JLS allows non-ASCII class and package names. You can have a class named "�owyn", for instance.
    class CheckPackage {
        public static void main(String[] args) {
            String pat = "([A-Za-z_$][A-Za-z0-9_$]*\\.)*[A-Za-z_$][A-Za-z0-9_$]*";
            System.out.println (args[0].matches (pat));
    }

  • Need Hex Encoder Class and Package Name

    Hi,
    I have a requirement in which I need to convert an xml (input) into a Hex format (output). I know that there is a class called as BASE64Encoder when you want to encode a data into base64Binary format and this one is present in the sun.misc.BASE64Encoder package. Now my question is do we have some class called as HexEncoder included under some standard package (like sun.misc.HexEncoder)?
    Please provide pointers on how to solve this.
    Thanks,
    Abhishek.

    Hi,
    You get most of the encorders from here http://www.koders.com/java/fid1DEA9207865756960D16FBA292EE6534A47D3BAD.aspx
    Regards
    Ayyapparaj

  • How to fetch what are all the tables used in this TR no and Package name of

    Hi Friends,
    I have input of Transport Request no (E070-TRKORR).
    How to fetch what are all the tables used in this TR no and Package name of this Table.

    HI,
    FYI
    SELECT E071OBJECT_NAME, E070MDEVCLASS
    FROM E071, E070M
    WHERE TRKORR = YOU REQUEST NO.

  • Undefined variable, class, or package name

    The following code in the jsp is supposed to display the correct 'Securities' link based on the app_main_frames URL. I am getting an error. Can anyone help?
    <% if (parent.app_main_frame.location == ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) { %>
    Securities
    <% } else { %>
    <a href="/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none
    target="app_main_frame">Securities</a>
    <% } %>
    I am getting the following error:
    Generated servlet error:
    /opt/JBoss-2.4.4_Tomcat-4.0.1/catalina/work/localhost/cgi-java/common/jsp/NavigationMenu$jsp.java:173:
    Undefined variable, class, or package name: parent
    if (parent.app_main_frame.location ==
    ^
    ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) {

    If app_main_frame is a frame in a frameset then you cannot
    simply refer to it in a Java scriptlet.
    You can refer to it in a JavaScript script, like this:
    <script>
    if (parent.app_main_frame.location == "http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")
       document.write("<a href=\"javascript:submit_Form('none')\"target=\"app_main_frame\">Securities</a>");
    else
       document.write("<a href=\"/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none\"target=\"app_main_frame">Securities</a>");
    </script>

  • Class name and package name clashing

    When i have a class and a package with the same name, I cannot access classes in the package. For example I have 3 classes and 1 package as below
    - Test.java
    - PackageName.java
    + PackageName // this is a directory
    - MyClass.java
    Below are the codes of .java files
    Test.java
    =======
    public class Test { PackageName.MyClass a = new PackageName.MyClass ();}
    PackageName.java
    ===============
    public class PackageName{ }
    MyClass.java
    ==========
    package PackageName; public class MyClass { }
    I can compile PackageName.java and MyClass.java but not Test.java. It says
    cannot resolve symbol
    symbol : class MyClass
    location: class PackageName
    PackageName.MyClass a = new PackageName.MyClass ();
    But if I remove the PackageName.java, I can compile Test.java perfectly. I think when I use PackageName.MyClass, java thinks that I try to access an inner class MyClass of PackageName class, and that does not exists. Is there any way to solve this ambiguation, other than making the package name and class name different? Thank you very much.

    This works fine: just add an import to Test.java.
    import PackageName.MyClass;
    public class Test
        public static void main(String [] args)
            MyClass a = new MyClass();
    public class PackageName {}
    package PackageName;
    public class MyClass {}It's a pretty wacky, useless example, but it works.
    Plus I thought inner classes would have a dollar sign in their .class file names. When I compile this:
    public class OuterClass
        public static void main(String [] args)
            OuterClass outer = new OuterClass();
            System.out.println(outer);
        public String toString() { return "I'm an OuterClass"; }
        class InnerClass
            public String toString() { return "I'm an InnerClass"; }
    }I see two .class files: OuterClass.class and OuterClass$InnerClass.class
    Why make up examples like this? It's hard enough writing code, and it's easy to disambiguate for the compiler.

  • Conflit in class name and package name

    I have a small doubt. If the class name and the package name are the same in a folder, is there will be any conflict between these while using it. That means suppose a folder named 'animator' contain a package 'a' and a class name 'a'. I got any error in the 'Eclipse' tool that "a collides with a package". Is this can be solved my any change of setting in Eclipse? If then where can i change.? Can anybody help me to solve this issue??

    This works fine: just add an import to Test.java.
    import PackageName.MyClass;
    public class Test
        public static void main(String [] args)
            MyClass a = new MyClass();
    public class PackageName {}
    package PackageName;
    public class MyClass {}It's a pretty wacky, useless example, but it works.
    Plus I thought inner classes would have a dollar sign in their .class file names. When I compile this:
    public class OuterClass
        public static void main(String [] args)
            OuterClass outer = new OuterClass();
            System.out.println(outer);
        public String toString() { return "I'm an OuterClass"; }
        class InnerClass
            public String toString() { return "I'm an InnerClass"; }
    }I see two .class files: OuterClass.class and OuterClass$InnerClass.class
    Why make up examples like this? It's hard enough writing code, and it's easy to disambiguate for the compiler.

  • Not allowed to import classes without package names?

    Hi,
    I have a few questions on Packages and importing?
    1. Is the following true that it is illegal to import classes in the same package as the current class, will this cause a comilation error? If this is the case where in the Java Language specification is this actually written as I could not find it?
    2. This has probably been answered by question 1 but if I have 2 classes in the same package and if I import 1 of the classes into the other class, is it illegal to import it by just using the class name and not the package name as well, ie
    if the package name is ie.tcd
    and the 2 class names are exp1.class and exp2.class, can I do this in class 2
    package ie.tcd;
    import exp1;
    public class exp2 {
    3. Is it illegal to import classes that are not explicitly part of any package or must a class be part of a package to be imported. I read somewhere that while this was always illegal it is only after jdk 1.4.2 that this is being enforced? If this is the case where in the Java Language specification is this actually written as I could not find it either?
    Thanks very much for any help,
    John

    Was just also wondering, 1 other thing, I am looking
    at someone elses code they have 2 classes (Class A
    and Class B) in the same package (pkg). The person
    imports class A into B:
    package pkg;
    import A;
    public class B {
    Is this legal code (or was it ever)?Not if A is really in pkg.A. If there is an A in the unnamed package it was legal, or at least it was understood by the compiler, and now it isn't (to both).
    Can you import or is there a point in importing a class in the same
    package?Only by naming the package in the import statement. If the current and the import statement are in the same package the import is redundant.
    If there is a point would you import just be
    using the class name (this would be illegal after jdk
    1.4) or should you use the whole package name even
    though it is in the package anyways?As I understand it you must always use the whole package name in imports.

  • Bug: "WEB-INF", "web-inf" and package names

    I'm using JSPs with Struts, and as recommended in the Struts Toystore Example all of my JSPs are below the WEB-INF directory. If I compile my JSPs I get the following warnings (hundreds of them):
    Warning: package name web2d_inf._jsp._gui._documents._document does not match source file name W:\root\output\Gui\View\classes\.jsps\_WEB_2d_INF\_jsp\_gui\_documents\_document\_Preview.java
    How can I get rid of this warnings, without disabling warnings completely? I'm using JDeveloper 9.0.3.2
    Thanks

    Hello;
    It looks like this bug may pop back up?
    I am using 10g Pre on LINUX and get the error:
    Project:/home/a/jdevhome/mywork/ir2/ViewController/ViewController.jpr
    /home/a/jdevhome/mywork/ir2/ViewController/public_html/WEB-INF/untitled1.jsp
    Error:/home/a/jdevhome/mywork/ir2/ViewController/public_html/web-inf/untitled1.jsp (No such file or directory)
    It looks like web-inf is getting set to lower case somewhere.
    I know Linux is not the release for the 10g pre, this is just in case the bug is going to 'pop' up again in the final version
    Thanks
    A

  • Installed Extensions and Package names

    I've read through reams of documentation about installed extensions and have experimented with putting jars into %JRE%/lib/ext, etc. My question is - is it possible to put jars that contain classes with system package (java.*) names and use them?
    This might sound like a strange thing to want to do, but I've been experimenting with the Long Term Persistence mechanism (http://java.sun.com/products/jfc/tsc/articles/persistence2/) which comes as a jar with classes of the package 'java.beans'. To use this from the command line I have been using the -Xbootclasspath option to include the jar. However, I want to deploy my app through Java Web Start and cannot (as far as I know) use that as a JVM option.
    My last hope is that I can install these jars as extensions on the client and see if I can pick up the classes there. Is this a security violation though - using system package names for extensions?
    Cheers
    AlanB
    P.S. I could use JDK1.4 which has the persistence mechanism as standard but the app server I'm using has 'mucho grande' problems with clients using 1.4!

    My last hope is that I can install these jars as
    extensions on the client and see if I can pick up the
    classes there. Is this a security violation though -
    using system package names for extensions?Unfortunately, I do believe this is the case... the only classloader that is permitted to load java.* packages is the bootstrap loader.
    There is one way to know for sure, though... ;-)

  • Drawing class and package

    My program is about drawing class diagram,package,object and interface�
    I have just done only for package and class diagram
    When I click on the classdiagram icon from my toolbox, it draws a class diagram,but when I then click on the package icon, a package is drawn but the class diagram disappears�..and when I then click again on the classdiagram icon, the package disappears and the previous class diagram reappears,,,,so why??/
    What is the problem?? Is it wiz the viewport??? How can I draw both a class and a package�
    IN MY MAIN MENU I INCLUDE THIS CODE:
    public MainMenu (String title,ProjectDoc doc) {
         super (title,null);
         setResizable(true);
         doc = new ProjectDoc(this);
         this.doc = doc;
         classView = new ClassView(doc,this);
         packageView = new PackageView(doc,this);
              Container content = getContentPane();
        content.setLayout(new BorderLayout());
        JToolBar toolBar = new JToolBar();
        content.add (toolBar, BorderLayout.NORTH);
         classView.setPreferredSize (new Dimension(6000,3500));
         packageView.setPreferredSize(new Dimension(6000,3500));
        drawingPane = new JScrollPane (
                       ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                       ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        drawingPane.setViewportView(classView);
      drawingPane.setViewportView(packageView);plzzz help me it is very urgent

    Hi,
    call chapter4.Drawing.class
    <applet code="chapter4.Drawing.class" width="100"
    height="100"> </applet>Regards,
    Ram

  • Class and Object name change in the universe designer

    Hello Experts
    I have a confusion , I am just wondering if I devlop a bobj universe, lets say, based on SQL database and change the name of the class and object during the creation of the universe, will that fetch the data from d/base properly while running a query / report. Although universe class and object has different names than database now but the records are the same. Do we need to point the object to d/base object in some kind of different or special way .
    To make my question more simple, In d/base table name is "Employee" whereas on universe side I create a class name "Staff" and at the same time field name in the database is "Emploee ID" whereas in the universe I named it "Badge number".
    Please advise if that will make any difference while I run the query or Is there any kind of complication on the universe side that I should expect which I am not familiar with.
    I would apprecite your response.
    Best Regards

    Hello experts,
    Let me rephrase the issue with exact scenario.
    I have a table names "REGION" with fields region id, region and country id.
    I have another table name REGION_SLINE with fields SL_id, region id and Sales_revenue.
    I created an equi join between these two tables based on region id field and checked the cardinality which is ok.
    Now when I try to create a report based on sales revenue per customer ( "customer's first name"  is an other field on CUSTOMER table), I dont get any result in the report and get a message that "No data to reterive"
    Also please note that when I run a report which is sales revenue per region id, I get the result, seem slike these two tables REGION and REGION_SLINE can generate the report but sales revenue per customer report is not generated because customer first name is a field of another table.
    I was just wondering if I need to write some kind of where clause in the object properties of region id which is used to create equi joon link.
    I woulld appreciate your response.
    Regards
    Edited by: SAP_LCCHS on Jul 4, 2011 9:19 AM
    Edited by: SAP_LCCHS on Jul 4, 2011 9:21 AM

  • Can I create a class and package for my inframe AS and access it global

    Ls,
    I made an app using only inframe actionscript in a .fla;
    transfrerring variables from frame 1 to frame 2 is unreliable.
    Some sources say the persist over frames but i found that not to be reliable.
    Arrays seem to be filled with the right values. Normal int vars declared in frame 1 fail some time.
    You should have used classes i hear you say,  and right you are.
    But I didnt.
    Now im using either reloading, re-initing and/or the sharedobject.
    Anyhoe..
    Question:
    If I declare a class for my main .fla file.,
    then declare, instantiate and load the globals i want in this main class,
    will I be able to acces these variables in my main .fla timeline script?
    If so, I could slowely reconstruct my .fla into smaller objects/classes and make it a real app.
    Just starting from scratch is. welll..i dont even want to think about that.
    Highest regards,
    Mac

    Yes! I got it to run as Mobile project.
    Now, how to test on my mobile thru USB.
    I'm more/only used to working from FLASH CS5.5
    Although I like the builder, it feels really flexible, it also seems more work(yeah still lazy).
    Is there an advantage to using the builder over Flash CS?
    Thank you.. again...again
    Mac

  • Class name and package names

    I read a passage from some Java Book (sorry don't have the reference handy) that
    "It is illegal for a package and a class to have the same name, so there can be no ambiguity."
    Yet I have created a class named pkgclass within a package with the very same name.
    i.e.
    package pkgclass;
    public class pkgclass {
    This compiles just fine. Have I misinterpreted the statement from the book? What is it trying to say?
    Thanks in advance.

    Here's a quote from the Java language spec:
    "The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (�7.6) declared in that package."
    So your book was not quite correct, or maybe you just misremembered it (clearly you are typing from memory there). It isn't illegal for a package to have the same name as a class, as in your example. But it is illegal for a package to contain a subpackage and a class with the same name.

  • Class And instance name

    how can i access a movieclip via a instance name in 1 class file (Not The Main Document)
    And Make The class reconize  the movieclip when i use a code like this :   this.y = player.y
    player is the instance name.
    thanks

    Already I had seen some thread over the forum and did not have a proper solution for this, but after a long hours I found a solution with the minimal effort:
    1. Create a flash file with a single movieclip named instance testMC
    2. On the timeline write the following code to declare Object of the class
        var obj:TestingAccess=new TestingAccess(stage);
       Here you should pass the stage as an argument to the constructor of the class
    3. Create a class file and write the following code:
       package  {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.display.Sprite;
        import flash.display.Stage;
        public class TestingAccess extends MovieClip {
            var stagRef:Stage;
            var rootMC:MovieClip;
            public function TestingAccess(stag:Stage) {
                // constructor code
                stagRef=stag;
                rootMC=MovieClip(stagRef.getChildAt(0));
                rootMC.testMC.rotation=45;
        }//Class
    }//Package
    I Just a made a rotation for that Movieclip. It works

Maybe you are looking for