How to Access a class outside a package which is friendly to the package

Hi All,
i hav a class which has friendly scope in package X. how do i access it from a class in package Y without declaring it as public.
Rgds,

Hmm. If it is friendly in X, you can access it only from X. There is no way you can access it from Y.

Similar Messages

  • Communicating with classes outside a package

    Hi,
    I what to access a class outside of my package, and this class doesn't belong to any package at all. How do I access it?
    Thanks!
    Erik

    Im using JBuilder to develop, in wich folder do I need to place these classes I want to access, in the projects source root - or in the projects root ? Have'nt got time to test it today, got a bus to catch!
    But it sounds like its gonna work, it is an option I have'nt tried yet anyway!
    Thanks For the help so far!
    /Erik

  • Anyone know how to find available classes in a package?

    Anyone know how to find available classes in a package?
    Given a String like "java.io" I would like to write a method to extract the available classes in this package. I can't seem to find a method for this anywhere in the docs. The package class does not seem to have a method like this.

    Here is some code I tried.
    I'm not very familiar with manipulating JARs The code below is what I tried, but how do I access the packages like "java.io" in the JarFile? and then get the available classes?
    import java.io.*;
    import java.util.*;
    import java.util.jar.*;
    class Tester
         public static void main(String args[])
              try {
                   JarFile jf = new JarFile("c:/jdk1.3/lib/dt.jar");/* usually rt.jar (and 1.4)*/
                   Enumeration e = jf.entries();
                        while (e.hasMoreElements())
                             Object current = e.nextElement();
                             System.out.println(current.toString() + "class:"+current.getClass());
                             try {
                                  Thread.sleep(300);
                             } catch (InterruptedException ie) {}
              } catch (IOException ioe) {System.out.println(ioe.toString());}
                   /*also tried      ClassLoader cl = ClassLoader.getSystemClassLoader();
              try {
                   Enumeration e = cl.getResources("c:/jdk1.3/lib/dt.jar");
                   System.out.println(e.nextElement());
                   while (e.hasMoreElements())
                   System.out.println(e.nextElement());
              } catch (IOException ioe) {System.out.println(ioe.toString());}

  • How to load data from a  flat file which is there in the application server

    HI All,
              how to load data from a  flat file which is there in the application server..

    Hi,
    Firstly you will need to place the file(s) in the AL11 path. Then in your infopackage in "Extraction" tab you need to select "Application Server" option. Then you need to specify the path as well as the exact file you want to load by using the browsing button.
    If your file name keeps changing on a daily basis i.e. name_ddmmyyyy.csv, then in the Extraction tab you have the option to write an ABAP routine that generates the file name. Here you will need to append sy-datum to "name" and then append ".csv" to generate complete filename.
    Please let me know if this is helpful or if you need any more inputs.
    Thanks & Regards,
    Nishant Tatkar.

  • How do I insert a font in Mail which is not in the Pref. scroll-down menu?

    How do I insert a font in Mail which is not in the Pref. scroll-down menu?
    I love Palatino, I have it bot in the System fonts folder, in the home/library/fonts folder and in the computer/library/fonts folder.
    Yet, It does not come out.
    Something else I should be doing?

    Keep in mind that if the recipient of the email doesn't have Palantino active on their computer, they're not going to see that font on their end. Their system will replace any instance of Palantino with whatever font is they have set as the default in their mail program.

  • How to set different icons for different windows which is seen in the top left corner?

    Hi
    How to set different icons for different windows which is seen in the top left corner? I know when building exe there is a option to edit icons or add icons and that icon is default for all the windows in the project. But i want different icons for different windows which is possible in VB.
    Is there any way to set icon by calling any dlls.
    Thanks & Regards
    Samuel J
    [email protected]

    Hi Sam,
    no problem. See the attachment.
    Mike
    Attachments:
    TestIcon_LV85.zip ‏44 KB

  • How to access a class file outside the package?

    created a two java files Counter.java and TestCounter.java as shown below:
    public class Counter
         public void print()
              System.out.println("counter");
    package foo;
    public class TestCounter
         public static void main(String args[])
              Counter c = new Counter();
              c.print();
    Both these files are stored under "D:\Test". I first compiled Counter.java and got Counter.class which resides in folder "D:\Test"
    when i compile TestCounter.java i got the following error message:
    D:\Test>javac -classpath "d:\Test" -d "d:\Test" TestCounter.java
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    2 errors
    what could be the problem. Is it possible to access a class file outside the package?

    ya that's fine..if we have two java files where both resides in the same package works fine or two java files which donot have a package statement also works fine. But my doubt is, i have a Counter.class which does not reside in a package and i have a TestCounter.class which resides in a package "foo", in such a scenario, how do i tell to the compiler that "Counter.class resides in such a path, please look at that and give me TestCounter.class". i cannot use import statement to import Counter.class in TestCounter.java because i donot have a package for Counter.java.

  • Accessing a Class in a Package[in a dir]  via Different Directory

    Hi,
    I am trying to access a class belonging to a package in a directory via another class in a different directory.
    However, there are problems.
    Here is what I do:
    I created a source file ProtectedTest2.java
    package com.java.MyLesson.ch8;
    public class ProtectedTest2
    private int iN1, iN2;
    public ProtectedTest2(){ }
    public ProtectedTest2(int iA, int iB)
    iN1 = iA;
    iN2 = iB;
    public String getNumbers()
    return "Numbers are: "+iN1 +" and "+ iN2;
    } After that, I compiled this file with javac -d C:\\MyUserClasses ProtectedTest2.java. There was no problem.
    I then, created another source file TestPro2.java and imported ProtectedTest2 in TestPro
    import javax.swing.JOptionPane;
    import com.java.MyLesson.ch8.ProtectedTest2;
    public class TestPro2 extends ProtectedTest2
    public TestPro2()
    ProtectedTest2 pro = new ProtectedTest2(8,12);
    JOptionPane.showMessageDialog(null, p.getNumbers() );
    public static void main(String args[])
    new TestPro2();
    System.exit(0);
    } Then, I continue to compile TestPro2.java like this:
    javac -classpath C:\\MyUserClasses TestPro2.java -- there was no problem, but when I try to execute
    TestPro2, the error I got was :
    Exception in thread "main" java.lang.NoClassDefFoundError: com/java/MyLesson/ch8/ProtectedTest2
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader . java:502)
    I understand that the class loader will look into the classpath[current directory] if it cannot find the user- defined class [ProtectedTest2.class] in the standard and optional java packages. Why did the application raise error if I have specified the classpath for the ProtectedTest2.class [which is in C:\MyUserClasses] during the compilation of TestPro2.java ?
    Can someone please correct me and tell me what is the mistake here ?
    Thank you all! :-)

    You need to have C:\MyUserClasses in the class search path both when compiling and running.
    Where the compiler finds a depency class is not saved in the generated .class file, so the runtime is on its own when it needs to find it. If C:\MyUserClasses is not in the class search path, the runtime doesn't know that it should be looking for ProtectedTest2 there. In addition to MyUserClasses you want to search for classes in the current directory (the path ".") so the command to execute TestPro2 is:
    java -classpath .;C:\MyUserClasses TestPro2
    See also the document on how classes are found (if you already haven't)
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html

  • How do I find classes in a package

    Hi,
    I am working on an automation tool which is to be used for testing public API's in our product. The tool is supposed to work this way:
    1. A developer of the API adds a new java file containing the test code for the API in a particular package (which the tool defines). Then he compiles and places the stuff in a jar. There is also a driver class in this same package path defined by the test tool. E.g.
    driver class: com.aaa.bbb.DriverClass
    new API test file: com.aaa.bbb.TestFile
    Now the driver file's job is to find out all the other classes in this particular package and then do some processing. When I tried doing the getPackage() on this driver class to find out about the package I got back a null.
    Question 1: How can I get the package for a particular class (An ugly way to do this would be to strip it out from the classname)
    Question 2: How can I find out what other classes are there in a package?
    Thanks in advance on this.
    Nikhil Singhal
    You can also send me mails at
    [email protected]

    hai
    i have the same problem to finding the classes in package...
    in my case i know the jars name and i have loaded
    classes using code
    ResourceBundle bundle = ResourceBundle.getBundle("source\\ClasssPath");
    StringTokenizer stToke = new StringTokenizer(bundle.getString("ClassPath"),";");
    String temp;
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    while(stToke.hasMoreTokens())
         temp = stToke.nextToken().trim();
    if(temp.endsWith(".jar"))
    JarFile jar = new JarFile(new File(temp));
         Enumeration en = jar.entries();
         String pathStr;
         while(en.hasMoreElements())
         pathStr = en.nextElement().toString();
         System.out.println("pathStr ="+pathStr);
         if(pathStr.endsWith(".class"))
              System.out.println( classLoader.getResource(pathStr));
              System.out.println(classLoader.loadClass(pathStr.substring(0,pathStr.indexOf(".class")).replace('/','.').trim()));
         else classLoader.loadClass(temp);
    here i am getting the classes in that package using code
         String[] filLis = new File("//it//sella//converter//ptlf//startup//").list();
         int length = filLis.length;
         while(length-- >0)
         System.out.println(">"+filLis[length]);
    but its returnign the class when this classes in locale folder(i.e)its not getting the classes in loaded memory...
    so how to retrieve the class files names using package structure name...
    (i am having more then 20 jars files, inthat inside the jar samepackage structue may appear in more then one jars )
    pls help me in this field..
    Thanx

  • How to import a class from a package at the same level

    Hello friends,
    i have a class as Plaf.java
    as
    package org.vaibhav.swing.plaf;
    import java.awt.*;
    import javax.swing.*;
    public class Plaf {
    other code
    }as you see, this is in org.vaibhav.swing.plaf package.
    I have one more class as
    package org.vaibhav.swing.frames;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class StartFrame extends JFrame implements ActionListener {
    other code
    }and this class is in package org.vaibhav.swing.frames
    Please hlp me how to use the class Plaf in StartFrame.java. Rather what import statement should i use in StartFrame.java.
    please help.
    thank you
    Message was edited by:
    vaibhavpingle

    but it then gives me this error
    StartFrame.java:11: package org.vaibhav.swing.plaf
    does not exist
    import org.vaibhav.swing.plaf.*;
    Have you first compiled Plaf.java and saved it in this directory strucuture
    /org/vaibhav/swing/plaf/
    And also have you set your classpath to the parent directory of org folder.
    Message was edited by:
    qUesT_foR_knOwLeDge

  • How to access ejb jar in ear package from other war web package?

    How to access ejb in jar packed in ear package from other war web package?

    Typically you would just look the EJB Home up in JNDI. If you're
    looking for example code, the medrec example in WLS 8.1 or petstore has
    plenty of webapps calling EJBs.
    -- Rob
    CottonXu wrote:
    How to access ejb in jar packed in ear package from other war web package?

  • Why does protected access also allow access from classes in same package

    Having been asked the question and found myself unable to answer it, I wonder if anyone can explain the reasoning why protected access implies the default access as well?

    Sure:
    ---------- class A ------
    package pkg;
    public class A
    protected static int _a;
    private int _i;
    public A() { _i = _a++; }
    public String toString() { return "instance "+_i; }
    --------- class B ------
    package pkg;
    public class B
    public B() { A._a = 27; }
    --------- class C -----
    public class C extends pkg.A
    -------- class main ----
    public class main
    public static void main(String[] args)
    pkg.B b1 = new pkg.B();
    pkg.A a1 = new pkg.A();
    pkg.B b2 = new pkg.B();
    C c1 = new C();
    System.out.println("a1 is "+a1);
    System.out.println("c1 is "+c1);
    The above classes are legal and compile and when
    run, the output is:
    a1 is instance 27
    c1 is instance 27
    (Please note, this is just an example of what is allowed and why I'm curious as to the advantages of this permitted behaviour, NOT what I would ever write!)

  • How to extend a class in same package

    I have a class called LoginBean.java which extends the class ConnectDB.java
    this both files have a statement both the classes are under the directory pmtools.
    and both are included in package pmtools.
    (they both have statement "package pmtools; " at top)
    when i am trying to compile LoginBean.java, it is giving me following error,
    LoginBean.java:7: cannot resolve symbol
    symbol : class ConnectDB
    location: class pmtools.LoginBean
    public class LoginBean extends ConnectDB
    ^
    LoginBean.java:59: cannot resolve symbol
    symbol : variable dbConn
    location: class pmtools.LoginBean
    stmt = dbConn.createStatement();
    ^
    2 errors

    did you compile the other class already? donnow if ithahahaha!!!!!
    ok include the import statement
    import pmtools.ConnectDB;
    in the second class and than compile..

  • How to access super class's super class

    Hello every one.
    I have a question.
    if I have a class like:
    public class A {
    void methoda() {
    void methodb() {
    and a class B extends A and override A's methoda
    public class B extends A {
    void methoda() {
    and a class C extends B which want use A's methoda.
    public class C extends B {
    // and here I want to use class A 's methoda,how can I do?
    thanks a lot

    Try the following. When run it eill print out:
    [In class C] A:B:C
    Now calling A's method: [In class A] A and i is 500Which is what you want right?
    public class TestSuperSuper {
        public static void main (String[] args) throws Exception {
            C c = new C();
            c.setName("A", "B", "C");
            c.setI(500);
            c.methodA();
        static class A {
            String aName;
            int i;
            public void methodA(){
                System.out.println("[In class A] " + aName + " and i is " + i);
            public void setName(String aName){
                this.aName = aName;
            public void setI(int i){
                this.i = i;
        static class B extends A {
            String bName;
            public void methodA(){
                System.out.println("[In class B] " + aName + ":" + bName);
            public void setName(String aName, String bName){
                this.aName = aName;
                this.bName = bName;
        static class C extends B {
            String cName;
            A wrappedA;
            public C(){
                wrappedA = new A();
            public void methodA(){
                reflectOnA();
                System.out.println("[In class C] " + aName + ":" + bName + ":" + cName);
                System.out.print("Now calling A's method: ");
                wrappedA.methodA();
            public void setName(String aName, String bName, String cName){
                this.aName = aName;
                this.bName = bName;
                this.cName = cName;
            private void reflectOnA(){
                try {
                Field[] aFields = wrappedA.getClass().getDeclaredFields();
                for (int i = 0; i < aFields.length; i++){
                    Class fldType = aFields.getType();
    if (fldType.isPrimitive()){
    if (fldType.getName().equals("int")){
    aFields[i].setInt(wrappedA, aFields[i].getInt(this));
    else {
    // now do the other primitive type tests here
    else {
    aFields[i].set(wrappedA, aFields[i].get(this));
    catch (Exception e){
    System.err.println(e);
    The main thing here is that in class C you have an instance variable called wrappedA which is an instance of A and the method called reflectOnA(). Basically, what this method does is it will set all the fields in wrappedA to the same values that this object has so that it would look like that wrappedA is somewhat the same as this object. You will call this method whenever you want to call your superclass' superclass' method.
    Hope this helps.

  • How to access icloud from outside computer

    I want to access my icloud mail from devices NOT my own such as work computer, travel in hotel, other persons computer.  I keep getting this message that tells me to LEARN more and gives all sorts of DOWNLOADING instructions to that computer. ENDLESS loop.   I am not downloading or configuring a public or work computer nor is it my device.   I JUST WANT TO ACCESS MY EMAIL REMOTELY LIKE I DID FOR YEARS ON MAC.MAIL AND CAN DO FROM ANYWHERE ANYTIME WITH OTHER WEB MAILS.  THIS IS SO FRUSTRATING.

    Thanks Roger,   Today I signed up to the apple support communities specifically so I could thank you.   And to publically complain about what Apple did and did not do when then terminated "mobile me" in June 2012.   My short story.... prior to June 2012 I had access to my personal MAC G4 computer, a family member's old IPAD and my work PC.  I tired to migrate to I-Cloud but that was not possible without buying a new home computer.  So next best option would be to use a browser on either my G4, or the IPAD or the PC at work to access this new  "icloud" server, or whatever it is.  I've been a mac user since the very first macs came to the market so I'm not a novice.  I spent many hours googling and searching Mac support to find out how to access my email after they turned off mobile me.  I did not find a way, so I recently bought a mac mini to hopefully get all my new and historical email back and working again.   Yes, I did get back on email again using the  mac mini I had to buy, so apple did OK there. 
    But I find it negelent, perhaps deceptive, that Apple did not provide simple instructions like you did to the mobile me users that Apple effectively kicked off their email service, which I paid  for, for many years.  That's very much like stealing in my opinion....Apple couldn't send me an email to the Icloud link like you provided, with instruction on how to get to my email?  Rather they kept insisting that I migrate to icloud, and insisting that I had to meet computer operating system requirements that my old G4 could not meet.  In my opinion they were not honest.  They effectively created the preception that anyone using an older mac had to buy a new one and I think they knew what they were doing.  I heard someone say that ethics cannot be taught, I agree.  Thanks again Roger, I can now access my Mac Mail from alternative locations.

Maybe you are looking for