Is there only a class in a .java file?

Can a .java file include more than one class?

mostly the others R inner classes but it doesn't have to be like that...
Take a look @ Thinking in Jave 2 by Bruce Eckel is good explanaition about that topic

Similar Messages

  • How many classes should a .java file contain?

    Are there any general guidelines on how many Java classes should be contained in a single .java file? I've been creating a new .java file for each class I write but see examples in Sun's Java tutorial where there are at least two classes in a single .java file. One such case is the TableDemo example at
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/TableDemo.java
    Thanks.

    The example you point to isn't really more the one class in one java file. It makes use of an inner class. An inner class is something different! As far as I understand it, it is mainly used to implement some behaviour (in this case AbstractTableModel behaviour). If the MyTableModel was in a separate class file, it couldn't access the variable of the main TableDemo class. So they use an inner class.
    So unless you need inner classes, this example is no reason to put more than one class in a .java file. In general, just put one class in a .java file. It's easier for everybody.

  • If you have two public class in a java file what will be the error ?

    Q:If you have two public class in a java file what will be the error and how will you remove that.?

    Kannan_S wrote:
    I dont want you to be on that list . Here goes my explanation..
    A class is well defined with members and functions
    An abstract class is not defined well as compared to a full fledged class (talking more generically)
    An interface is more abstract.
    I was asking the author who has posted this question to be like a class(very clear)
    and not either as an abstract class or an interface
    Hope i have made it clear..Not in the slightest. This has absolutely no bearing whatsoever on the question asked. Not to mention that classes are classes, and all equal in the eyes of the compiler, be they abstract, concrete or interfaces. It's difficult to see what your point is, to be honest, but I suspect it wouldn't be worth seeing anyway

  • Can you have multiple classes in one .java file ?

    or am I being dumb ;-)
    I'm guessing not because the filename has to match the classname but maybe you can ... ?
    C

    To elaborate a bit more. The public class must match the filename, however you can declare "inner" classes.
    An inner class can be declared inside another class, or even inside another method. Where you declare that class dictates the scope it will have. However, the lack of an ability to declare these classes public (a public class must be declared inside a java file with the same name), means that they are not visible anywhere else. However, they do still have plenty of uses.
    Declaring a class inside a method is used rarely, but would look something like
    public void foo(Bar myBar = new Bar
            private String baz = "Hello";
            public String doSomething()
                 return baz;
         myBar.doSomething()
    }This declares and implements the class Bar inside the method header. Sure, this is a pretty useless example, but you could put any methods or variables inside your inner class, and they would be available only during execution of that method. (ie. only have method scope).
    }

  • Only one class level to java applet?

    I take it Java Applets only do one level of class and do not do a sub class, and that is the class the
    HTML file calls up? So you can not have a sub-class in that class? it appears none of the examples
    I have seen in the text book have sub class

    You're not making much sense, due at least in part to non-standard terminology.
    Eric-Auckland wrote:
    I take it Java Applets only do one level of classWhat exactly do you mean "do one level of class"? Show sample code that "does one level" and "does two levels".
    and do not do a sub class, What exactly to you mean "do a sub class"?
    and that is the class the
    HTML file calls up?The web server will serve up whatever class is specificied in the HTML, and any classes it depends upon. The applet class has to extend Applet or JApplet or whatever.
    So you can not have a sub-class in that class? What do you mean "have a sub-class *in* that class"? One rarely if ever puts a subclass inside its parent class, whether applet or standalone or web app or whatever.
    it appears none of the examples
    I have seen in the text book have sub classWhat do you mean they don't "have a subclass"? Why would they need one? Your applet subclasses some base applet class. You could in turn subclass your applet class, but why would you want to?
    I suspect you have serious misconceptions about what inheritance is for.

  • How to create a .java file with multiple classes

    I have all the below classes declared in a file say ABC.java under
    a common package called somepackage
    Abstract class A
    Void abstract metod1();
    Void metod2();
    Class B
    void method3();
    Void method4();
    Class C
    void method1();
    Void method2();
    In Client.Java
    On compiling the Client.Java I get errors
    Import somepackag.*;
    Class Samp extents A
    void Method1()
    Public class Client
    A a1 =new Samp(); //error undeclared class A
    B b1 = new B1();//error undeclared class B
    C c1 = new C1();//error undeclared class C
    is it possible to have all the class declared in one file ( i dont need mutiple classes, as this file will be autogenerated , i need all classes in one file) and use the classes inside this in the some client app
    regards
    MP

    Peetzore wrote:
    As long as you have only one public class and your .java file is named after it you shouldn't have any problem.I did exactly that, but still i get the same error "Cannot find symbol"
    i have used the import command on top as import somepackage.*;
    Edited by: mpjava on Jun 2, 2009 1:29 AM
    Edited by: mpjava on Jun 2, 2009 1:30 AM

  • How to convert .class files to .java files

    Hi,
    I want to convert .class files to .java files. Is there is any software for that doing except Dj DCompiler? Because if i am using this i am not getting proper code i mean as it is available in the file.
    I tried by writing simple java file and i compiled Sample.java file and i got a .class file then i converted this Sample.class to Sample.java file by using DjDcompiler but i was missing some statements i need entire code that is available in Sample.java file. Please tell me any other software for that doing.
    Thank you in advance

    I want to convert .class files to .java files.
    iles. Is there is any software for that doing except
    Dj DCompiler? Because if i am using this i am nothttp://www.google.com/search?hl=en&q=java+decompiler&meta=
    getting proper code i mean as it is available in the
    file.I doubt you ever will.
    I tried by writing simple java file and i compiled
    Sample.java file and i got a .class file then i
    converted this Sample.class to Sample.java file by
    using DjDcompiler but i was missing some statements i
    need entire code that is available in Sample.java
    file. Please tell me any other software for that
    doing.Did you hear about "compiler opimizations"?

  • How to invoke another Java file in Java program?

    Hello all,
    Now I am building a commnity of agents that can talk in Java, I have another Java-Based dialogue system to handle the dialogue between the agents. But I don'y know how to invoke the Java dialogue system file in the agent class.
    Is there any methods can call another .java file in a Java program?
    Help!!!!!please

    Yep, vaguest of the vaguey vague vague.
    Anyhoo,
    I'm guessing you want to call a method from a different class?
    Assuming you have the "Runner" class and then "Agent1", "Agent2", etc.
    Agent1 whatever = new Agent1();

  • Where's the location of JSP's java files in weblogic

    When I put *.jsp in my Web application,
              I can find the complied class in
              C:\bea\user_projects\mydomain\myserver\.wlnotdelete\extract\myserver_BOFT_BO
              FT\jsp_servlet\****.class
              But anyone can tell me where the ***.java?
              What's the location of these java files ?
              Samuel
              

    In WL8.1, it appears that the .java files are placed in the same directory,
              but are removed after the class is compiled successfully. (Is there a
              setting to prevent the .java files from being deleted?)
              Try placing an intentional syntax error in your JSP file so that the
              compilation fails, and you should see the .java file where the .class file
              would have been.
              -- Craig
              "Samuel Hsu" <[email protected]> wrote in message
              news:3fc4365a$[email protected]..
              > When I put *.jsp in my Web application,
              > I can find the complied class in
              >
              C:\bea\user_projects\mydomain\myserver\.wlnotdelete\extract\myserver_BOFT_BO
              > FT\jsp_servlet\****.class
              > But anyone can tell me where the ***.java?
              > What's the location of these java files ?
              >
              > Samuel
              >
              >
              

  • Java file missing in par file

    Hi all,
    We have a par file. After importing that par file in NWDS we could see only jsp pages. No Java file exists. 
    This par file is downloaded from our portal which is created by previous developer. I think previous developer did not selected "Include Source code" option while exporting par file to portal.
    Now we need to changes in R/3 side and in java file. For that we need to know the Function Module or Report used in R/3. I think this data will be in java file. 
    Can anybody let me know how to find the java file related to a par file?
    Regards,
    Swapna.

    Hi Bobby/n@v!n,
    Thank you for the inputs given.
    But I heard that we cant get the same java file (like original) when we use the Java Decompiler. We will get the file which gives the same output with different code. I'm not sure if we can the use the file given by java decompiler.
    Is there any other way to get the original java file of given par file?
    Regards,
    Swapna.

  • Tracing Java files in Jdev

    Hi,
    I am new to Jdeveloper. In our project there is one Java form window with some issues. I can able to see the UI but I don't know which class is associated with that form so that i can change the code. Is there any way to display the Java file name in console when I open the particular UI in applet viewer during Run?
    Thanks,
    Prabhu

    I'm not sure but look in the zipfile src.jar in the java installation directory

  • Using java files with JSP

    Ok, so im pretty new to this JSP lark and have a question.
    I have Java Classes resting in .java files, i need to know how
    do i link these files to my .jsp page so that the classes/variable etc.
    declared with the java files are recognised when they are come
    across in the .jsp file.
    I dont know if I have explained that properly.

    Just include this statement at the top of your jsp:
    <%@page import="yourpackage.yourclass"%>
    The .java files should of course be compiled into .class files prior to using (and you don't include the extension when importing).

  • .java files don't compile on redhat

    im using redhat 9.
    i installed the binary of JDK
    in the bin folder when i type javac and then press enter, it says command not available or something like that
    actually i did it after when i could not compile .java files like:
    javac Hi.java
    moreover it also displays the same message for java
    but i have checked it that both of the files: javac and java are present in the bin directory
    is there any other method of compiling java files on linux
    kindly help me in this regard

    It could be that the current working directory your in is not in your path.
    You should be able to check that by typing echo $PATHat the command prompt.
    I'm using SUSE and the output of the command reads like this: /home/wyd/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:
    /usr/lib/java/bin:/usr/lib/ant/bin:/usr/lib/ant/bin:/usr/lib/ant/binAs you see somewhere in there there is the line /usr/lib/java/bin: this needs to show up in your path as well. Otherwise you have to add this directory to your path. Can't tell you how to do this on Redhat sorry.
    Furthermore you see that the entry . (thats the dot for the current working directory) is not in my path. So in order to execute a command that is not in the path, you have to type ./javacfor instance. (a dot followed by a backslash, then the command to run) Thereby the shell knows you want to run a program located in the current working directory.
    So do the following tests:
    cd to the bin-directory of the JDK
    type ,/javac and you should the usage info for the compiler
    add the bin-directory of the JDK to your path and you should be able to run the compiler from any directory

  • How to compile dunamically genrated java files through java program?

    Hi, I have a requirement where i generate java files from WSDL dynamically using wsdl2java jaxbri. I need to compile these files dynamically on the fly and jar it. Everything should happen through java program. Bcos everything is dynamic here, no information is known (like dir, file names ...) until the runtime. Everything is user fed.
    the directories may contain other directories with java files. its recursive
    i tried com.sun.tools.javac.Main.. but either its not scaling to my needs or i donno how to wok with this.
    is there any option to compile the java files as they are created thru JAXBRI (wsdl2java)?
    any help is appreciated..
    -s

    my requirement is :
    i create java files from wsdl2java (axis).. i need to compile all the java files.. directories with in the directories (recursive)...
    as bcos the the java files have inter-dependencies they have to be compiled as a bunch something like (java *.java). I donno how to do this in javac.Main tool
    Once all these files are compiled i need to create a jar out of them
    Any help is appreciated!

  • Where are the JSP  Java Files stored in WL8?

    Hi there,
              i'm looking for the .java-Files generated from the .jsp-File. I have already set the property "JSPKeep Generated".
              Thanks for your help
              cheers immo

    I don't know if this varies by WLS version, and you haven't specified which version you are using, but in my WLS 8.1SP2 distribution, they are stored at:
              c:/bea/user_projects/domains/<domain>/<server>/.wlnotdelete/extract/.../jsp_servlet/.../*.java

Maybe you are looking for

  • Is it possible to sync two different iphones and an ipad on only one computer?

    Is it possible to sync two different iphones and an ipad on only one computer?? My husband has an iphone 4 & ipad. I have an iphone 4S. We both use the same  itunes account. We are having trouble w/ all of our contacts/calendars & info getting all mi

  • How do I stop email on Mac from receiving?

    With all the questions about how to stop mail from recieving, why hasnt apple come put with a stop button for receiving and sending mail? It is not too difficult that sometimes you dont what to be receiving mail or want to send at a time of your choo

  • Problem using BAPI BAPI_ACC_DOCUMENT_POST with vendor field XZEMP

    Hi, I'm using the bapi BAPI_ACC_DOCUMENT_POST, when i fill the table ACCOUNTPAYABLE and execute it, if i use a vendor that doesn't have an 'X' in the field XZEMP (Indicator: Alternative payee in document allowed ?) of the table LFA1 the bapi returns

  • Deleting a rebate with Accruals

    Hello Gurus, I have a scenario where i need to delete a rebate which has accruals. If i try to delete the rebate it says "Order type has not been defined in the sales Area". Is there any way to delete/settle this rebate without maintaining this custo

  • Issues receiving and sending email

    I am havng major issues with email. Here's is what has happened and what I have done: 1. The account is with Roger ISP in Canada, which uses Yahoo for it's email. I am running Mac OS X Lion (cannot update to Mountain Lion machine is not compatible.)