Whts the need of static ....

Simple code....
in the following code ... wht is the need of "static"
import java.io.*;
public class sample
static int a=34;
public static void main(String args[])
System.out.println(a);
What "Static " actually means?

What "Static " actually means?It means a field (as in your sample) is associated with the class, as opposed to being associated with the single instances of that class.
You could (I dare assume) and should read the documentation before asking such questions, since they -- presumably -- will explain it better (accumulated accuracy) than anybody here will.
http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html

Similar Messages

  • What is the need for static block?

    this was my interview question..
    what is the scenario where u need a static block?

    SO
    public static String foo = "FOO";
    and
    static
    public String foo="FOO";
    both are static blocks?I don't know what the JLS says about that term. The second one is usually called a static initializer. I wouldn't consider the first one a block, but the JLS may say differently.
    What is the difference between both?They're not quite the same.
    public static String foo = "FOO";
    // is equivalent to
    public static String foo;
    static {
      foo = Foo;
    }Note that the variable must be declared outside the block to be a class member variable.
    Now, consider the following, for which the static initializer block is necessary:
    static ComplexThingummy ct;
    static {
      try {
        ct = new ComplexThingrummy();
        ct.initializeSomethingSomehow();
      catch (CTCheckedException exc) {
        throw new ExceptionInInitializerError(exc);
        // OR
        ct = someDefaultPreInitializedComplexThingummy;
    }

  • Avoiding the need to compile static content...

    Hi,
    In the absence of any way to download fonts on the fly for mobile content, particularly iOS, I am forced to compile around 70MB of fonts into the app. This, needless to say, takes A Long Time. And every time I change anything, it seems to be done _again_.
    But the fonts don't change...
    Can anybody suggest a way to still include the fonts as compiled, embedded media but without the need to recompile them each and every time? For example, if I have them as compiled SWF CSS, can I embed those in a way that will avoid the need to tie up my "Build workspace" task?
    Thanks,
    G

    I'm using Flash Builder 4.6 that _also_ should have incremental compiling and it does, to a point, but it seems to do a full recompile before every export which has become dramatically longer since I increased the number of fonts from 20 to 371...
    I'm wondering whether I can compile the fonts into an SWC library and then use the SWC rather than a library project in my definition? I'll try it once the current compile completes... which may be a while... based on past performance.
    G

  • How to embed the needed fonts in a pdf file

    Dear Sir/Mam,
    We had purchased licenced version of adobe acrobat x pro
    We are facing issues while embedding the font in the pdf file
    Please find the below mentioned requirement
    Requirement:
    We have a pdf file (template) with some static images and static text in it
    We need to populate dynamic data in the pdf file for this we may use text boxes
    We need to set the font name for the text box and embed that font in the pdf template (Eg:Font to be used in textboxes is "RotisSansSerif-Bold")
    Queries
    Please let us know how to embed the needed fonts in the pdf file?
    Once user exports the pdf file, even if user doesnot have the fonts installed in his system the text need to be displayed in the same fonts,how to acheive this?Eg:if we define "RotisSansSerif-Bold" as font in the textboxes,after exporting the data the text need to be in the same font.
    Note:
    Fonts will only installed in the application server and not in the client system
    The mentioned requirement need to work on below mentioned specifications
    OS:Windiows-XP,  Browser:IE
    OS:Mac osx, Browser:Safari
    Regards,
    S.N.Prasad

    There is a similar post just a few away from yours. I will suggest what I would try. Open your job settings file (press or print preferred to get all fonts) and then select the properties and the font tab. At your font to the always embed list and you will likely need to uncheck the subset box. Then save your job settings (give it a name that is meaningful to you, you can not use the settings file you started with as they are read only and I do not recommend changing that). Maybe that will do the job. Of course that is for the creation of the PDF, I forgot you were talking about a form. You might check the form field properties, but I suspect you have already tried that. Guess I don't play with forms enough. Others may be by to answer.

  • How to get the class name  static method which exists in the parent class

    Hi,
    How to know the name of the class or reference to instance of the class with in the main/static method
    in the below example
    class AbstA
    public static void main(String[] args)
    System.out.println(getXXClass().getName());
    public class A extends AbstA
    public class B extends AbstA
    on compile all the class and run of
    java A
    should print A as the name
    java B
    should print B as the name
    Are there any suggestions to know the class name in the static method, which is in the parent class.
    Regards,
    Raja Nagendra Kumar

    Well, there's a hack you can use, but if you think you need it,Could you let me the hack solution for this..
    you probably have a design flaw and/or a misunderstanding about how to use Java.)May be, but my needs seems to be very genuine..of not repeat the main method contents in every inherited class..
    The need we have is this
    I have the test cases inheriting from common base class.
    When the main method of the test class is run, it is supposed to find all other test cases, which belong to same package and subpackages and create a entire suite and run the entire suite.
    In the above need of the logic we wrote in the main method could handle any class provided it knows what is the child class from which this main is called.
    I applicate your inputs on a better way to design without replicating the code..
    In my view getClass() should have been static as the instance it returns is one for all its instances of that class.
    I know there are complications the way compiler handles static vars and methods.. May be there is a need for OO principals to advance..
    Regards,
    Raja Nagendra Kumar
    Edited by: rajanag on Jul 26, 2009 6:03 PM

  • I really need abstract static methods in abstract class

    Hello all.. I have a problem,
    I seem to really need abstract static methods.. but they are not supported.. but I think the JVM should implement them.. i just need them!
    Or can someone else explain me how to do this without abstract static methods:
    abstract class A {
    abstract static Y getY();
    static X getX() {
        // this methods uses getY, for example:
        y=getY();
       return new X(y); // or whatever
    class B extends A {
    static Y getY() { return YofB; }
    class C extends A {
    static Y getY() { return YofC; }
    // code that actually uses the classes above:
    // these are static calls
    B.getX();
    A.getX();I know this wont compile. How should i do it to implement the same?

    Damn i posted this in the wrong thread.. anyways.
    Yes offcourse i understand abstract and static
    But i have a problem where the only solution is to use them both.
    I think it is theoretically possible ot implement a JVM with support for abstract static methods.
    In fact it is a design decision to not support abstract static methods.. thats why i am asking this question.. how could you implemented this otherwise?
    There is an ugly soluition i think: using Aspect Oriented Programming with for example AspectJ.. but that solution is really ugly. So anyone has an OO solution?

  • Require the definition of static members in derived classes

    What I would like to do is require the definition of static variable with a particular signature in all implementing/extending classes of T.
    I would have thought this could be done in the following way:
    public template T
    {public static final Object obj;}To me, this says that all classes implementing this interface must define a member with this exact signature. This is not the case.
    Basically, I'd like to replicate the behavior I see when I extend a serializable class. I get this warning : "The serializable class X does not declare a static final serialVersionUID field of type long".
    Anyone know how to do this? I've googled many search strings, and looks on the forums extensively. I could potentially use code weaving (Aspects), but this adds another level of complexity to my project.
    Thanks in advance,
    Luke

    There is a definite use for it.
    I have an ObjectFactory A. Upon initializing a copy of this object, it scans the given package for all classes. Each class is inspected via Reflection. If there is a variable with a particular signature, in my case public static final ObjectFactory.Constructor, we get a copy of the static variable and add it to a TreeMap.
    Then, whenever someone calls ObjectFactory.createInstance("class name"), I do a lookup, and invoke a method of the Contructor object to return an instance of that object. Also, the ObjectFactory allows the programmer to list all "extensions" loaded in this manner.
    The reason I'm doing this instead of simply putting a static initializer in the "extension" class that would register the extension with the ObjectFactory is:
    I want to control when and where extensions are registered.
    Does this makes sense?
    The only thing I am missing, is how to warn (other than through documentation) the programmer that they need to define this field, exactly in the same manner as classes extended from serialized classes receive a warning that "The serializable class X does not declare a static final serialVersionUID field of type long".
    I could do this using Aspect oriented programming, but that adds a layer of complexity that I do not need.
    Here is the code:
    public class ObjectFactory<T extends Object>
         private TreeMap<String,Constructor<T>> cons=new TreeMap<String,Constructor<T>>();
         public ObjectFactory(String pkg)
              ClassLoader cld=Thread.currentThread().getContextClassLoader();
              if(cld==null)
                   throw new NullPointerException();
              String path=pkg.replace(".","/");
              URL tmp;
              Enumeration<URL> resources;
              File dir;
              try
                   resources=cld.getResources(path);
                   while(resources.hasMoreElements())
                        try
                             tmp=resources.nextElement();
                             dir=new File(URLDecoder.decode(tmp.getPath(), "UTF-8"));
                             if(dir.exists())
                                  String[] files=dir.list();
                                  for(String file:files)
                                       try
                                            if(file.endsWith(".class"))
                                                 Class<?> c=Class.forName(pkg + '.' + file.substring(0, file.length() - 6));
                                                 try
                                                      Field f=c.getField("constructor");
                                                      //TODO add type checking
                                                      Constructor<T> con=Constructor.class.cast(f.get(null));
                                                      synchronized(cons)
                                                           cons.put(con.getName(),con);
                                                           System.out.println(con.getName());
                                                 catch(IllegalAccessException ignored)
                                                 catch(NoSuchFieldException ignored)
                                       catch(ClassNotFoundException e)
                        catch(UnsupportedEncodingException e)
              catch(IOException e)
         public interface Constructor<T>
              public T createInstance();
              public String getName();
         public T createInstance(String name) throws FactoryNotFound
              Constructor<T> c=cons.get(name);
              if(c==null)
                   throw new FactoryNotFound();
              return c.createInstance();
    import ObjectFactory.Constructor;
    public final class Extension
         public static final String desc="";
         public static final String name="Test01";
         public static final Constructor<Object> constructor=new Constructor<Object>()
              public Object createInstance()
                   return new Fighter();
              public String getName()
                   return name;
    }

  • What is the benefit of static in a method/function

    hello,
    can u explain the benefit of static in a function?
    and why i cannot called a function in a static method..example :
    class jalaninFungsi{
         public static void main(String args[])
              tesfungsi();
         public  void tesfungsi()
              System.out.println("ini tesfungsi");
    }its produce error : non-static method tesfungsi() cannot be referenced from static context
    thanks.

    A class is an object.
    So for example:
    class STUDENT
    public String getStudentName()
    return name;
    public int getStudentGPA()
    return GPA;
    In this case, to be able to call the function getStudentName() and getStudentGPA() you will actually need a STUDENT object.
    That means you must have declared e.g. STUDENT A; (in the main method for example), then to call those two functions above you'll need to write A.getStudentName(); and A.getStudentGPA();
    HOWEVER if you have static method, you don't need to create an object of that class type. You can just simply call the class name and then use the dot operator and call the function. e.g.:
    class STUDENT
    public static String getStudentName()
    return name;
    public static int getStudentGPA()
    return GPA;
    Notice that these are static methods, so to access these methods you just need to write STUDENT.getStudentName(); or STUDENT.getStudentGPA();
    Again, notice that here I don't use A . but instead I used the class name (STUDENT.)
    However, this is not logically correct in this (my) particular case to make those two methods static. You'll need to read more by yourself about the usage of static method. I am just trying to explain it to you why there is such thing called static methods in java.
    - o.z.

  • Whts the signifacnce of MANDT field wid data type CLNT in DB table  ??

    nybody pls explain in details?
    Whts the signifacnce of MANDT field wid data type CLNT in DB table  ??
    why fields ( ex- Kunnr - CUSOMER NO. ) is repeated in many tables, but not as a Primary Key , so whts d need to include dis field in many tables? we can fetch the sem field  from a single Table?/

    Hi sager
      MANDT is field for client , means it describes the parcular data is for perticular CLIENT.
      with this field you can contain data for multiple client is one table, that is the advantege.
    and read some basic tutorial .
    Thanks & Regards
    Prashant Gupta

  • Using the iplanet-am-static-group-dn attribute

    Hi,
    I'm trying to construct a user query filter that would return me all the users in a particular static group, in order to integrate with some Synchronisation Services in Plumtree Portal.
    I'm thinking of using the iplanet-am-static-group-dn attribute to do so.
    However it seems that although I can see this attribute, there are restrictions using this for queries. I could only use this attribute to query when using the root account. When I tried the same query with my application account, it returned no results.
    I need advice on a few issues:
    1) Are there other better ways to query for the users in a static group? I'm not sure if the iplanet-am-static-group-dn attribute will remain stable in future releases.
    2) If there are no better ways to do this, can the right to query using this attribute be delegated? This is a system attribute, so I'm not sure if we can really open this out to be searchable by other users other than root?
    Appreciate any advice on this at all, as I'm running on a tight deadline for this solution.
    Thanks!

    The best way to query for members of a static group is to read the list of uniqueMembers in the group entry itself.
    The iplanet-am-static-group-dn attribute is an attribute whose usage is private to Identity Server, and is not guaranteed to be up to date, accurate, or maintained by any other tool that used the directory.

  • I have a fully paid subscription to CC and use of installed programs but I can no longer sign in to CC. It repeatedly says "You've been signed out". I have the need to install another program but I can't sign in.

    I have a fully paid subscription to CC and use of installed programs but I can no longer sign in to CC. It repeatedly says "You've been signed out". I have the need to install another program but I can't sign in.

    Sign Out When Sign In http://forums.adobe.com/thread/1450581?tstart=0 may help
    -and http://helpx.adobe.com/creative-cloud/kb/unable-login-creative-cloud-248.html

  • A better way to generate the needed XML?

    I am working on a 10.2 system and looking to see if there is a better way to generate the resulting XML than what I have come up with. Here is a test case and the output it generates. I don't really like querying the table for each column needed as the real table has eight columns I am pulling. I would like to make one pass on person_h and get the info needed instead of making eight passes, but not sure if it is possible.
    with person_h as
       (select 1 id, 'M' gender, 'W' race, '170' weight from dual union all
        select 1, 'M', 'W', '170' from dual union all
        select 1, 'M', 'W', '180' from dual union all
        select 1, 'M', NULL, '175' from dual union all
        select 1, NULL, 'W', NULL from dual
    select xmlelement("Person",
             (select xmlagg(xmlelement("Sex", gender))
                from (select distinct gender
                        from person_h
                       where id = 1
                         and gender is not null) pg),
             (select xmlagg(xmlforest(race as "Race"))
                from (select distinct race
                        from person_h
                       where id = 1) pg),
             (select xmlagg(xmlforest(weight as "Weight"))
                from (select distinct weight
                        from person_h
                       where id = 1) pg)
           ).getstringval()
      from dual;
    Output
    <Person>
      <Sex>M</Sex>
      <Race>W</Race>
      <Weight>170</Weight>
      <Weight>175</Weight>
      <Weight>180</Weight>
    </Person>Note: Previously posted on the XML DB forum at A better way to generate the needed XML? but still looking for other solutions so putting in front of more eyes here. I have considered using a WITH statement to do the initial query on person_h but haven't tested that yet to see what Oracle really will do as just getting back around to this lower priority task of mine.

    I'm using the WITH statement to simulate a table and DUAL/UNION ALL to create data in that "table". I've seen it used plenty of times in this forum so not sure why a problem for this example. The actual SQL/XML statement hits that "base table" three times, so I didn't include all eight columns because three columns is sufficient to show the problem in the way I coded the SQL. Following the SQL is the sample OUTPUT that SQL statement generates and that is the output I created and need. I'm just looking for other options to achieve the listed output.

  • Whts the corresponding BW report for AP Liability Reconciliation report?

    HI All,
    Whts the corresponding BW report for AP Liability Reconciliation report?
    R/3 report is: S_ALR_87012082 u2013 provides vendor balances that make this up.
    Whts the BW report for validating the R/3 data.
    Please Reply.
    Thansk in Advance.

    Hi,
         Yes, I was getting partial results. I got rid of it by unchecking the the options in the 'SQL' tab in the Universe parameters.
         Thanks for the help.
    Regards,
    Alok.

  • How to trigger Bookmarks (Safari) syncing without the need to merge??

    I found that my bookmarks were out of sync on my home Mac (although iCloud was active), after I did some sorting and cleaning on the office Mac. Since I found no other way (wait or reboot did not help), I did deactivate and then re-activate bookmarks syncing in Preferences => iCloud => Safari. This DID trigger syncing, BUT (after I was offered the option to cancel or to merge) the result was that now the sorting and cleaning work I did before was lost. In fact, it was worse because of the merge in two directions.
    So the question is:
    What can one do to force syncing in a way that avoids the merge?
    It is really stupid that there is no option (like with MobileMe) to select the sync direction. Or did I miss that?

    OK, you are correct, but this is only due to the phrasing of my last comment and not because of the quality of iCloud syncing. MobileMe was MUCH better in this respect! It DID offer the option to overwrite the data WITHOUT the need to manually delete before.
    In addition, this was not the core point.
    The main point is that iCloud for (at least to me) unknown reasons did stop performing its job for the bookmarks that were synced before.
    I would like to know if there is an option to trigger syncing, without the need to delete manually, and then switch of and on again.
    Again, the question is:
    What can one do to force syncing in a way that avoids the merge?

  • Can't restore apple id ,you were blocked for security reasons, but to restore the need to enter the key after typing it sends a 4-digit code on the ipad , but at ipade I am not connected to icloud ,and to connect you need to recover your account

    can't restore apple id , because apple were blocked for security reasons, but to restore the need to enter the key two- step werification . after typing it , apple sends a 4-digit code on the ipad , but at ipad I am not connected to icloud ,so i cant get code . but if i want to recover apple id, i need to  connect icloud, so what to do? help !

    I have (sorry forgot to add that). I was switched around and finally I was told I would be put through to a supervisor but after being on hold for about 10 minutes the phone went dead, I did not lose connection so I do not know if I was hung up on or there was some technical difficulty. I called again yesterday and did in fact speak with a supervisor for Account Security but he told me he did not know why it was happening and put me through to a different number but that ended up not being any helpful either. That's when I decided to give it a shot on here!

Maybe you are looking for

  • Is Creative Cloud compatible with Windows 8.1 Blue?

    Is Creative Cloud Compatible with Windows 8.1 Blue Preview?  I had it working in Windows 8 but now that I am trying 8.1 I can not install it.

  • Migrating PS CS3 to Intel with OS 10.5.6 Plug-ins Not Available

    After migrating CS3 to MacBook Pro, 10.5.6, a list of unavailable plug-ins comes up. All except two were PS plug-ins, NOT aftermarket. Sure enough, they don't show up in the filters menu. I don't know where else they are missing. (migrated from Power

  • LIV-Subsequent debit/credit

    Hi all, My company would like our users to be able post Invoice and Credit memo using MIRO but not Subsequent debit and credit.  Is there a way to make this happen? Few thoughts that come to mind are:   - Remove Subsequent Debit/Credit transactions f

  • Using Classes

    Am trying to use class to do some simple calculations, but its not working, the solution error is "Cannot implicitly convert type 'void' to 'string'". Can anyone help me thank you. namespace myPractise public partial class Main : Form public Main() I

  • Listner problem in RHEL 3

    -bash-2.05b$ lsnrctl start LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 06-MAR-2007 16:34:27 Copyright (c) 1991, 2005, Oracle. All rights reserved. Starting /usr/lib/oracle/xe/app/oracle/product/10.2.0/server//bin/tnslsnr: please wait... TNS