Static ? static ? static ?

i wish to use the main() function to see my results step by step. but, do i really have to make every method a static one in order to elimate the error message " can't make static reference to method test2() in class testdrive" ? is there a better way ? what does static modifier really do anyway ? what's the use of it ? examples ?
thank you very much !
code =>
public class testdrive {
public static void main(String args[])
System.out.println(test());
static int test()
int a;
a=1 + test2();
return a;
int test2()
int a;
a=2;
return a;

methods or variables declared as static meaning there's only one such copy for the class, even if you initialize objects from the particular class, the method, variable will also be shared between the instances. You can call a static method without an instance of a class, example I have a class Dog with a public static method bark, I can simply call it using:
Dog.bark();
rather than
Dog dog = new Dog();
dog.bark();
Both ways will work, but its better to perform it in the 1st way to show its a static method.
As for static variable, it shares among the instances, there's only 1 copy. For example, in a Counter class, I have a static variable int count.
Counter counter1 = new Counter();
counter1.setCount(2);
System.out.println(counter1.getCount());
This will return you 2.
However, if you intialize another instance:
Counter counter2 = new Counter();
System.out.println(counter2.getCounter());
This will also return you 2.
Correct me if I'm wrong

Similar Messages

  • Converting from non-static to static

    I am tyring to convert a method from non-static to static. I changed a few variables to get it to work and everything is now static in the method except for the getClass() method which it calls, does anyone know how I could work around this.
    Heres the method -
    public static void addObjectToPanel(String type, String name)
            JLabel label = new JLabel("The object");
           // The getClass() here is causing the problem
            label.setIcon(new ImageIcon(getClass().getResource("object.gif")));
            label.setBounds(xCoordinate, yCoordinate, width, height);
            display.setLayout(null);
            display.add(label);
            // After the image is placed by this method, then the x coordinate is moved to allow for the next object
            xCoordinate +=150;
            // This resizes the JPanel as images are added, this solves a potential issue with the JScrollPane
            display.setPreferredSize(new Dimension( (900+xCoordinate), (600+yCoordinate) ));Is there any way I can get around using getClass() or is there anything else I could do, thanks.

    It's a static method. You should know what thename
    of the class that it is in is.Sorry, I didn't see that they were talking about the
    actuall class that the method is in, i missed
    something written earlier.
    I am now using label.setIcon(new
    ImageIcon("object.gif"));and everything is working fine now.
    Thanks everyone for your help.Be warned that this is not the same as what you did initially. The initial version looks in the class loading path. The final version looks in the current directory. I believe your intention is better reflected by the initial version.

  • Non-static and static errors

    Hi,
    I've created a couple classes, say, Input and Output both with a number of different methods.
    Output holds an integer value that Input needs access to.
    I created a method in Output to return the value, such as
    //doneItemCount is declared up here somewhere, etc
    public int items()
         int returnvalue = doneItemCount;
         return returnvalue;
    My Input class has a method from which it tries to get that value
    public void blah()
    int test = Output.items();
    but no matter what i try i get
    non-static method items() cannot be referenced from a static context
    int test = Output.items();
    If i make the methods static, then i get the same error for doneItemCount not being static or whatnot.
    Any tips on how to overcome this?
    Thanks

    Hi!!
    This error means that you are mixing up static and non-static methods. If you keep items() as you wrote it, then it's not a static method, and you'll have to create or use an Output variable in the blah() method. If I'm not clear:
    In Output, you put:
    public int items()
    return doneItemCount;
    And in Input, you put either:
    public void blah()
    int test = new Output().items();//not very useful
    or, if you declared and instanciated an Output variable(say blabla) somewhere else in the Input class, you put:
    public void blah()
    int test = blabla.items();
    Anyway, you should keep items() non-static, since it needs to access to an attribute(doneItemCount).
    Hope this'll help. When I first met this error, I thought it was quite a weird solution, but you get used to it. And the compiler leaves you alone :).

  • Non static to static?

