Why files with no public classes have no naming restrictions ?

As i know a file with a public class ,uch have the same name as the class name but the files with no public classes have no naming restrictions and then how we can access these classes ?

but the files with no public classes have no naming restrictions and then how we can access these classes ?You can access a class in a files with no public classes have no naming restrictions by just creating their object.
Here is the code you can run.
File: NonPublic.java
* @(#)NonPublic.java
* @author Gagan Ichake
* @version 1.00 2009/1/15
class NotAsFileName{
     void baz()
          System.out.println("I am in NonPublic class.");
}File: AccessNonPublic.java
* @(#)AccessNonPublic.java
* @author Gagan Ichake
* @version 1.00 2009/1/15
public class AccessNonPublic {
        public static void main(String []arg)
          NotAsFileName nafn = new NotAsFileName();
          nafn.baz();
}Edited by: Ggn on Jan 15, 2009 10:53 PM

Similar Messages

  • File name vs. public class?

    Could anyone tell me that why should the file name be the same as the only public class in that file? Is there any reason for this rule? Thanks in advance. I really appreciate it.
    David

    A java restrication rule and only one class declared public.

  • 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.

  • How do you create a jar file with txt and classes?

    Hey, I'm trying to create code to create a jar file with a text file, but I can't figure out how to add the text file. Here is what I have so far:
    try {
                // Name of jar file to write
                String archiveFile = "test.jar";
                Manifest jman = new Manifest();
                try {
                    // Create a manifest from a file
                    //InputStream fis = new FileInputStream("manifestfile");
                    //Manifest manifest = new Manifest(fis);
                    // Construct a string version of a manifest
                    StringBuffer sbuf = new StringBuffer();
                    sbuf.append("Manifest-Version: 1.0\n");
                    sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
                    sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
                    sbuf.append("Main-Class: Main\n");
                    sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
                    sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
                    // Convert the string to a input stream
                    InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
                    // Create the manifest
                    jman = new Manifest(is);
                } catch (IOException e) {
                FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
                JarOutputStream out = new JarOutputStream(stream, jman);
                out.putNextEntry(new JarEntry("test.txt"));
                out.closeEntry();
                out.close();
            } catch (Exception ex) {
            }It creates the .jar file with the correct manifest but I can't get it to write the test.txt or anything else into the jar file.
    -Gandolf
    Edited by: GanMatt on Jun 18, 2009 8:18 AM
    Edited by: GanMatt on Jun 18, 2009 8:19 AM

    Alright, my question has changed. Here's the code:
    try {
                // Name of jar file to write
                String archiveFile = "test.jar";
                Manifest jman = new Manifest();
                try {
                    // Create a manifest from a file
                    //InputStream fis = new FileInputStream("manifestfile");
                    //Manifest manifest = new Manifest(fis);
                    // Construct a string version of a manifest
                    StringBuffer sbuf = new StringBuffer();
                    sbuf.append("Manifest-Version: 1.0\n");
                    sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
                    sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
                    sbuf.append("Main-Class: Main\n");
                    sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
                    sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
                    // Convert the string to a input stream
                    InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
                    // Create the manifest
                    jman = new Manifest(is);
                } catch (IOException e) {
                FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
                JarOutputStream out = new JarOutputStream(stream, jman);
                out.putNextEntry(new JarEntry("test.txt"));
                out.write("Hi".getBytes());
                out.flush();
                out.closeEntry();
                out.close();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,ex.toString(),"BUG!",JOptionPane.INFORMATION_MESSAGE);
            }It creates the jar file with the txt file inside it, but I can't write "Hi" inside of the text file. Any ideas?
    -Gandolf

  • I can't open pps files with FF4. I have Powerpoint Viewer installedAny suggestions?

    I can open Powerpoint (pps) files with Google Chrome but not Firefox 4. How do I get FF4 to associate pps files with the Powerpoint Viewer that is installed on my computer?

    Many thanks!!!  This works and is probably the best fix for now.  Thank you!!!
    Date: Wed, 30 Jan 2013 10:58:01 -0800
    From: [email protected]
    To: [email protected]
    Subject: I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates
        Re: I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates
        created by 99jon in Photoshop Elements - View the full discussion
    For the D600 NEF's you have two alternatives: (1) Upgrade to PSE 11. (2) Download and install the free Adobe DNG converter to convert your raw files to the Adobe universal Raw format and the files will open in all versions of PSE (keep your originals as backups and for use in the camera manufactures software)  Windows download click here DNG Converter 7.3  Mac download click here DNG Converter 7.3  You can convert a whole folder of raw images in one click. See this quick video tutorial: You Tube click here for DNG Converter tutorial
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5034913#5034913
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5034913#5034913
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5034913#5034913. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Elements by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Why update with subqueries does not have cost and cardinality?

    There is update.
    update test t1 set dummy = (select dummy from test2 t2 where t1.id = t2.id);Both tables which have actual statistics. Each has 1000 rows. And column ID have values from 1 to 1000 in each table.
    This is explain plan
    | Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |       |  1000 | 13000 |   426   (9)| 00:00:01 |
    |   1 |  UPDATE            | TEST  |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| TEST  |  1000 | 13000 |   426   (9)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |     1 |    13 |   426   (9)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("T2"."ID"=:B1)We can see here, that Oracle consider subquery within update as once-executed subquery.
    This is runtime plan
    | Id  | Operation          | Name  | Starts | E-Rows | A-Rows |
    |   1 |  UPDATE            | TEST  |      1 |        |      0 |
    |   2 |   TABLE ACCESS FULL| TEST  |      1 |   1000 |   1000 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |   1000 |      1 |   1000 |
    Predicate Information (identified by operation id):
       3 - filter("T2"."ID"=:B1)Why first plan does not have cost in step 1?
    Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
    Or it is my bug (or what?)?

    793769 wrote:
    Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
    Or it is my bug (or what?)?It's not possible to say whether this is a bug or a deliberate choice.
    Because of "subquery caching" (see http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/ ) the optimizer cannot predict how often the subquery will have to run. So possibly it shows nothing rather than showing the best or worst cases or a pure guess.
    Regards
    Jonathan Lewis

  • PNG files with a transparent background have background in Internet Explorer.

    I have two banners that are rounded rectangles for a website.
    The have quite a few gradients in them, with a gif it looks
    distorted. I can't use jpg, so I went with png. In dreamweaver it
    shows the banners as having no backgrounds, but in Internet
    Explorer, they have backgrounds! How can I fix this?
    Also, on another note, when I use the type tool in Fireworks,
    my type window will not stretch as I continue to type, I did not
    set a width for the box, however, I get two words into a sentence,
    and I am jumping to the next line. I have tried over-and-over to
    fix this problem, but with no luck. It happens on and off, but it
    is driving me crazy.
    Thanks for the help, Guys/Gals!
    Chuck

    If you do a search in Google for png transparency in IE
    you'll find a
    bunch of links to various solutions. Here's one
    http://koivi.com/ie-png-transparency/
    Peter
    "ChuckRWD" <[email protected]> wrote in
    message
    news:ee4cuq$eqm$[email protected]..
    |I have two banners that are rounded rectangles for a
    website. The have
    quite a
    | few gradients in them, with a gif it looks distorted. I
    can't use jpg, so
    I
    | went with png. In dreamweaver it shows the banners as
    having no
    backgrounds,
    | but in Internet Explorer, they have backgrounds! How can I
    fix this?
    |
    | Also, on another note, when I use the type tool in
    Fireworks, my type
    window
    | will not stretch as I continue to type, I did not set a
    width for the box,
    | however, I get two words into a sentence, and I am jumping
    to the next
    line. I
    | have tried over-and-over to fix this problem, but with no
    luck. It
    happens on
    | and off, but it is driving me crazy.
    |
    | Thanks for the help, Guys/Gals!
    | Chuck
    |

  • I cannot open a .dat file with adobe X1. Anyone have a solution, simple one please?

    I have adobe x1 but I cannot open an email .dat file. Any easy solutions out there please?

    As Test Screen Name states - Adobe Reader opens PDF files only.
    So - fire up Bing or some other web search engine and look for applications that open / process / work email DAT files.
    Be well...

  • I updated Firefox and now I can't attach files to an e-mail in gmail. I have tried multiple files with no success but have no problems in Chrome.

    See above.

    Try to clear cache and cookies by doing the following:
    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
    #Now click the ''Clear now'' button.
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.
    Did this fix your problems? Please report back to us!

  • Why it is necessary that public class name should  same as filename in java

    hi,
    why it is necessary that public class name should same as filename in java.
    As I know that it is a convention, but I want the information why this convention is made.
    thanx.

    user13445117 wrote:
    but suppose if i am creating a java file with default access modifire then we do not need to save the file name as a class name.So, your question is "Why does the rule about top-level classes being in a file of the same name apply +only+ to public classes"?
    If it were applied to all classes, then we could never have two top-level classes in the same file. Doing that is generally not a good idea, but it might be useful from time to time. EJP already told you why it applies to public classes, and, since these are the most common by far, it's a fair compromise that it apply to them but not to other classes.
    Was this the reason the original designers did it that way 15 or so years ago? Don't know, don't care, but it's one plausible explanation. Maybe it was just a balance between simplicity and clarity on the one hand, and flexibility on the other.
    It's certainly not something I can see caring that much about, unless you're doing an in-depth history on Java, or writing an in-depth treatise on computer language and compiler theory.

  • Public class and the source filename

    May be I'm asking a silly question, but why the name of the source file needs to match with the public class's name?
    If the rule is that only one public class is allowed per source file, then the compiler can simply flag the error and quit.
    Any reasons behind this, other than for the ease of compilation?

    I refer you to the Java Language Spec:
    When packages are stored in a file system (�7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
    - The type is referred to by code in other compilation units of the package in which the type is declared.
    - The type is declared public (and therefore is potentially accessible from code in other packages).
    This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.

  • Porblem with the FCConverter class

    Sorry guys about the last thread. I was so sleep deprived that day. Right now I AM LEARNING THE BASICS because this is an intro to java type corse.
    My problem:
    Classes: Temperature.java & FCConverter.java
    Purpose of program: To convert fareighheight to celcius and vice versa
    Problem: I don't have any clue on what to do to make the FCConverter to work. IU have messed around with this for hours and have not yet had any sucess.
    Note: This is an applet so I will supply the HTML source.
    The source code:
    File: TestTemperature.html
    <HTML>
    <HEAD>
    <TITLE>Test</TITLE>
    </HEAD>
    <BODY>
    <APPLET CODE="Temperature.class" WIDTH="200" HEIGHT="50"
    ALT="Test class failed">
    Java is disabled
    </APPLET>
    </BODY>
    </HTML>
    File: Temperature.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    public class Temperature extends JApplet
    implements ActionListener
    private JTextField displayF, displayC;
    private static DecimalFormat displayFormat = new DecimalFormat("0.0");
    public void init()
    Container c = getContentPane();
    c.setBackground(Color.white);
    c.setLayout(new GridLayout(2, 2, 10, 0));
    c.add(new JLabel(" Fahrenheit:"));
    c.add(new JLabel(" Celsius:"));
    displayF = new JTextField(6);
    displayF.setBackground(Color.yellow);
    displayF.addActionListener(this);
    c.add(displayF);
    displayC = new JTextField(6);
    displayC.setBackground(Color.yellow);
    displayC.addActionListener(this);
    c.add(displayC);
    public void actionPerformed(ActionEvent e)
    String s;
    double degrees;
    FCConverter fc = new FCConverter();
    if ((JTextField)e.getSource() == displayF)
    s = displayF.getText().trim();
    degrees = Double.parseDouble(s);
    fc.setFahrenheit(degrees);
    degrees = fc.getCelsius();
    displayC.setText(displayFormat.format(degrees));
    else
    s = displayC.getText().trim();
    degrees = Double.parseDouble(s);
    fc.setCelsius(degrees);
    degrees = fc.getFahrenheit();
    displayF.setText(displayFormat.format(degrees));
    File: FCConverter.java
    public class FCConverter
    public FCConverter()
    String s;
    double degrees;
    return (5/9); // s-32;
    I know temperature's source code is fine because it was supplied by our textbook but we have to write the FCConverter class and I'm am completely stuck on this.
    Can anybody point me in the right direction? Just tell me what methods I need and tell me where they need to be. I think I'll be able to figure the rest out, but this is the part where I'm completely stuck. Thanks for your time.
    __________________

    bbritta
    I think when you give somebody the answer it is
    typically applied without further thought. No
    learning takes place. You might've noticed it on the
    other thread, where you posted the code yet OP asked
    you to describe the algorithm too.
    In the end everyone looses out - OP does not learn,
    you forego the pleasure of teaching (as opposed to
    telling) and the rest of us get to read yet more
    questions that have the same error at their core.
    I hope that doesn't come across as moralizing. I
    respect your right to do as you please and will not
    raise this topic again. :-)I guess my teaching method needs a little work. I guess I start by assuming that if someone is asking a question they want to learn something.
    You might notice that in both cases I gave enough of the answer to help if they wanted to figure out what was going on, but not enough to simply solve the problem for them. It seems I'm just being too oblique.
    No offense taken. Feel free to comment on my posts.

  • Converting mov files with Quicktime Player for iDevices

    I wasn't sure if should post this under iPad or here or at all as it is about coding, but it is about coding for Apple iDevices that can't display Flash, using Quicktime Player or QT Player 7 Pro:
    I'm trying to add the ability for Apple iDevices that can't display tutorials I created in Flash, to see them with H.264. I read that I can simply open the original tutorial that luckily is a .mov file with Quicktime Player 10 in Snow Leopard and File > Save For Web and QT will convert to H.264 and also output several files needed to upload to your server.
    But the only options are for iPhone, iPhone (cellular) and Computer. I assume an iPod would use the iPhone file, but iPad didn't exist yet.
    I chose iPhone and Computer for my test. I got 2 .m4v files a .jpg, a small .mov and a .html page with the code I needed to copy/paste to my target html page.
    Uploaded the files and could see the tutorial movie with my iPad fine. Using FireFox, I saw the beginning of the movie, then got the beachball. After a long wait, I tried a force quit and found that my Mac Pro was crashed too so had to hard shut down. Hate that.
    Rebooted the computer. Tried accessing with Safari this time and it worked fine.
    I also own Quicktime Player 7 Pro pre Snow Leopard (I'm running Snow Leopard now) and tried the conversion with it and noticed a few more config choices, like for frame rate. But the resulting code was about 29 lines of code with expected parameters versus 2 lines of code in the QT Player code which actually really surprised me. With both apps they have JavaScript references for the head tab to files on Apple's library on their site.
    So.. I'm wondering why FF and my computer crash, I did output for computer as well as iPhone. And what to do for FF users and the fact that there's no specific output for iPad, am I OK just using the iPhone output since I can see the file OK on my iPad test.
    Last, I've been reading about HTML5 versus Flash, but assume that what both my QT apps are outputting is HTML4. In the QT Player code there isn't even an embed tag, let alone the video tag I've read about, just a href to the exported Saved For Web .mov file, which I assume must point to the .m4v files that QT outputs and puts in the same folder as the other files, but there's no direct reference to them.
    Sorry for the length, or if this isn't the place for these questions, but I do want to get this right before I convert about 20 tutorials
    I wonder if I should wait until Lion and see if QT is changed to fix the FF crash and adds output for iPad?
    One last thing: when you access the converted file with an iPad, first you see a jpg of the first frame with "Click to Play" in the center. When you do, you get the movie with a play triangle which you have to press to actually start the movie. But when you access the same html file with Safari, all you have to do is click the "Click to Play" and the movie starts as expected. Bug?

    QuickTime X and QuickTime Player Pro create slightly different html code (but it all works about the same way). The "click to play" image file, a "reference" movie, multiple versions for different devices and the html code to preview the page and use as copy/paste into your Web page.
    QuickTime X has fewer options than QuickTime Player Pro. The iPhone preset works just fine on the iPad.
    Your Firefox crash may have been just coincidence and I doubt it was caused by the page code.
    You may want to wait a while longer for the HTML 5 code because browser support is still in the learning stage and millions of PC users still use out of date browsers.
    The reference movie points to the different versions of the file. The code "reads" the device and serves up the correct version for it.
    I don't own an iPad but I suspect it works like my iPod Touch. All of my QuickTime files have the play "triangle" so the click to play image style page requires two clicks on it.

  • "Archive Source Files with Errors"  feature - how to?

    File sender adapter has a feature to  Archive Source Files with Errors.
    I have an adapter module applied to inbound files and in case an error occurs during the processing of the adapter module, I want to make use of this feature , this is because the CC keeps on picking the file with erroneous data after regular specified interval and shows up an error in RWB.
    How can I use the  Archive Source Files with Errors feature with this? Do I have to do anything specific in the adapter module code for this to work?
    Regards,
    Amol

    Hi,
    if you see whats mentioned on the help link
    http://help.sap.com/saphelp_nw04/helpdata/en/f4/2d6189f0e27a4894ad517961762db7/frameset.htm
    it says:
    To archive source files where a permanent error occurred during processing, set the indicator.
    A permanent error occurs either during the conversion of the file content, or in a module in the module processor.
    does this not mean it could be used with errors raised in adapter modules? ideally it should be.

  • Conversion of a file with 2 converters in UCM / IBR?

    Hi Folks,
    This might be a basic question, but would be helpful in making a key decision in our use case.
    Can we configure 2 conversions for a single file format? As we would like to convert each incoming jpeg file into PDF as well as getting the image renditions.
    To get the incoming jpeg file with different renditions, we have configured DAM. In the file formats > jpeg : Digital Media Graphics if configured, then we get the image converted into different renditions like Web, Thumbnail and Preview.
    To get the incoming Jpeg file into PDF, In the file formats > jpeg : Direct PDF export if configured, then we get the image converted into PDF.
    But what we would like is both, as i cannot define both the conversions for the same file format jpeg? We would like the image to be converted into pdf as the Web Viewable format and also with the rendition data. Any pointers here?
    Can each file format supports only one conversion?
    Regards
    Prabhu

    Hi,
    Have you solved this problem?
    Regards
    Carlos

Maybe you are looking for

  • Pipeline performance report in sap crm 7.0 web ui

    Hi Experts, The box Weighted sales volume should be unprefilled (not marked as default) in all Pipeline performance reports for all user groups with a possibility to use these reports. Please let me know how to do this settings in to untoggle the The

  • I have Photoshop on a CD, how do I install on a computer without CD-rom?

    I Have photoshop on a CD, how do I i stall IT on my nen Apple which does not have a CD reader?

  • Flash CS6 does not publish for iOS with ANE included

    Hi, I'm creating a game to run on iOS devices and one of the game requirement is for the device to vibrate on some action. I added the Vibration.ane file (http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/vibration.html) into the l

  • Extracting records from an XML

    Hi All, I have an XML in this format. <?xml version="1.0" encoding="UTF-8" standalone="no"?> <pm testval="1" xmlns:xsi="http://urltest"> <mid>15</mid> <mname>Info</mname> <mrid>145</mrid> <fs id="11"> <fd> <fd-id>73</fd-id> <pfd>23</pfd> <pfn>Test de

  • My airport express suddenly stopped working.

    I have had an airport express unit that I purchased new from Apple about a year ago. The warranty is now expired and it has suddenly stopped working. It shined its amber light for more than an hour, and when I unplugged it to see if it would work som