Question about Classes, Abstract  Classes and Interfaces.

I have been experimenting with Classes, Abstract Classes and Interfaces and wonder if anyone can explain this to me.
I was looking for a way to assign a value to a variable and then keep it fixed for the session and have devised this.
First I create an abstract class like this:
public abstract class DatabaseConnection {
private static String ServerName = null;
public static void setServerName(String serverName) {
          ServerName = serverName;
     public static String getServerName() {
          return ServerName;
}and then I created an interface
public interface DatabaseAccess {
     String servername = DatabaseConnection.getServerName();
}And finally the class itself with some test lines in it so I could see what was going on:
public class CreateDatabase extends DatabaseConnection implements DatabaseAccess {
     public static void main (String args[]){
          new CreateDatabase();
     public CreateDatabase(){     
          setServerName("Server Name 1");
          System.out.println ("Before update ");
          System.out.println ("ServerName from Interface           = " + servername);
          System.out.println ("ServerName from Abstract Class = " + getServerName());
          System.out.println ("After update ");
          setServerName("Server Name 2");
          System.out.println ("ServerName from Interface           = " + servername);
          System.out.println ("ServerName from Abstract Class = " + getServerName());
          System.out.println ("==========================");
}The output I get from the above is:
Before update
ServerName from Interface           = Server Name 1
ServerName from Abstract Class = Server Name 1
After update
ServerName from Interface           = Server Name 1
ServerName from Abstract Class = Server Name 2
==========================I also tried this in another class which calls the above class to see if I get the same effect
public class CheckDatabaseAccess {
     public static void main (String args[]){
          new CreateDatabase();
          CreateDatabase.setServerName("Server 3");
          System.out.println("CreateDatabase "+CreateDatabase.servername);
          CreateDatabase.setServerName("Server 4");
          System.out.println("CreateDatabase "+CreateDatabase.servername);
          CreateDatabase.setServerName("Server 5");
          System.out.println("CreateDatabase "+CreateDatabase.servername);
}The output of which is this:
Before update
ServerName from Interface           = Server Name 1
ServerName from Abstract Class = Server Name 1
After update
ServerName from Interface           = Server Name 1
ServerName from Abstract Class = Server Name 2
==========================
CreateDatabase Server Name 1
CreateDatabase Server Name 1
CreateDatabase Server Name 1Can anyone explain why I appear to only be able to change or set the ServerName only the once?
Is this the correct way to do it? If it is it's exactly what I am looking for, a way to set the value of variable once in a session and then prevent it being changed.
Or is there a better way of doing this.
What I want to use this for is for example, storing the accesses to a database on a server. I won't know what server the database will be stored on nor what the database is called so I create an INI file which stores this information in encrypted format, which is set by the database administrator. It occurs to me I can use this method to then retrieve that data once and once only from the INI file and use that throughout the life of the session to access the database.
Any help appreciated
Regards
John

Not gonna read all of it, but this jumps out:
public abstract class DatabaseConnection {
private static String ServerName = null;
public interface DatabaseAccess {
     String servername = DatabaseConnection.getServerName();
}You have two completely separate variables (with two different names, for that matter, since you were inconsistent in your capitalization, but it wouldn't make a difference if they did have the same name with the same case). And the one in the interface is implicitly public, static, and final.
Anytime you refer to "servername" through a reference of type DatabaseAccess, it refers to the one declared in the interface.
Anytime you refer to "ServerName" inside the DatabaseConnection class, it refers to the one declared in that class.

Similar Messages

  • Question about required workshop classes for OCP

    Im working on finishing up my OCP in a few months. Quick question about the workshop class. Is there a test at the end of the week?
    Also how do most people pay for these classes? They are pretty steep and my company doesnt pay for stuff like this for me. Im paying totally out of my own pocket. Also why is the online class the same amount as the instructor lead class? Its not like im in a room at some building that Oracle has to lease for use or something.

    RedDeuce wrote:
    Im working on finishing up my OCP in a few months.What Certificate exactly are you working towards?
    Also how do most people pay for these classes? They are pretty steep and my company doesnt pay for stuff like this for me. Im paying totally out of my own pocket.Then talk to your employer again or maybe look for other jobs that support your plan better.
    Also why is the online class the same amount as the instructor lead class? Its not like im in a room at some building that Oracle has to lease for use or something.They know that you might save on expenses for travel and hotel etc.

  • Less dumb follow-up question about super/sub classes in WDJ?

    This is a follow-up question to the question which Maksim answered in this thread:
    Dumb question about super/sub classes in WDJ
    Question:
    Is there any kind of weird C++-like statement that you can put at the top of a WDJ module to force the module to interpret any reference to superclass A as a reference to some specific subclass B of A ???

    David,
    1. Java has no preprocessor, so C++ tricks are not available. Also I would not recommend such tricks even in C++ if you don't want to turn your colleagues working with same code into personal enemies.
    2. The phrase "easier to create a WDJ custom class loader " makes me smile. First, it's not that simple to interfere WDJ class loading scheme. Plus custom class loaders is not trivial Java topic per se.
    3. The problem "replace all A-s with B-s" is typically solved using one or another GoF creation patterns, like <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory</a> or <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">Factory Method</a>. You may use them with custom class loader, if you really want to
    By the way, all UI controls in WD are created using Abstract Factory (role played by view). So you may use this as good example.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • HT201263 What will i do?screenshot There is a problem with your iPhone. Please visit the Service Answer Center to find answers to all your questions about service options, warranty and other processes in your country. To find your nearest Apple Store, cli

    What will i do? ITune screenshot is as follows >
    There is a problem with your iPhone. Please visit the Service Answer Center to find answers to all your questions about service options, warranty and other processes in your country. To find your nearest Apple Store, click here.

    Do what it said to do.
    "Please visit the Service Answer Center to find answers to all your questions about service options, warranty and other processes in your country. "

  • TS1814 There is a problem with your iPhone. Please visit the Service Answer Center to find answers to all your questions about service options, warranty and other processes in your country. To find your nearest Apple Store, click here.

    There is a problem with your iPhone.
    Please visit the Service Answer Center to find answers to all your questions about service options, warranty and other processes in your country.
    To find your nearest Apple Store, click here.
    Please help me i can aktivate my phone imei 012423006333181.

    There is a problem with your iPhone.
    Please visit the Service Answer Center to find answers to all your questions about service options, warranty and other processes in your country.
    To find your nearest Apple Store
    no imei also

  • Few questions about Calendar / SimpleDateFormat classes

    Hi.
    I have few questions about Calendar class:
    1. How can I get only date representation (without the time)?
    after doing:
    Calendar cal = Calendar.getInstance();
    I tried to clear unecessary fields:
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.HOUR_OF_DAY);
    But after printing the time, it seems that the HOUR was not cleared:
    SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    System.out.println(sdf1.format(cal.getTime()));
    ---> 03/11/2004 17:00:00
    Am I missing somthing?
    2. I want to make sure that two different formats couldn't be compared. i.e., if I'll try to parse one String according to different format -- ParseException will be thrown.
    String date = "19/04/2004 13:06:10";
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date dateObj = sdf.parse(date);
    However, even though that formats are different, no exception is thrown and the return Date is 19/04/2004 00:00:00.
    How can I cause to exception to be thrown if formats are not identical?
    Thanks in advanced

    The Calendar class has a few of what Microsoft would call 'features'. :^)
    To clear the time, call:
    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY), 0, 0, 0);
    If you want 'pessimistic' rather than 'optimistic' date parsing, you have two options:
    1) Call calendar.setLenient(false);
    See if that is strict enough for your needs, otherwise:
    2) Write code to ensure a stricter parsing of the string passed in. For example, you could very simply check the length of the string to determine if time data is also present.
    When parsing, a string like '02/29/02' would parse to the date '03/01/02'. Setting lenient to false may fix this, but the surest way is to do some testing and then make the parsing more pessimistic where it suits your needs.
    - Saish
    "My karma ran over your dogma." - Anon