    Hi im getting the following error code when trying to compile....
    148: non-static method stockSize() cannot be referenced from a static context
    for(int x = 0; x < stockDA.stockSize() ;x++){
    Im trying to call it from this method in MainMenu():
      public void actionPerformed(ActionEvent e) {
            JMenuItem source = (JMenuItem)(e.getSource());
            String title = "A text-only menu item";
            String title2 = "Both text and icon";
            if(title.equals(source.getText())){
            for(int x = 0; x < stockDA.stockSize() ;x++){
                 String s = stockDA.showStock(x);
                 output.append(s + newline);
                 output.setCaretPosition(output.getDocument().getLength());}
        }The method itself is within stockDA()
    public int stockSize ()
              int news = stockList.size();
              return news;
         }How do i transfer the data?? it should just be a simple int.... stockList is a vector

    There's no way for the static method to know which
    instance's variable to use, and thus, the compiler
    happily tells you that you can't access an instance
    variable from a class method.To put it more bluntly. You're trying to access a variable that doesn't exist so if the compiler wouldn't tell you your program would crash when you tried to run it.
    The non-static variables only exist within an object. Without an object reference they just aren't there.

  • Static/non-static

    Hi!
    I've read some docs, but can't seem to find an adequate answer to this:
    Why can't a non-static field or method be referenced by a static method and vice versa?
    What's the problem exactly?
    Thanks in advance!

    Wow, I've seemed to have touched on something here. I guess I should clarify what I mean.
    deenen is correct in what I was talking about. In that when you have a static instance variable the memory space is shared by all instances of the class.
    Now if it is good practice or style to do such a thing that is another matter. The talk about how you can't change a static variable is incorrect. The static keyword only means that there is no need for an explicit parameter (or implicit, I always mess the two up). Because it implies the keyword "this".
    The keyword final is used to make it so that you can not change a variable once it has been initialized.
    I have used this static instance variable to my advantage only in debugging objects. When I have lots of objects and they have to all keep the same state I sometimes put a static variable in the class and keep testing it to make sure that the state never changes. Probably bad practice, but like I said, only for debugging. That way I can tell usually when the state changed (which is good in threaded apps). But not which object it was changed on.

  • How to set and static ip_address for a Suse Linux box

    Hi.
    I've done the following to set an static ip address for my Suse 9 Linux box:
    - Take not of inet address value from ifconfig command. ie: (172.17.2.14)
    - Change this value in /etc/hosts for my linux box.
    Since Suse is configure by default to use DHCP for assigning dinamic ip_addresses i'm not sure whether will lastly be set as a static address. I've rebooted my box and it seems to be OK.
    Thanks in advance ...!

    /etc/hosts is not configuration file for ethernet interfaces.
    Configuration files for ethernet interfaces are stored in /etc/sysconfig/network directory.
    For example if you have eth0 device then configuretion for this device is stored in /etc/sysconfig/network/ifcfg-eth0 file.
    Important directives:
    DEVICE - interface (eth0)
    IPADDR - IP address of interface
    NETMASK - netmask
    BOOTPROTO - "static" for static configuration, dhcp for dynamic configuration via dhcp
    ONBOOT - activating interface during boot (yes/no) (yes - of course :-) )
    GATEWAY - default gateway
    So for example you want setup static IP (192.168.10.1 / 255.255.225.0) for eth0 interface.
    Edit the /etc/sysconfig/network/ifcfg-eth0 file and your configuration should be:
    DEVICE=eth0
    IPADDR=192.168.10.1
    NETMASK=255.255.255.0
    BOOTPROTO=static
    ONBOOT=yesThen you simply restart the nework using:
    /etc/init.d/network restartOR
    /sbin/ifdown eth0
    /sbinf/ifup eth0 OR
    ifconfig eth0 down
    ifconfig eth0 up

  • Static-nat and vpn tunnel bound traffic from same private address?

