Acces specifiers and Access Modifiers in java

what are Access specifiers?
what are Access modifiers?
Whether both of them are same or is there any difference?

As far as I know "access specifier" == "access modifier".
To me, they both mean "the Java Language word which specifies the visibility of a class or class attribute".
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
... but I'm no expert.
Cheers.

Similar Messages

  • What is the difference between access specifiers and access modifiers?

    what is the difference between access specifiers and access modifiers? are they same? if not what is the difference.

    Access Specifier are used to specifiy how the member variable ,methods or class to other classes.They are public ,private and protected.
    Access Modifier:
    1.Access
    2.Non Access
    Access:
    public ,private,protected and default.
    Non Access:
    abstract,final,native,static,synchronized,transient,volatile and strictfp

  • Deploying a VB dll using some web service and accessing it through java

    I'm new to Web Services Based Programming. I would like to know whether this is possible and if so has anyone tried it. I want to create a vb dll that contains the remote methods that the client will access from a java program. After going thru a lot of articles, I'm still unsure on how to do this. I found one method was to Create a VB program/dll, deploy it in a web service and create the java program that accesses by another web service.
    I'm doing this as part of my lab syllabus. The thing is My lab exercises do not state anything about the technologies that I can use to do this.
    This is all that is stated there:-
    Creation Of DLL Using VB And Deploy it in Java
    I just cant get any ideas other than deploying both the parts as web services. If anyone has Better ideas for this, I would really appreciate it.
    I dont know anything about CORBA for languages other than Java and I'm already using the servlets and EJB's in my normal life. I'm also learning the ORB based programming in java. Therefore your help will probably help me learn something new then what I know.

    Sorry I wasn't too specific in my last question.
    This is my java class calling the native method print
    //HeyWorld.java
    class HeyWorld {
    private native void print();
    public static void main(String[] args) {
    new HeyWorld().print();
    static {
    System.loadLibrary("HeyWorld");
    In this case, my C method for calling a C++ method: HelloWorld.cpp
    #include "jni.h"
    #include "stdio.h"
    #include "stdafx.h"
    #Include "HeyWorld.h" //this is where i get my function prototype
    #include "Test.h" //this is the C++ header where the print method and the Test class is
    JNIEXPORT void JNICALL
    Java_HeyWorld_print(JNIEnv *env, jobject obj)
    CTest a; //CTest is the print class I created
    a.print();
    //This is the header for Test.h
    class CTest: public CWinApp
    public:
         CTest(); //constructor
         void print(); //our method
    //And this is the implementation of the class Test.cpp
    void CTest::print()
         printf("Hey World!\n");
         return ;
    I could compile the Test.cpp, HeyWorld.cpp successfully. However when I tried to compile HeyWorld.cpp using
    cl -I<path of jdk include> -I<path of jdk include win32> -LD HeyWorld.cpp -FeHeyWorld.dll,
    the VC++ 6.0 compiler gave me this error:
    HeyWorld.obj:error LNK2001: unresolved external symbol "public:_thiscall CTest::CTest(void)"
    HeyWorld.obj:error LNK2001: unresolved external symbol "public:_thiscall CTest::print(void)"
    Thanks for the help.

  • Overriding and Access Modifier

    Is it must to override with the same access modifiers ?
    For example
    class A {
    protected void test() {
    class B extends A {
    //overrides test() here
    }

    RZP wrote:
    Is it must to override with the same access modifiers ?No, but an overridden method cannot have more restrictive access modifiers, so
    public String getName();cannot be overridden by
    protected String getName();However, the other way around is fine.
    Winston

  • Understanding the combination of inheritance, packages and access modifiers

    I am working on a problem to help my practical understanding of accessing inherited members and methods from a different package using both inheritance and instance variable.
    Unfortunately, I am totally lost when I tried to set this up and understand what was happening.
    Problem:
    Create a class named "classA" under package "pack1" with 4 members (int pub_a, int priv_a, int prot_a, int def_a) and methods (pub_func1, priv_func1, prot_func1, def_func1). Mark the members and methods with 4 different access specifiers (public, private, protected, and default)
    Create a class named "classB" under package "pack2", ClassB will inherit classA of package pack1. ClassB will have 2 members (int pub_b, int priv_b) and methods (pub_func2, prot_func2) with 2 different access specifiers (public, protected)
    Try accessing the members of class classA in package pack1 inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through inheritance.
    Create an instance of class classA inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through the instance.
    Note: In your solution, comment out the lines that are in-accessible with the actual error message at the top of the comment.
    So I produced the following code (I don't think i set this up right):
    //filename A.java
    package pack1;
    public class A {
         public int pub_a;
         private int priv_a;
         protected int prot_a;
         int def_a;
         public int pub_func1() {return 1;}
         private int priv_func1() {return 2;}
         protected int prot_func1() {return 3;}
         int def_func1() {return 4;}
    //filename B.java
    package pack2;
    import pack1.A;
    public class B extends A{
         public     int pub_b;
         private int priv_b;
         public int pub_func2() { return 5; }
         private int priv_func2() { return 6; }
         //directly inherited fields, at least one should be accessible?
         pub_a = 1;
         priv_a = 1;
         prot_a = 1;
         def_a = 1;
         int i;
         // directly inherited methods, at least one should be accessible?
         i = pub_func1();
         i = priv_func2();
         A a = new A();
         //not sure what's accessible here, as no error red underlines appear
         a.pub_a = 1;
         a.priv_a = 1;
         a.prot_a = 1;
         a.def_a = 1;     
    }I would be interested to know how one would approach and address this problem.

    //filename B.java
    package pack2;
    import pack1.A;
    public class B extends A{
         public     int pub_b;
         private int priv_b;
         public int pub_func2() { return 5; }
         private int priv_func2() { return 6; }
         //directly inherited fields, at least one should be accessible?
         pub_a = 1;//true
         priv_a = 1;// false
         prot_a = 1;//true
         def_a = 1;//false
         int i;
         // directly inherited methods, at least one should be accessible?
         i = pub_func1();//true
         i = priv_func2();//false
         A a = new A();
         //not sure what's accessible here, as no error red underlines appear
         a.pub_a = 1;//true
         a.priv_a = 1;//false
         a.prot_a = 1//false;
         a.def_a = 1;//false
    }Edited by: fun_with_me on May 31, 2008 8:30 AM

  • How to Configure the Datasource In JNDI and access it through Java Code

    I have declared under web.xml
    <resource-ref>
          <res-ref-name>MSDataSource</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    Under Jrun-resource.xml
    <data-source>
                <dbname>xxxxxxx</dbname>
                <driver>macromedia.jdbc.sqlserver.SQLServerDriver</driver>
                <url>jdbc:macromedia:sqlserver://xxx.xxx.xx.xx:1433;databaseName=xxxxxxx</url>
                <username>xxxxxxxx</username>
                <password>xxxxxxxxx</password>
                <encrypted>false</encrypted>
                <encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class>
                <native-results>true</native-results>
                <remove-on-exceptions>true</remove-on-exceptions>
                <pool-statements>false</pool-statements>
                <initial-connections>1</initial-connections>
                <connection-timeout>1200</connection-timeout>
                <transaction-timeout>20</transaction-timeout>
                <cache-enabled>false</cache-enabled>
                <cache-size>5</cache-size>
                <cache-refresh-interval>30</cache-refresh-interval>
                <jndi-name>MSDataSource</jndi-name>
                <poolname>Pool</poolname>
                <minimum-size>0</minimum-size>
                <maximum-size>2147483647</maximum-size>
                <user-timeout>20</user-timeout>
                <skimmer-frequency>420</skimmer-frequency>
                <shrink-by>5</shrink-by>
                <maximum-soft>true</maximum-soft>
                <debugging>false</debugging>
                <disable-pooling>false</disable-pooling>
                <isolation-level>READ_UNCOMMITTED</isolation-level>
                <description/>
         </data-source>
    Under jrun-web.xml
    <resource-ref>
          <res-ref-name>MSDataSource</res-ref-name>
          <jndi-name>MSDataSource</jndi-name>
    </resource-ref>  
    Java Code
    String dsndb="java:comp/env/MSDataSource";
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,"jrun.naming.JRunContextFactory");
    p.put(Context.PROVIDER_URL, "localhost:2932");
    InitialContext context=new InitialContext(p);
    System.out.println(context.getEnvironment());
    DataSource ds=(DataSource)context.lookup(dsndb);
    ds.getConnection();
    System.out.println(ds.getConnection().toString());
    Error is
    {java.naming.provider.url=localhost:2932, java.naming.factory.initial=jrun.naming.JRunContextFactory}
    Exception in thread "main" javax.naming.NameNotFoundException: No such binding: MSDataSource
        at jrun.naming.ContextManager.getBinding(ContextManager.java:680)
        at jrun.naming.ContextManager.getBinding(ContextManager.java:686)
        at jrun.naming.ContextManager.getObject(ContextManager.java:690)
        at jrun.naming.ContextManager.lookup(ContextManager.java:463)
        at jrun.naming.JRunNamingContext.lookup(JRunNamingContext.java:501)
        at jrun.naming.JRunNamingContext.lookup(JRunNamingContext.java:644)
        at jrun.naming.JRunNamingContext.lookup(JRunNamingContext.java:470)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at Controller.DBManager.getConnection(DBManager.java:29)
        at Controller.DBManager.main(DBManager.java:42)
    Please help me .
    Thanks in advance

    Also, try to log the username/password in your authenticator, just to be sure that credentials changeGood piece of advice, michael. Worth of it. When I changed the credentials manually, it worked correctly,but from the application, when I logout from 'a', 'a' and log in to 'b', 'b', I got a valuable information.
    I tried debugging like given below for checking from the application.
    class MyAuthenticator extends Authenticator {
        protected PasswordAuthentication getPasswordAuthentication() {
             System.out.println("userrrrrrrrr"+UtilsHTTPS.username);
             System.out.println("pwdddddddddd"+UtilsHTTPS.password);
      .........................................The information I got while debugging from the application was, the username and password does not get printed. It implies that, Authenticator.setDefault(new MyAuthenticator()); does not work as desired ie; even on calling new MyAuthenticator(), it does not get inside the MyAuthenticator class.
    Why does this happen? What is the solution for this?

  • What are Access Modifiers and Access Specifiers??

    what are Access Modifiers and Access Specifiers??
    advance thanks

    http://www.google.com/search?q=what+are+Access+Modifiers+and+Access+Specifiers%3F
    Advance welcome.
    ~

  • Java class access modifiers

    Why java class cannot have private and protected access modifiers?

    class X {
      private class y {}
    }should compile just fine. A top-level private class makes no sense because you wouldn't be able to see it. As for protected, I don't know.

  • (261680070) Q SYNCH-11 How do my web service methods accees EJBs and java classes?

    A<SYNCH-11> How do my web service methods accees EJBs and java classes?
    A<SYNCH-11> It is simple to use java classes, just do it as you would ordinarily.
    The .jws file really contains a simple class so you can program with it in the same
    way that you would use a regular Java class.
    To use an EJB you can go and access it directly as you would with any EJB remote
    client (lookup home stub, create, etc) or if the EJB is deployed to WLS you can use
    a control to provide a very simple wrapper to the EJB. We will see this in detail
    on Thursday in the ADVC module.

    Futher information about the possibility of callback:
    It may be possible for a synchronous only web service (i.e. MS .net) to even paticipant
    in the callback functionality of asynchronous web services. If the client implements
    the appropriate methods for the callback but listens for them on a different port
    or binding than the SOAP request, then web service may be able to build a response
    if the client's "callback URL" is submitted as the beginning part of a conversation.
    Watch the BEA developer forum (http://dev2dev.bea.com) for more information about
    this approach and other tips and techniques for building web services.
    "Adam FitzGerald" <[email protected]> wrote:
    >
    Q<SYNCH-03> I heard that MS .net only implements synchrnonus method? If
    this is true.
    Does it means my async methods will only work with J2EE clients?
    A<SYNCH-03> I do not know the limitations of .net but let me point out that
    is very
    difficult to provide asynchronous web service method invocation (this is
    different
    from an asynchronous web service). HTTP as a general communication protocol
    is based
    on a request and response paradigm so your client libraries will mostly
    likely be
    expecting a response even if it is empty (check the asynchronous example
    from today
    to see that the start method still returns an empty response). You must
    distinguish
    this from the notion of an asynchronous web service which is a business
    operation
    that occurs on the server whose return value/result is not directly associated
    with
    building response to the client. An asynchronous web service can (and generally
    will)
    be started and stopped with web service operations that are invoked synchronously.
    Thus MS .net clients can still be client to WLS hosted web services.

  • Accessing connection from java and generated code

    In JDeveloper 10.1.2.x I set up a connection and selected a stored procedure and generated java to call the stored proc. All good.
    Now, in a web service application I want to call the method in that class that was generated.
    So, the generated class has setConnectionContext(), getConnectionContext(), etc methods. I don't know how to use them. What is a ConnectionContext?
    How do I provide the database connection information and call the method in the generated code that I need?
    My Oracle AS server has a datasource configured that is the one I would like to use, but I don't know how to 'access' it via java in the context of this generated class.
    I am deploying to Oracle AS 10.1.2,
    thanks

    Hi, well CSV is not currently an Excel file, it is a Comma Separated Values
    file which can be read through Excel.
    Now, if you wish to remove the header, I would purpose that you develop an
    application that reads the CSV file, as it is mere text, and that it also reads
    another file (lets call it confirguration.txt) in which you determine the pattern
    you want to remove, then you just read your report and if a string line
    matches the pattern you defined in the configuration.txt file, then you simply
    erase it.
    And if you keep interested in reading real Excel files (xls), I would
    recommend you use POI-HSSF API from Apache.org
    http://jakarta.apache.org/poi/hssf/index.html
    Hope this helps, cya around.

  • Protected and public access modifier - exact difference

    Hi everybody,
    Please help me to give an exact difference between protected access modifier and public
    Protected: Classes with in the same package as well as subclasses can access.
    Public : Classes outside the current class can access while declaring public.
    My doubt is that what is the practical difference between public and protected.
    I searched the net , but the information was not satisfactory to solve my confusion.
    Thanks & regards
    Parvathy

    Obviously doubt = lacks the ability to think for
    oneself.When one person raises a doubt, that does n't mean that he lacks the ability to think . He/She might have thought about it and if he didnt get a proper clarification then it will be posted in the forum.
    In such cases please dont discourage others who are ready to answer the subject.Without knowing the actual intention , i request you please dont reply like this

  • Inheritance and access control - "private protected"

    I'm reopening an old topic, seems to have been last discussed here 2-3 years ago.
    It concerns the concept of restricting access to class members to itself, and its subclasses. This is what "protected" does in C++ and "private protected" did in early versions of the Java language. This feature was removed from Java with a motivation along the lines of not being "simple", and "linear" (in line with the other access modes, each being a true subset of the next). Unfortunately, the article which explained Sun's position on this keyword combination seems to have been removed from the site, so I haven't been able to read its original text.
    But regardless of simplicity of implementation or explaining Java's access modifiers to newbies, I believe it is a fundamental part of OO programming for such an access mode to exist. The arguments for having the standard "private" mode in fact also apply for having a C++-style "protected" mode. (Arguing that classes within a package are related and it therefore doesn't hurt to also give them access to Java's "protected" members, is equally arguing that "private" is unneccessary, which noone of course believes.)
    The whole concept of inheritance and polymorphism and encapsulation builds on the access modes private, protected, and public (in the C++ senses). In Java the "package" concept was added - a nice feature! But I see no justification for it to negate the proper encapsulation of a class and its specializations.

    What effect upon inheritance other than hiding members
    from subclasses is there?
    None. And I cant think of another declaration that prevents members from being inherited but private.
    Of course the onus comes on the programmer with Java's
    definition of "protected" - but
    1) there is rarely a single programmer working within
    a package
    The point was the package is a unit which does not hide from itself. Just like all methods within a class can see each other, all classes within a package can, and all packages within a program can.
    2) it muddies the encapsulation in the design - when
    you see a "protected" method someone else, or yourself
    some time ago - wrote, how do you know if the design
    intention is to have it accessed solely by the class
    and its subclasses, or if it is indeed intended to be
    shared with the whole package? The only way to do
    this today is to always explicitly specify this in the
    comments, which may be lacking, inconsistent, and
    abused (since it isn't enforced).Encapsulation would be implementation hiding. Not method hiding. The only thing you should probably allow out of your package is an interface and a factory anyway.
    I understand where you are coming from, but I really have not had occasion to take issue with it. I can't think of a real codeing situation where this is required. OTOH, I can't think of a coding situation where I need to access a protected method from another class either.

  • Jintegra problem - accessing Matlab from Java??

    Hi:
    Sorry if this post doesn't belong here!!
    I am accessing Matlab from JAVA using JIntegra for COM. I tried running the example in their website.
    (http://j-integra.intrinsyc.com/support/com/doc/other_examples/Matlab.htm)
    I have also posted the example below. I am using their trial version and have included all the jars as said. I get the an unexpected output (all zero's) for reading a variable in the matlab workspace. I don't understand why I get this. Can anyone let me know if this runs for you??
    Thanks
    Pavan
    Example code from Jintegra website:
    public class MatlabExample {
    public static void main(java.lang.String[] args) throws Exception {
    try {
    // DCOM authentication: Make sure NT Domain, NT User, NT Password are valid credentials.
    // Uncomment this line if MatlabExample.java remotely accesses MATLAB :
    // com.linar.jintegra.AuthInfo.setDefault("NT DOMAIN", "NT USER", "NT PASSWORD");
    // Create the MATLAB object
    // Specify host name or IP address of MATLAB machine as parameter if
    // MatlabExample.java remotely accesses MATLAB.
    // mlapp.MLApp mlApp = new mlapp.MLApp("123.456.789.0");
    mlapp.MLApp mlApp = new mlapp.MLApp();
    String result = mlApp.execute("a = [1 2 3 4; 5 6 7 8;]");
    System.out.println("Execute result is " + result);
    double mreal[][] = new double[2][4];
    double mimage[] = new double[0];
    mlApp.getFullMatrix("a", "base", new Object[]{mreal}, new Object[]{mimage});
    for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 4; j++) {
    System.out.println(mreal[i][j]);
    } finally {
    com.linar.jintegra.Cleaner.releaseAll();
    }

    ......How are you declaring the class in your JSP? ... are you instantiating it as a bean using the useBean tag, or just instantiating it in your code like normal.
    Maybe you could post the relevant JSP code too?
    Hello again,
    Only the last string is populating after the file has be tokenized. What I'll like to accomplish is passing the very first string in the file. I did not get too far in the JSP file setup because the code is still in it's testing stage, but any help will be highly appreciated.
    Here is the JSP code
    <%@page import="dev.*" %>
    <%@page session="true" language="java" import="java.io.*" %>
    <jsp:useBean id="wagerhist" scope="request" class="dev.RoundDetail2" />
    <html>
    <head>
    <title>Round Detail</title>
    <body>
      <table width="530" bordercolor="#000000" valign="top">
        <tr>
              <td align="left"  width="19%">Game ID<%=wagerhist.string_gameID%></td>
              <td align="left"  width="30%">  </td>
              <td align="left"  width="20%">card1</td>
              <td align="left"  width="31%">  </td>
            </tr>
      </table>
    </body>
    </html>

  • Default/package/none access modifier

    Hi,
    I was hoping for some discussion on the default/package/none access modifier. It's always really bugged me that we have public, private, protected, and then "none", while it seems to me that it would be less confusing, and more consistent to use the keyword "package", or maybe even "default".
    Then, source code would look like
    public class MyClass{
        public int getValue() {}
        private void setValue() {}
        protected void someMethod() {}
        package int justForPackage() {}
    }I know this concept has come up before, but the books I've read which mention this topic haven't offered any actaul justification/explanation for why there isn't some keyword.
    Anyway, are there any insights as to why java is this way, and any reasons why java should or shouldn't be changed to include the package access modifier.

    A good example is within a tightly grouped package (usually should be this way) you may have some cooperative classes that access methods.
    // one .java file
    public class SomeHelper {
       private void method() {
         new ClassForUsers().accessHiddenLogic();
    // next .java file in same package
    public ClassForUsers {
        /* default-access */ void accessHiddenLogic() {
    }But, you may want to allow users to subclass your ClassForUsers, without giving them access to the hidden logic method directly:
    // another .java file in a different package
    public class UsersSubclass extends ClassForUsers {
        public void userMethod() {
            // can't do this
            accessHiddenLogic();
    }This could be for either business logic or security reasons. So, package level access can be very useful. However, I've seen that in practice it is avoided because it isn't obvious what is going on.

  • Read, Write and create files from java applet.

    Dear All,
    I have created a two files. One is applet and one application file. I am creating a instance of application file in applet. Application file is used for reading, writing and creating files. When I invoke applet from broser it dipslays error wrt file access permission. From the forum search I know that we need to sign the applet / edit the java policy to run the code locally. Final delivery of my code should execute on different system. Its not web. I have created a html page on submitting the form it invokes applet to read the form values from param and needs to update the values in xml file located locally. Please help me on how I can proceed with this fix.
    Thanks in advance.

    Sorry if I have not stated the problem clearly. I need to update content to files hosted in local system using java applets.
    I belive there are two ways to achive that.One with jar signer and one with modifying the java policy file. But this application needs to be installed in different system locally as I have created a application with webpage as useinterface and need to update the content in local files on submission. Not sure on how to modify the java.policy files in each end user system and whats the value we need to update in java policy file. Please help me on the steps to be followed

Maybe you are looking for