  • Question about using container class - Map

    hi all
    i have a question about the following :
    i have two sets of data, both use a common filed as key for the map:
    A = {a,b,d,f,g,h} and B = {a,d,e,g,i,k}, each key has a value associated with.
    i need to find out the commonality, and the difference - i.e fields are in map A but not in Map B, and some fields that are in B but not in A. is there any quick method that comes with the collection class that can calculate this? thanks

    yes, the keyset will be used to access values.
    so, SetA.retainAll(SetB) will modify the SetA so that it contains keys that are in both SetA and SetB - the intersection.
    and SetA.removeAll(SetB) will modify the SetA so that it only contains keys that are in SetA, but not in SetB?
    correct?

  • Documentation formats for interfaces, classes, abstract classes

    I am writing docs and want to make sure it conforms to best practices. Here is what I am doing:
    interfaces = [italics, not bold]
    classes = [not italics, bold]
    abstract classes = [italics, bold]
    I am most unsure of abstract classes?
    That is important to me, so please help me get this straight. thanks.

    Everybody knows that interfaces are blue, classes are red, and abstract classes use jumpy text.
    (that was a joke by the way)
    To my mind, using bold for abstract classes would be misleading. Just on an intuitive level, bold seems more concrete. But that's just me. I think the best thing to do is just to decorate the names with "<<interface>>" or "<<abstract>>" so there's no confusion.

