Data Curruption and Static methods

public static void myMethod( String Argument)
     int i = 0 ;
What are the chances of data corruption in this static method?
IF there are chances of data corruption, am I corrupt in saying that chances of data corruption for argument and Variable i are same?
Where is function state stored in static method stored? What will happen to this if one thread pre-empts other?
public class a
     int j;
     public static void myMethod( String Argument)
          int i = 0 ;
How is integer j different from integer i? Where will JVM keep these variables ?

Sorry The
int j ;
should have been
static int j;
I thought the behaviour of a variable in a static method will be same as static variable.

Similar Messages

  • My ipod cclassic 80gb is hang after trying dat press and hold method then also its not working please tell me solution

    My ipod cclassic 80gb is hang after trying dat press and hold method then also its not working please tell me solution

    Thanks for your response and good luck wishes, I suspect I will need them!
    In principle, I agree re: the manufacturer's warranty. However, I am pretty upset that this is now my second iPod to develop a critical fault within weeks of the warranty expiring, and frankly, it is not unreasonable to expect a state-of-the-art $500 electronic device to last well beyond one year of life.
    I agree talking to Apple is not likely to do me any good (the clue is in how impossible they make it to talk to them in the first place) - but that is not necessarily OK. I expect I will have to pay money to get the battery replaced - again, not OK (full stop - but especially given the cost of the device and the money I have spent with Apple). Yes, the batteries have a limited lifespan, but it should last longer than this (and surely, I should notice a gradual decline in its functionality, not an instant stop).
    I will try Deggie's suggestion (see my reply post), but probably won't hold my breath (think I have already done this). I probably will have to get the new battery - and probably under my own steam. It is a principle at stake and I feel I should be able to let Apple know how I'm feeling - and am frustrated that they make this virtually impossible. It sends the very clear message that they are not interested in listening to their customers.

  • Datacorruption and static methods

    public static void myMethod( String Argument)
         int i = 0 ;
    What are the chances of data corruption in this static method?
    IF there are chances of data corruption, am I corrupt in saying that chances of data corruption for argument and Variable i are same?
    Where is function state stored in static method stored? What will happen to this if one thread pre-empts other?
    public class a
         int j;
         public static void myMethod( String Argument)
              int i = 0 ;
    How is integer j different from integer i? Where will JVM keep these variables ?

    What are the chances of data corruption in this static
    method? None. As long as this static method only acts on local variables (variables declared inside the method) each call to the method is completely separate from any other call.
    Where is function state stored in static method
    stored? What will happen to this if one thread
    pre-empts other?I'm not sure what you mean by 'function state' but static methods are not associated with an Object, though they can modify and depend on the state of static (class) varaivbles.
    How is integer j different from integer i? Where will
    JVM keep these variables ? j is a member varaible. It is associated wth the instance of the class. i is a local variable and is created at the beginning of a method call and destroyed (eventually) after the method completes.

  • Regarding Returning Parameter and Static method

    Hi frnds,
    I am learning oops ABAP. I want to use returning parameters in method and also STATIC METHOD.
    If any example it will be more helpful
    regards,
    satya

    Hi satya,
                 Check this out ,Its helpful.
    To get some values from a method , one can use the exporting, changing or returning parameters.If one uses RETURNING parameters, the following restrictions apply:-(1) No EXPORTING/CHANGING parameters can be used for the method.(2) Only one RETURNING parameter can be used.(3) RETURNING parameters are only passed by value.This program demonstrates the use of RETURNING parameters and the various ways   to call a method with RETURNING parameter to get the value into some variable.
    Sample Program
    </code>
    report ysubdel1 message-id 00.
    data : w_num type i.
    class c1 definition .
    public section. 
    methods : m1 importing input1 type i
                            input2 type i
                            returning value(result) type i .
    endclass.
    class c1 implementation.
    method  : m1.
    result = input1 * 2 + input2.
    endmethod.
    endclass.
    start-of-selection.
    data : obj1 type ref to c1 . 
    create object obj1.
    Syntax 1     
    call method obj1->m1 EXPORTING input1 = 5                                                        input2 = 4  
                                   RECEIVING result = w_num.  
      write:/5 w_num .
    Syntax 2
         w_num = obj1->m1( input1 = 10 input2 = 20 ).
      write:/5 w_num .
    Syntax 3     
    move obj1->m1( input1 = 2 input2 = 3 ) to w_num .  
    write:/5 w_num .
    </code>
    Static method example
    <code>
    REPORT  zstatic.                              .
    data : num type i.
    class testclass definition.
    public section.
      class-methods : testmethod.
    endclass.
    class testclass implementation.
    method : testmethod.
      num = 5.
      write:/5 num.
    endmethod.
    endclass.
    start-of-selection.
    call method testclass=>testmethod.
    </code>
    Reward Points if u find helpful.
    Thnks & Regards,
    Rajesh

  • Nested Classes and Static Methods

    I was perusing the Java Tutorials on Nested Classes and I came across this...
    [http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html|http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html]
    I was reading the documentation and I read a slightly confusing statement. I was hoping some further discussion could clarify the matter. The documentation on "Nested Classes" says (I highlighted the two statements, in bold, I am having trouble piecing together.)
    Static Nested Classes
    As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ? it can use them only through an object reference.
    Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • Abstract classes and static methods

    I have an abstract report class AbstractReportClass which I am extending in multiple report classes (one for each report, say ReportA, ReportB, ...). Each report class has its own static column definitions, title, etc., which I have to access through a static method getDataMeta() in a web application. Each report has the same exact code in getDataMeta, and no report may exist without these fields. My intuition tells me that AbstractReportClass should contain the code for getDataMeta, but I know that you can't mix abstract and static keywords.
    Am I missing a simple solution to unify the getDataMeta code in the abstract base class? or do I really need to have a static function getDataMeta with the same code in each of the base classes?
    My apologies if this has been discussed many times before.
    Thanks,
    -Andrew

    I'm not trying to be "right"; rather I just asked a question about whether I can do something that seems intuitive. Perhaps you might write code in a different way than I would or perhaps I wasn't clear about every little detail about my code? Do you regularly belittle people who ask questions here?
    I have a loadFromDB() member function in AbstractReport for which all sub classes have an overloaded version. All reports I'm displaying have 4 common fields (a database id and a name and a monetary value, for example), but then each other report has additional fields it loads from the database. Inside ReportX classes' loadFromDB(), I call the superclass loadFromDB() function and augment values to get a completely loaded object. In fact, the loadedData member object resides in AbstractReport.
    I can't use a report unless it has these common features. Every report is an AbstractReport. There is common functionality built on top of common objects. Isn't this the point of inheritance? I'm essentially saying that abstract class Shape has a getArea function and then I'm defining multiple types of Shapes (e.g. Rectangle and Circle) to work with...

  • Generics and static methods

    Hi,
    I need a sanity check to make sure I have not missed design pattern.
    I believe that it is not possible to call a static method defined in a generic type.
    For example:
    public class Red extends Color
        public static Color getHue()
    public class Green extends Color
        public static Color getHue()
    public class GenericColorTest<C extends Color>
        public void fooBar()
             Color hue= C.getHue();  // Is this a valid method call ?
    }Since the base class Color can not define static methods, it seems resonable that a generic type can't make the call to get getHue(). Or am I missing something ? Is there a way for the class GenericColorTest's generic type C to call a static method ?
    Thanks
    HB

    I think I can be ever more specific than gafter on this.
    Your call, "C.getHue()", just plain makes no sense. C is "some kind of Color object", and the class "Color" has no function (static or not) called "getHue()". So calling "C.getHue()" is a simple case of you trying to call a function that isn't in the class.
    In fact you can call static functions, but only if they are in the base class require by the generic definition (erm, sorry can't remember the exact term right now). So, for example, if there was a "getHue()" static function in your class "Color", then sure, you can call "C.getHue()" in your code. But since static functions can't be overridden, the "C.getHue()" will do exactly the same thing no matter which actual class C was at the moment, which doesn't seem to be what you want.
    The right thing to do is just make "getHue()" non-static. Then things will work great.

  • Synchronized and static methods

    I've got a doubt: is it possible to apply syncrhonized to a static method? I know that synchronized takes a lock on the current object, but in the case of a static method there could be no object.
    So how can I synchronize a static method?
    Thanks,
    Luca

    previous X POST(s) :
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411296
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411285
    http://forum.java.sun.com/thread.jsp?forum=31&thread=390499
    http://forum.java.sun.com/thread.jsp?forum=31&thread=374388
    http://forum.java.sun.com/thread.jsp?forum=31&thread=325358
    BOTTOM LINE : Search the forum b4 posting.
    rgds.

  • Interfaces and static methods

    Hi All,
    Does anyone know why you can't declare static methods in an interface? Is there a way round this problem?
    Cheers...

    But this won't:public class StijnsClass
      public static void aMethod()
        System.out.println("StijnsClass.aMethod()");
      public static void main(String[] arg)
        StijnsClass stijnsInstance = new StijnsSubClass();
        stijnsInstance.aMethod();
        System.out.println("Nothing else to say, here?");
    class StijnsSubClass extends StijnsClass
      public static void aMethod()
        System.out.println("StijnsSubClass.aMethod()");
        super.aMethod(); // Wrong!!!
    }You will get:
    "StijnsClass.java:21: non-static variable super cannot be referenced from a static context".
    If you remove static from the subclass method definition, you will get:
    "StijnsClass.java:18: aMethod() in StijnsSubClass cannot override aMethod() in StijnsClass; overridden method is static"
    That's the point. You aren't extending the method; you are only hiding it. To make it work, both methods must be instance methods, ergo, static methods cannot be extended.

  • Fighting with typed data set and GetChildRows() method

    Hi,
    I have problems with the GetChildRows method of a typed data set of a VS2005 data set designer generated code to get all child rows from a parent table. Its not working the way it should and throws a "invalid cast exception" on the line
    DataSet.T_CHILDRow[] childs = parent.GetT_CHILDRows();
    I don't know if the problem is me and my still limited VS/C# knowledge or the Oracle .NET provider (local installed oracle10gR2 and Oracle .NET provider v2.0.50727) or VS2005 and the code generator for the data set.
    I attach the sample script to create my test table T_PARENT and T_CHILD as well as some test data and my program.cs console test application. To create the data set, just add a new data set to the solution named "DataSet.xsd" and drop the two test tables from the database explorer onto the data set designer window.
    TIA,
    Stefan
    ================ sample.sql =================
    create table T_PARENT (
    PARENT_ID number(10) not null,
    PARENT_NAME varchar2(100) not null,
    constraint T_PARENT_PK primary key(PARENT_ID)
    using index
    create table T_CHILD (
    CHILD_ID number(10) not null,
    PARENT_ID number(10) not null,
    CHILD_NAME varchar2(100) not null,
    constraint T_CHILD_PK primary key(CHILD_ID)
    using index
    alter table T_CHILD
    add constraint T_CHILD_FK1 foreign key(PARENT_ID)
    references T_PARENT(PARENT_ID);
    insert into T_PARENT(PARENT_ID, PARENT_NAME) values (1, 'Parent 1');
    insert into T_PARENT(PARENT_ID, PARENT_NAME) values (2, 'Parent 2');
    insert into T_PARENT(PARENT_ID, PARENT_NAME) values (3, 'Parent 3');
    insert into T_CHILD(CHILD_ID, PARENT_ID, CHILD_NAME) values (11, 1, 'First Child of Parent 1');
    insert into T_CHILD(CHILD_ID, PARENT_ID, CHILD_NAME) values (12, 1, 'Second Child of Parent 1');
    insert into T_CHILD(CHILD_ID, PARENT_ID, CHILD_NAME) values (13, 1, 'Third Child of Parent 1');
    insert into T_CHILD(CHILD_ID, PARENT_ID, CHILD_NAME) values (31, 3, 'First Child of Parent 3');
    ================ program.cs =================
    using System;
    using System.Collections.Generic;
    using System.Text;
    using TestChildRows.DataSetTableAdapters;
    namespace TestChildRows
         class Program
              static void Main(string[] args)
                   T_PARENTTableAdapter taParent = new T_PARENTTableAdapter();
                   DataSet.T_PARENTDataTable dtParents = taParent.GetData();
                   foreach (DataSet.T_PARENTRow parent in dtParents)
                        Console.WriteLine("\nParent Name: " + parent.PARENT_NAME);
                        DataSet.T_CHILDRow[] childs = parent.GetT_CHILDRows();
                        if (childs.Length > 0)
                             foreach (DataSet.T_CHILDRow child in childs)
                                  Console.WriteLine("\tChild Name: " + child.CHILD_NAME);
                        else
                             Console.WriteLine("\tThis parent has no childs!");
                   Console.Write("\nPress any key to end program ");
                   Console.ReadLine();
    }

    I found it: the problem is a bug in VS2005. Even SP1 provides no fix. MS just states that it will be fixed in the next VS release, but provides no info which release this will be.
    See:
    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=114983
    For a work arround see:
    http://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=114983
    Stefan

  • Polymorphism and static methods

    Say I have classes A and B:
    public class A {
         public static A newInstance() {
              return new A();
    public class B
    extends A {
    }How can I write the newInstance method in A so that:
    B.newInstance();returns an object of class B instead of A? I know I can override the method in B to make an object of the right type - but is there a way to write the A method so that the correct type is created by any subclasses?

    I suppose this is cheating...
    class A {
       public static A newInstance(Class c)
       throws InstantiationException, IllegalAccessException {
          return (A) c.newInstance();
    class B extends A {
    class Testx {
       public static void main(String[] args)
       throws InstantiationException, IllegalAccessException {
          B b = (B)B.newInstance(B.class);
          System.out.println(b.getClass().getName());  //B

  • Data tables and insertRow() method

    I've seen this question a number of times and no answers yet. Is it possible to create a CRUD page with a data table, without creating additional fields outside of the table, I mean, I saw an example with a single page tabular CRUD, but in order to insert a new row, I had to type the new values outside the table, ain't ther a way to do it with the table only? I've tried appendRow, insertRow (which would be the ideal way, since when a table is paginated it doesn't work). I'm sure it shouldn't be that hard, i'm struggling with this for some days now. Could anyone help me? Thanks.
    My scenario:
    I have a dataprovider, inside my page, that extends ObjectListDataProvider and is set to a class defined by me -> .setObjectClass(UfDTO.class)
    I fill the dataProvider list through another list fetched from the sessionbean:
    .setList(getSessioBean1.getUfList());
    I can delete rows from a checkbox I put into the data table, refresh the data and everything works ok, what i am trying to do, but doesn't work is:
    ufListDataProvider.cursorFirst();
    RowKey first = ufListDataProvider.getCursorRow();
    ufListDataProvider.canInsertRow(first); => returns false!
    If I try the appendRow() it works, but once I try to save, the values entered on the data tables field are lost.

    Yes, I've already looked at the tutorials, there, however, the cachedRowSet is used, and the db table is directly bound to the jsp table, but I don't this tight coupling.
    I can call the appendRow method, however when i call the setValue() method on my properties, they remain null. Just to make thigs clearer, I didn't bind my Hibernate entities to the dataProvider, I used another object that is transformed into one or more entities.
    That's what I have:
    an POJO named UfDTO
    public class UfDTO() {
    private Integer id;
    private String name;
    ...(getters and setters)
    on the SessionBean1
    ObjectListDataProvider listDataProvider...
    listaDataProvider.setObjectType('com.campo.dto.UfDTO);
    public String btnAdd_action(){
    if(listDataProvider.canAppendRow()){
    RowKey rk = ufListDataProvider.appendRow();
    ufListDataProvider.setValue("id", new Integer(0));
    ufListDataProvider.setValue("id", new String());
    return null;
    The code runs fine, with no exceptions, and when I am debugging I can see that after the call to appendRow() a new object is created under the 'appends' properties of the listDataProvider, but even after the calls to setValue, the values of the UfDTO properties into the appends remain null.

  • Completely stuck, get/set, Contructors and Static Methods

    Hi any help would be very appreciated on this one,
    import java.util.Scanner;
    import java.io.*;*
    *import java.util.*;
    public class Course extends Program {
         public Course(String Coursecode, String Coursename){
              Coursecode = stuinput.courseCode;
    public void getCoursecode(){
         return stuinput.courseCode;
    //public String getCourseCode(){
    //     return this.courseCode;
           public static void printCourses() throws Exception
                stuinput[] courseObjArray = new stuinput[18]; //Make sure this is the same as the ammount in the text
                   Scanner sc = new Scanner(new File("courses.txt"));
                   int i=0;
                   boolean found = false;
                   while(sc.hasNextLine())
                   //Delimit this line with scanner
                   Scanner sc1 = new Scanner(sc.nextLine());
                   sc1.useDelimiter(":");
                   courseObjArray[i] = new stuinput(sc1.next(),sc1.next());
                   i++;
                   }//while
                   for(int i1 = 0;i1 < courseObjArray.length;i1++)
                   System.out.println(courseObjArray[i1].courseCode);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println("-----------------");          
           //This print the indexOf what you want to search
              class stuinput
              String courseCode = null;
              String courseName = null;
              stuinput()
              stuinput(String courseCode,String courseName)
              this.courseCode = courseCode;
              this.courseName = courseName;
    import java.io.*;
    public class gradCheck {
         public static void main (String args[]) throws Exception {
                      Course.printCourses(); //Prints All Course but dont need that
    }This ^^^ Is basically the driver class, Im trying to run the printCourse() from the 1st Class I posted.....but it's giving me lots of errors with everything I try, I'm trying to get the values out of that text file and have them broken up so I can use them amoung various class's, I want to use those values inside the Course class, as well as the Program Class and other Class's that extend off of that,
    Any Ideas (im sure there are because im very new), as to how I might to that
    Thanks :-) would be much appreciated

    yes, I still have a lot to learn here I think, Thank you so much, that worked for me, I think I need to read a lot about all of this and understand it......thank you
    If I may, one more thing which I'm really stuck on and if I can get this right, I think my whole program and ideas will just fall into place...Ive been trying to a couple of weeks now and can't quit get it right
    in the above code,
    this bit,
              class stuinput
              String courseCode = null;
              String courseName = null;
              stuinput()
              stuinput(String courseCode,String courseName)
              this.courseCode = courseCode;
              this.courseName = courseName;
              }how do I pass this off to another class through the constructor
    public class Course extends Program {
         public Course(){
         }at the top....say If I want it to be used in the Program class.......or a student class that extends of the this current class above (Course Class)
    Thanks,

  • Advantages and disadvanteges with static methods

    Hi,
    Can anybody suggest me the advantages and disadvantages of static methods? In my project i am using templates which are used by different programs and in that templates i am using static methods.
    It is web application. is there any problems if made methods as static in templates that are used by diferent clients?
    Thanks
    Karimulla

    A static method can't be overridden, and static methods are usually only used for some utility methods and other things which don't belong to the class. I would probably not make the methods static.
    Kaj

  • What's wrong with static methods?

    Answers on an postcard please.

    I think the point here is that sometimes people come from a procedural background (or maybe no background) and they start with main, and one static method leads to another. They reach a tipping point where they are reluctant to define non-static methods to a class because it's all static elsewhere. And static method can't access instance data, so their data becomes largely static as well. When the dust settles, they are programming procedually in Java. So too many static methods is a sign that you may be programming procedurally instead of doing OOP, but using static appropriately is still cool.
    And let's not get pedantic. What goes wrong if I make my String class's getLength method static?
    public final class MyString {
        private int length;
        public static int getLength(String s) {
            return s.length;
    }It's a misuse of static, but it doesn't break my design.

Maybe you are looking for

  • First battery charge and current issues?

    Hi! I just bought a new MacBook (2.0 GHz, 160 GB). I have two quick questions: 1. I plugged in my AC adapter, turned on the notebook for about 5 minutes to make sure it works fine, etc, then shut it down to let the battery charge. Would I have lost a

  • Two Users on one computer

    I have an IPod Mini and a new shuffle, and have my iTunes set up with my own Library. My daughter just go a new IPod, 30Gig and needs to set it up, but I don't wont to have her music mixed with mine. Is there a way to set up two different libraries o

  • NEED PODCAST HELP AND PLAYLIST HELP!@#$

    A)I just upgraded my 20 gig plain to 5g 30 gig. I downloaded video podcasts like nba playoffs and abc news(free you know). It comes up on my itunes library and I then dragged it onto the Ipod. It appears. Fine and good. Disconnect the ipod and its no

  • Excise invoce for Invoice correction Request

    Dear Gurus, created one order in which base price ented as 3500/- instead of 3800/-) and delivery, Invoice and Excise invoice also done. i want to bill for difference of amount. For this I have created price diff invoice with reference to previous in

  • How can I reset cursor to left on subject line

    Composing e-mail OR forwarding..the subject line cursor is offset to the right instead of on the left of the subject box.  This just occurred recently from my memory.  Ran AVG virus check with nothing found there.  Any one know how to get the cursor