    Hi guys,
    I have site-to-site tunnel local host @192.168.0.250 and remote-host @172.16.3.3.
    For this local host @192.168.0.250, I also have a static one-to-one private to public.
    static (mgmt-192,outside-50) 216.9.50.250 192.168.0.250 netmask 255.255.255.255
    As you can see, IPSec SA shows end-points in question and traffic is being decrypted but not encrypted host traffic never enter into the tunnel, why?
    How can I resolve this problem, without complicating the setup ?
    BurlingtonASA1# packet-tracer input mgmt-192 icmp 192.168.0.250 8 0 172.16.3.3
    Phase: 1
    Type: CAPTURE
    Subtype: 
    Result: ALLOW
    Config:
    Additional Information:
    MAC Access list
    Phase: 2
    Type: ACCESS-LIST
    Subtype: 
    Result: ALLOW
    Config:
    Implicit Rule
    Additional Information:
    MAC Access list
    Phase: 3
    Type: ROUTE-LOOKUP
    Subtype: input
    Result: ALLOW
    Config:
    Additional Information:
    in   0.0.0.0         0.0.0.0         outside-50
    Phase: 4
    Type: ROUTE-LOOKUP
    Subtype: input
    Result: ALLOW
    Config:
    Additional Information:
    in   192.168.0.0     255.255.255.0   mgmt-192
    Phase: 5
    Type: ACCESS-LIST
    Subtype: log
    Result: ALLOW
    Config:
    access-group mgmt_intf in interface mgmt-192
    access-list mgmt_intf extended permit icmp any any 
    access-list mgmt_intf remark *** Permit Event02 access to DMZ Intf ***
    Additional Information:
    Phase: 6
    Type: IP-OPTIONS
    Subtype: 
    Result: ALLOW
    Config:
    Additional Information:
    Phase: 7
    Type: INSPECT
    Subtype: np-inspect
    Result: ALLOW
    Config:
    Additional Information:
    Phase: 8
    Type: NAT-EXEMPT
    Subtype: 
    Result: ALLOW
    Config:
    nat-control
      match ip mgmt-192 host 192.168.0.250 outside-50 host 172.16.3.3
        NAT exempt
        translate_hits = 5, untranslate_hits = 0
    Additional Information:
    Phase: 9
    Type: NAT
    Subtype: 
    Result: ALLOW
    Config:
    static (mgmt-192,outside-50) 216.9.50.250 192.168.0.250 netmask 255.255.255.255 
    nat-control
      match ip mgmt-192 host 192.168.0.250 outside-50 any
        static translation to 216.9.50.250
        translate_hits = 25508, untranslate_hits = 7689
    Additional Information:
    Phase: 10
    Type: NAT
    Subtype: host-limits
    Result: ALLOW
    Config:
    static (mgmt-192,dmz2-172) 192.168.0.0 192.168.0.0 netmask 255.255.255.0 
    nat-control
      match ip mgmt-192 192.168.0.0 255.255.255.0 dmz2-172 any
        static translation to 192.168.0.0
        translate_hits = 28867754, untranslate_hits = 29774713
    Additional Information:
    Phase: 11
    Type: VPN
    Subtype: encrypt
    Result: ALLOW
    Config:
    Additional Information:
    Phase: 12
    Type: FLOW-CREATION
    Subtype: 
    Result: ALLOW
    Config:
    Additional Information:
    New flow created with id 1623623685, packet dispatched to next module
    Result:
    input-interface: mgmt-192
    input-status: up
    input-line-status: up
    output-interface: outside-50
    output-status: up
    output-line-status: up
    Action: allow
    BurlingtonASA1# 
    Crypto map tag: map1, seq num: 4, local addr: 216.9.50.4
          access-list newvpn extended permit ip host 192.168.0.250 host 172.16.3.3 
          local ident (addr/mask/prot/port): (192.168.0.250/255.255.255.255/0/0)
          remote ident (addr/mask/prot/port): (172.16.3.3/255.255.255.255/0/0)
          current_peer: 216.9.62.4
          #pkts encaps: 0, #pkts encrypt: 0, #pkts digest: 0
          #pkts decaps: 53, #pkts decrypt: 53, #pkts verify: 53
          #pkts compressed: 0, #pkts decompressed: 0
          #pkts not compressed: 0, #pkts comp failed: 0, #pkts decomp failed: 0
          #pre-frag successes: 0, #pre-frag failures: 0, #fragments created: 0
          #PMTUs sent: 0, #PMTUs rcvd: 0, #decapsulated frgs needing reassembly: 0
          #send errors: 0, #recv errors: 0
          local crypto endpt.: 216.9.50.4, remote crypto endpt.: 216.9.62.4
          path mtu 1500, ipsec overhead 74, media mtu 1500
          current outbound spi: 37CA63F1
          current inbound spi : 461C843C
        inbound esp sas:
          spi: 0x461C843C (1176273980)
             transform: esp-aes-256 esp-sha-hmac no compression 
             in use settings ={L2L, Tunnel, }
             slot: 0, conn_id: 77398016, crypto-map: map1
             sa timing: remaining key lifetime (kB/sec): (3914997/25972)
             IV size: 16 bytes
             replay detection support: Y
             Anti replay bitmap: 
              0x003FFFFF 0xFFFFFFFF
        outbound esp sas:
          spi: 0x37CA63F1 (936010737)
             transform: esp-aes-256 esp-sha-hmac no compression 
             in use settings ={L2L, Tunnel, }
             slot: 0, conn_id: 77398016, crypto-map: map1
             sa timing: remaining key lifetime (kB/sec): (3915000/25972)
             IV size: 16 bytes
             replay detection support: Y
             Anti replay bitmap: 
              0x00000000 0x00000001