  • Question about Inner/Outer classes

    Hello!
    I'm still preparing for java cert exam and have a question. If I have Outer and Inner classes like this:
    Outer o = new Outer();
    Outer.Inner i = o.new Inner();Does this mean that 'i' has a reference to both Outer and Inner classes. Moreover, does 'i' have a reference to the 'this' of 'o'?
    Thanks,
    Victor.

    "i" doesn't have a reference. "i" is a reference. I think you are trying to express this:
    import java.lang.reflect.*;
    public class Outer {
        class Inner {
            private int foo;
        public static void main(String[] args) {
            Outer o = new Outer();
            Outer.Inner i = o.new Inner();
            for(Field field : i.getClass().getDeclaredFields()) {
                System.out.format("%s %s %s;%n", Modifier.toString(field.getModifiers()),
                    ((Class)field.getGenericType()).getName(), field.getName());
    }

  • Difference between Class Pool program and Interface Pool program

    Both Class Pool program and an Interface Pool program indicate that the program contains interfaces that other programs can use globally. What exactly is the difference between them?

    Transparent Table :
    Exists with the same structure both in dictionary as well as in database exactly with the same data and fields.
    " Pooled Table :
    Pooled tables are logical tables that must be assigned to a table pool when they are defined. Pooled tables are used to store control data. Several pooled tables can be cominied in a table pool. The data of these pooled tables are then sorted in a common table in the database.
    " Cluster Table :
    Cluster tables are logical tables that must be assigned to a table cluster when they are defined. Cluster tables can be used to strore control data. They can also be used to store temporary data or texts, such as documentation.
    " what is the major difference between Standard tables, Pooled tables and
    " Clusterd Tables?
    A transparent table is a table that stores data directly. You can read these tables directly on the database from outside SAP with for instance an SQL statement.
    Transparent table is a one to one relation table i.e. when you create one transparent table then exactly same table will create in data base and if is basically used to store transaction data.
    A clustered and a pooled table cannot be read from outside SAP because certain data are clustered and pooled in one field.
    One of the possible reasons is for instance that their content can be variable in length and build up. Database manipulations in Abap are limited as well.
    But pool and cluster table is a many to one relationship table. This means many pool table store in a database table which is know as table pool.
    All the pool table stored table in table pool does not need to have any foreign key relationship but in the case of cluster table it is must. And pool and cluster table is basically use to store application data.
    Table pool can contain 10 to 1000 small pool table which has 10 to 100 records. But cluster table can contain very big but few (1 to 10) cluster table.
    For pool and cluster table you can create secondary index and you can use select distinct, group for pool and cluster table. You can use native SQL statement for pool and cluster table.
    A structure is a table without data. It is only filled by program logic at the moment it is needed starting from tables.
    A view is a way of looking at the contents of tables. It only contains the combination of the tables at the basis and the way the data needs to be represented. You actually call directly upon the underlying tables.
    . Transparent tables (BKPF, VBAK, VBAP, KNA1, COEP)
    Allows secondary indexes (SE11->Display Table->Indexes)
    Can be buffered (SE11->Display Table->technical settings) Heavily updated tables should not be buffered.
    II. Pool Tables (match codes, look up tables)
    Should be accessed via primary key or
    Should be buffered (SE11->Display Table->technical settings)
    No secondary indexes
    Select * is Ok because all columns retrieved anyway
    III. Cluster Tables (BSEG,BSEC)
    Should be accessed via primary key - very fast retrieval otherwise very slow
    No secondary indexes
    Select * is Ok because all columns retrieved anyway.
    Performing an operation on multiple rows is more efficient than single row operations.
    Therefore you still want to select into an internal table.
    If many rows are being selected into the internal table,
    you might still like to retrieve specific columns to cut down on the memory required.
    Statistical SQL functions (SUM, AVG, MIN, MAX, etc) not supported
    Can not be buffered
    IV. Buffered Tables (includes both Transparent & Pool Tables)
    While buffering database tables in program memory (SELECT into internal table) is generally a good idea for performance,
    it is not always necessary.
    Some tables are already buffered in memory.
    These are mostly configuration tables.
    If a table is already buffered, then a select statement against it is very fast.
    To determine if a table is buffered, choose the 'technical settings' soft button from the data dictionary
    display of a table (SE12). Pool tables should all be buffered.
    More at this link.
    http://help.sap.com/saphelp_erp2004/helpdata/en/81/415d363640933fe10000009b38f839/frameset.htm
    Transparent Table:
    Exists with the same structure both in dictionary as well as in database exactly with the same data and fields.
    Pooled Table:
    Pooled tables are logical tables that must be assigned to a table pool when they are defined. Pooled tables are used to store control data. Several pooled tables can be cominied in a table pool. The data of these pooled tables are then sorted in a common table in the database.
    Cluster Table:
    Cluster tables are logical tables that must be assigned to a table cluster when they are defined. Cluster tables can be used to strore control data. They can also be used to store temporary data or texts, such as documentation.
    A transparent table is a table that stores data directly. You can read these tables directly on the database from outside SAP with for instance an SQL statement.
    Transparent table is a one to one relation table i.e. when you create one transparent table then exactly same table will create in data base and if is basically used to store transaction data.
    A clustered and a pooled table cannot be read from outside SAP because certain data are clustered and pooled in one field.
    One of the possible reasons is for instance that their content can be variable in length and build up. Database manipulations in Abap are limited as well.
    But pool and cluster table is a many to one relationship table. This means many pool table store in a database table which is know as table pool.
    All the pool table stored table in table pool does not need to have any foreign key relationship but in the case of cluster table it is must. And pool and cluster table is basically use to store application data.
    Table pool can contain 10 to 1000 small pool table which has 10 to 100 records. But cluster table can contain very big but few (1 to 10) cluster table.
    For pool and cluster table you can create secondary index and you can use select distinct, group for pool and cluster table. You can use native SQL statement for pool and cluster table.
    A structure is a table without data. It is only filled by program logic at the moment it is needed starting from tables.
    A view is a way of looking at the contents of tables. It only contains the combination of the tables at the basis and the way the data needs to be represented. You actually call directly upon the underlying tables.
    http://www.datamanagementgroup.com/Resources/Articles/Article_0106_2.asp
    more info
    http://help.sap.com/saphelp_erp2004/helpdata/en/81/415d363640933fe10000009b38f839/frameset.htm
    http://cma.zdnet.com/book/abap/ch03/ch03.htm
    Check this links.
    http://help.sap.com/saphelp_40b/helpdata/en/4f/991f82446d11d189700000e8322d00/applet.htm
    http://www.techinterviews.com/?p=198

  • Question about the String class

    Did I understood the JLS/Javadoc properly if I say that the String class has got an internal pool of String objects (therefore I expect this pool to be stored in some sort of static variable)?
    Looking at the intern() method in the String class, this is declared as native, which make me think the whole pooling thing is managed internally by the JVM.
    Does this mean that, if there is only a String class per JVM and String literals (or better Strings that are values of constant expressions) are pooled in the String class, the more String constants are around the bigger the String class object becomes?

    Did I understood the JLS/Javadoc properly if I say
    that the String class has got an internal pool of
    String objects (therefore I expect this pool to be
    stored in some sort of static variable)?Yes.
    Looking at the intern() method in the String class,
    this is declared as native, which make me think the
    whole pooling thing is managed internally by the JVM.The intern() method is implemented in some programming language. If you happen to have a Java runtime where it is written as a native method, it is probably implemented in C or C++. Not a terribly important detail.
    Does this mean that, if there is only a String class
    per JVM and String literals (or better Strings that
    are values of constant expressions) are pooled in the
    String class, the more String constants are around
    the bigger the String class object becomes?The String.class object (of type java.lang.Class) as such doesn't "grow", but some memory structure somewhere will contain interned String literals. Probably a hash table of some sort. Yes indeed: if you have String literals in your program, those literals are stored in the computer's memory during runtime so that they can be accessed by the executable program code.

  • Easy question about 3 driver classes

    which are the differences between  
    Plug and Play normal
    Plug and Play (project-style)
    and IVI?
    i have to make a program to comunicate and control a oscilloscope...
    which one i have to download?
    Using LabVIEW 7.1

    I normally use either the Plug and Play or Plug and Play project style. Both are LabVIEW wrapper functions for the instrument calls and come with a DLL that does the translation into, for example, SCPI commands.
    Plug and Play project style is organized more like classes with private and public functions.
    I stay away from IVI because I always seem to need to use vendor specific calls that aren't part of the IVI spec, defeating the whole purpose of using IVI.
    “A child of five could understand this. Send someone to fetch a child of five.”
    ― Groucho Marx

  • Dumb question about super/sub classes in WDJ

    In WDJ, if you want to use some method M of some subclass B that inherits from some class A (because you've customized method M in superclass B), don't you call the method of class B in your WDJ code ???

    David,
    Actually, this is just Java.
    As with any OOP language you get polymorphic objects behavior -- you may use subclass whenever superclass is necessary. Also the version of method called will be always method from the "most derived class" -- actual class used when instantiating object, not the version from class used for declaring variable.
    By the way, this differs java from C++/C# -- all methods are virtual by nature, you should not use "override" keyword to explicitly mark method as overwritten. This C# feature bugs me several times when I did my first steps with .NET.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • Some questions about Unity 4.0 and IPC

    I have a couple of questions and I was looking for "real world" answers, not specific answers from the design guide.
    1.What is this bandwidth requirement between Exchange and Unity and what is it used for?
    2. What sort of issues would we experience if we placed the Unity UM Server at the Colo and placed the Exchange server at the customer premise; with a single T1 between the sites?
    3.What else is involved with a Unity UM install vs. a Unity VM install?
    4.Does the Unity UM and Exchange servers have to be running AD?
    5. Can Unity or the Exchange box be the Domain Controller? Or does it need to be a separate server?
    6. Where does a vm message get streamed from? The Unity server or the Exchange server?

    No you do not pay for FaceTime. It uses your WiFi network, so if you have access to WiFi it is free.
    There is no server required for FaceTime, it will use a direct device to device protocol.
    I can't answer the question about using phones in different countries as that will depend on if you buy a phone that is locked to a carrier.
    If you buy a phone in Germany and it is locked to a German phone network then it will most likely not work with a SIM from Turkey. You would need to buy an unlocked phone which are very expensive as they do not have any carrier subsidy applied to the price.

  • Question about using 10g/11g and APEX ...

    Hi,
    I just recently learned of Oracle's APEX and have a few questions about using it.
    Can I use APEX with express, standard, and enterprise editions of 10g and 11g?
    Are all of these free to use?

    You might want to read about APEX rather than jumping into questions that are reasonably well documented. Info at http://www.oracle.com/technology/products/database/application_express/index.html
    Your specific questions:
    1) Apex is a package that can be installed into any properly licensed database.
    2) The price for the production license of the database varies by edition.
    The price for Express Edition is $0 for use in production. Part of the cost for that edition is 'no Oracle Support based support, no patches, data volume limitation, etc.'

Maybe you are looking for

  • Last Result from Fulltext SQL Query Search Not Showing

    I am creating a custom search results page for MOSS 2007 (using inline .aspx code - don't ask) that uses Fulltext SQL Queries.  I get the results in a ResultTable (see code below) and then use a DataTable to write code to display it (I could have use

  • How can you change the thumbnail selected for an Album in Photos?

    I'm having difficulty changing the photo that is automatically selected as the thumbnail on an iPad Air and iPad Mini.  How can I change this, and what parameter governs which photo is selected? There are a number of threads about changing the name,

  • Binary files in java

    hi I am a bit new to java and am having some problems with binary files. What I need to do is search a binary file for any accurances of the data contained with in another set of binary files. I need to know if the first file contains any of the sign

  • Java Local Cache Outperformed C++ Local Cache in 3.6.1

    Currently I'm using same local cache configuration to publish 10000 record of a portable object and retrieve same item few times from both Java and c++ client with oracle coherence 3.6.1 version. I'm using linux x86 version for both java and c++. Res

  • Auto PO for Services with ME59N

    Hi I have done following settings. 1) Auto PO marked in Vendor master 2)SproMMExternal Services ManagementSource Determination and Default Valuesfor Purchasing Organizations-Auto Po generation for service requitions. 3)PR created with Item cat --D an