    Hi
    intersting VPN ACL
    object-group network DM_INLINE_NETWORK_18
         network-object YYY.YYY.YYY.0 255.255.255.0
    object-group network DM_INLINE_NETWORK_22
    network-object UUU.UUU.UUU.0 255.255.255.0
    access-list outside_access_in extended permit ip object-group DM_INLINE_NETWORK_22 object-group DM_INLINE_NETWORK_18
    Static NAT
    static (Inside,outside) XXX.XXX.XXX.171 YYY.YYY.YYY.39 netmask 255.255.255.255
    No NAT
    object-group network DM_INLINE_NETWORK_20
    network-object UUU.UUU.UUU.0 255.255.255.0
    access-list Inside_nat0_outbound extended permit ip ZZZ.ZZZ.ZZZ.0 255.255.255.0 object-group DM_INLINE_NETWORK_20
    VPN CLient Pool
    No pool configured as it uses the interesting traffic or protected traffic in ASDM - UUU.UUU.UUU.0 is the IP address range at the far side of the site to site VPN.
    I hope this helps
    Thanks

  • Can't get networkmanager working with openvpn (using static key)

    I'm trying to configure networkmanager to open up my VPN connection - using the static/preshared key method - but no dice.  (Although I'm able to connect just fine using openvpn from the command line)  Anyone been able to get this to work and/or have some suggestions?
    I've installed the packages networkmanager, networkmanager-openvpn, and nm-applet.  I run nm-applet, and configure the connection, but when I try to launch the connection, it fails.  Log file reads as follows:
    Oct 28 16:43:56 daroselin NetworkManager: <info> Starting VPN service 'org.freedesktop.NetworkManager.openvpn'...
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN service 'org.freedesktop.NetworkManager.openvpn' started (org.freedesktop.NetworkManager.openvpn), PID 19131
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN service 'org.freedesktop.NetworkManager.openvpn' just appeared, activating connections
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN plugin state changed: 1
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN plugin state changed: 3
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: OpenVPN 2.1_rc20 x86_64-unknown-linux-gnu [SSL] [LZO2] [EPOLL] built on Oct 18 2009
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: LZO compression initialized
    Oct 28 16:43:56 daroselin kernel: tun0: Disabled Privacy Extensions
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: TUN/TAP device tun0 opened
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: /sbin/ifconfig tun0 10.1.0.2 pointopoint 10.1.0.1 mtu 1500
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN connection 'DARSYS VPN' (Connect) reply received.
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN plugin failed: 2
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: /usr/libexec/nm-openvpn-service-openvpn-helper tun0 1500 1545 10.1.0.2 10.1.0.1 init
    Oct 28 16:43:56 daroselin nm-openvpn[19133]: Exiting
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN plugin failed: 1
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN plugin state changed: 6
    Oct 28 16:43:56 daroselin NetworkManager: <info> VPN plugin state change reason: 0
    Oct 28 16:43:56 daroselin NetworkManager: <WARN> connection_state_changed(): Could not process the request because no VPN connection was active.
    Oct 28 16:43:56 daroselin NetworkManager: <info> Policy set 'Auto eth0' (eth0) as default for routing and DNS.
    Suspiciously, it never seems to try to open a connection to the gateway.  (Note that the gateway's IP address never appears in the log entries.)
    I've configured the connection in nm-applet as follows:
    Gateway:  <internet IP address of the gateway/server I'm trying to VPN into>
    Type:  Static Key
    Static Key:  <the static key file>
    Key direction:  none
    Remote IP address:  10.1.0.1
    Local IP address:  10.1.0.2
    When I launch openvpn from the command line, the conf file reads as follows:
    [darose@daroselin ca]$ cat /etc/openvpn/static-client.conf
    # Sample OpenVPN configuration file for
    # office using a pre-shared static key.
    # '#' or ';' may be used to delimit comments.
    # Use a dynamic tun device.
    # For Linux 2.2 or non-Linux OSes,
    # you may want to use an explicit
    # unit number such as "tun1".
    # OpenVPN also supports virtual
    # ethernet "tap" devices.
    dev tun
    remote <internet IP address of the gateway/server I'm trying to VPN into>
    # 10.1.0.1 is our local VPN endpoint (office).
    # 10.1.0.2 is our remote VPN endpoint (home).
    ifconfig 10.1.0.2 10.1.0.1
    # Our up script will establish routes
    # once the VPN is alive.
    ; up ./office.up
    #up ./client.up
    route 10.0.0.0 255.255.255.0 10.1.0.1
    # Our pre-shared static key
    secret static.key
    # OpenVPN 2.0 uses UDP port 1194 by default
    # (official port assignment by iana.org 11/04).
    # OpenVPN 1.x uses UDP port 5000 by default.
    # Each OpenVPN tunnel must use
    # a different port number.
    # lport or rport can be used
    # to denote different ports
    # for local and remote.
    ; port 1194
    # Downgrade UID and GID to
    # "nobody" after initialization
    # for extra security.
    #user nobody
    #group nobody
    # If you built OpenVPN with
    # LZO compression, uncomment
    # out the following line.
    comp-lzo
    # Send a UDP ping to remote once
    # every 15 seconds to keep
    # stateful firewall connection
    # alive. Uncomment this
    # out if you are using a stateful
    # firewall.
    ; ping 15
    # Uncomment this section for a more reliable detection when a system
    # loses its connection. For example, dial-ups or laptops that
    # travel to other locations.
    ; ping 15
    ping 10
    ; ping-restart 45
    ping-restart 120
    ;keepalive 10 60
    ping-timer-rem
    persist-tun
    persist-key
    # Verbosity level.
    # 0 -- quiet except for fatal errors.
    # 1 -- mostly quiet, but display non-fatal network errors.
    # 3 -- medium output, good for normal operation.
    # 9 -- verbose, good for troubleshooting
    verb 3
    #verb 9
    Anyone have any idea what the problem might be here?

    If anyone's curious, I opened an upstream bug about this:
    https://bugzilla.gnome.org/show_bug.cgi?id=606998

  • Where can I find the file where the static mapping allocations of the DHCP server are stored?

    In our company we are using DHCP to assign static ip addresses to our clients.
    Now we are forced to change the ip address range. To prevent changing each allocation
    of mac-address to ip-address manually with the admin tool i would like to change the allocation
    in the file where the allocations are saved. The reason ist that i just have to use copy & paste for all
    the allocations.
    So how is the file named and where can I find the file where
    the static mapping allocations of the DHCP server are stored? Is it just an ASCII file?
    Must i note anything when i change the file manually?

    From man bootpd:
    BOOTP/DHCP STATIC BINDINGS
         Static IP address to ethernet address bindings are stored in the /etc/bootptab file and in Open Directory.  Bindings specified in the /etc/bootptab file take precedence over those in Open Directory.
         See bootptab(5) for more information about the /etc/bootptab file.
         For Open Directory, bootpd looks at the /Computers records for the following properties:
    /etc/bootptab is a standard text file, while the records in Open Directory can be manipulated either through the command line, or via Workgroup Manager.

  • Xfa.host.setfocus -- to an object e.g. picture or static text etc?

    I can get the setfocus to target another input field - but can work out how (or if it can) to get it to focus the screen to an image or static text component.
    The path selecton tool in the script panel just stays that impassive red circle
    issue arises as selections from radio group opens largish subform with focus set to it's first field - and given layout radio list is lost out the top of the screen (as it were) so we put in a "made the wrong choice? click here to go back" style of button on the top of each subform -
    as the radio button selection displays the subfields using the radiobuttons as the target does not work (get into an event loop)
    so we need something else to target off the go back - i was hoping the title graphic image or static text but cant work it out
    i though the documentation said focus could do images but i cant get it to,
    thanks for any pointers/code line

    Hi,
    I don't think you can focus on static objects (static text, static images).
    I think the down and dirty workaround is your best option. Maybe make the button very small (0.01in) and you can always place a static image (icon) over it to mask the button.
    N.

  • Non-static method paint cannot be referenced from static context

    i cant seem to figure out this error dealing method paint:
    public class TemplateCanvas extends Canvas implements Runnable {
        //static
        public static final int STATE_IDLE      = 0;
        public static final int STATE_ACTIVE    = 1;
        public static final int STATE_DONE      = 2;
        private int     width;
        private int     height;
        private Font    font;
        private Command start;   
        private int state;
        private String message;
        public TemplateCanvas() {
            width = getWidth();
            height = getHeight();       
            font = Font.getDefaultFont();
            //// set up a command button to start network fetch
            start = new Command("Start", Command.SCREEN, 1);
            addCommand(start);
        public void paint(Graphics g) {
            g.setColor(0xffffff);
            g.fillRect(0, 0, width, height);
            g.setColor(0);
            g.setFont(font);
            if (state == STATE_ACTIVE) {
                Animation.paint(g);
            } else if (state == STATE_DONE) {
                g.drawString(message, width >> 1, height >> 1, Graphics.TOP | Graphics.HCENTER);
        public void commandAction(Command c, Displayable d) {
            if (c == start) {
                removeCommand(start);
                //// start fetching in a new thread
                Thread t = new Thread(this);
                t.start();
        public void run() {
            state = STATE_ACTIVE;
            //// start network fetch
            Network network = new Network();
            network.start();
            //// start busy animation
            Animation anim = new Animation(this);
            anim.start();
            //// wait for network to finish
            synchronized (network) {
                try {
                    wait();
                } catch (InterruptedException ie) { }
            //// end animation
            anim.end();
            //// get message from network
            message = network.getResult();
            //// repaint message
            state = STATE_DONE;
            repaint();
    }TemplateCanvas.java:38: non-static method paint(javax.microedition.lcdui.Graphics) cannot be referenced from a static context

    Animation.paint(g); paint() is not a static method. That means you have to call it on an instance of an Animation class (an object), not on the class itself. This is designed this way because the paint() method uses variables that have to be instantiated, so if you don't have an instance to use, it can't access the variables it needs. Static methods don't use instance variables, they only use what's passed in to them, so they don't need to be called on an object. Hope that was clear.

  • Order of execution of static { }  statements question

    Hi,
    I have a question about the order of execution of static statements. Let's imagine the following Class B inheriting of Class A:
    public class A {
        static {  // My static code for A };
    public class B extends A {
        static { // My static code for B; };
    }I know that static statements are executed when classes are loaded, but does Java guarantee an order of execution of static statements between inherited classed (like for constructors) or is it 'random' in that it depends which class is loaded first?
    Thanks,
    J.

    Jrm,
    My advise with this and all such questions is "Suck it and see"...
    Have compiler, will travail ;-)
    Cheers. Keith.
    PS:
    package forums;
    import java.util.List;
    import java.util.ArrayList;
    public class InitBlocksTesterpator
      private List<String> list = new ArrayList<String>() {
          add("This hack uses an anonymous inner-class to populate the list.");
          add("It causes serialization problems");
    C:\\Java\\home\\src\\forums\\InitBlocksTesterpator.java:8: warning: [serial] serializable class <anonymous forums.InitBlocksTesterpator$1> has no definition of serialVersionUID
      private List<String> list = new ArrayList<String>() {
                                                          ^
    1 warning
      static {
        System.out.println("this is a static initialiser block above the main method.");
        System.out.println("this is a instance initialiser block above the main method.");
      public static void main(String[] args) {
        // static { System.out.println("this is a static initialiser block inside the main method."); } // won't compile
        { // this is hardly ever used. just use a method FFS!
          int n = 0; // n is lexically scoped... i.e. it only exists in this code block
          System.out.println("this is a code block inside the main method.");
        new InitBlocksTesterpator().moreBeer();
        System.out.println("this is a instance initialiser block below the main method.");
      static {
        System.out.println("this is a static initialiser block below the main method.");
      public void moreBeer() {
          System.out.println("this is a code block in the moreBeer instance method.");
        // static { System.out.println("this is a static initialiser block in an instance method"); } // won't compile
        System.out.println(list);
    }... just to save you some time ...

  • Static Identity Group Assignment

                       Does anyone know a way to bring in an endpoint with the following attributes?
    Endpoint Policy Name       Static = True
    Static Group Assignment   Static = True
    The 1.2 manual says;
    If the file used for import contains endpoints that have their MAC addresses, and their assigned endpoint profiling policy is the static assignment, then they are not re-profiled during import. 
    To change a dynamic assignment of an endpoint identity group to static, check the Static Group Assignment check box. If the check box is not checked, then the endpoint identity group is dynamic as assigned by the profiler based on policy configuration.
    Statically Profiled Endpoints
    An endpoint can be profiled statically when you create an endpoint with its MAC address and associate a profile to it along with an endpoint identity group in Cisco ISE. Cisco ISE does not reassign the profiling policy and the identity group for statically assigned endpoints.
    A) Does anyone know a way to import from an LDAP database and maintain the Static Group Assignment = True.
    I successfully do an LDAP import of the MAC and Endpoint Group (which comes in as True) but the Static Group Assignment has the Endpoint Group Assignment correct but static is false unchecked.  I don't want these profiling any more.  These are thousands of endpoints and I do not see any way to do a bulk change.  I have tried exporting and re-importing but that doesn't really scale.
    B) Would creation of an endpoint group that is not part of the Profiled endpoint group change the behavior I see above when I do my LDAP import?
    If there were a way to do the bulk selection and change the static property or the Static Group Assignment that would be of huge benefits.  The changes apply to the fields selected within the endpoints while maintaining the MAC property of the endpoint.
    Thanks in advance for any suggestions.

    James,
    That is possible but do you have the dhcp probe enabled and have you thought about setting up an ip helper statement or assigning the ISE node as one of the dhcp servers on the WLC?
    There is a built in check such that if the dhcp class identifier contains MSFT will profile the endpoint as a windows workstation.
    However if this is not the case then you can create the following condition under the Policy Elements > Conditions > Profiling > New Profiler Condition, you will use the create (advanced...) then select NMAP > 135-tcp > then set the operator EQUAL to msrpc.
    Then go under the Microsoft-Workstation and select the option to create a matching identity group (its much easier rather than using the heirarchy option) and set the certainity factor 30. Then add this new condition and set the certainity to 30 also.
    Hope that helps,
    Thanks,
    Tarik Admani
    *Please rate helpful posts*

  • To static or not to static

    Hello, i have a little discussion with a colleage of mine about the use of statics.
    say we have a class (sqlManager) which is used to do all the sql work including the db connection.
    would it be wise to make this class static. in my opinion no. perhaps make it a singleton, but not static.
    My colleage thinks otherwise, make it static i do not need an object of it. it makes it easier to code and smaller.. perhaps this is true, i personally find it ugly. any suggestions.
    Maqish

    I think if in the constructor method there are
    important things to be executed, then the singleton
    pattern will be better. Otherwise, the static
    solution is better.There's always a static initializer (static { .. }) for static classes that have the same basic role for static content as constructors do for instance content. Not playing favorites, just pointing it out for any future readers.
    If you are sure that the class has features that make
    this class immutable, that is, probably it never
    will be necessary to inherit the class because of its
    characteristics, then you may declare its methods as
    final and static.Inheritability is definitely a major factor.
    This doubt is only about the architecture of the
    application, that is, about its features, that must
    be analized to decide what kind of class has to be
    developed.As mentioned, I think a good general rule is that if you need singleton behavior, use a singleton. If you just need some utility methods, use static methods.

  • Alternatives to binding to static variables

    As has been discussed before, flex does not dispatch a binding event when a static variable changes. I was wondering if there are any alternatives to simulate this functionality.
    I have a class called UserDataManager which contains static properties i use throughout my application. One of these is an array which i need to access and change on various different components throughout my application. After changing this must then change the array on all the other components.
    I suspect i could manage this by 2-way binding on an instance of UserDataManager and passing this instance to all the components on creation, however this seems like a computationly and time expensive workaround.
    Are there any alternatives?
    Thanks

    Use a singleton pattern so your statics arent static.

Maybe you are looking for