Page 29 of 34 FirstFirst ... 1926272829303132 ... LastLast
Results 281 to 290 of 335
  1. #281

    Default Re: Java Programming


    In java, passing object data type to a method can be the same as pass by reference in c/c++ when passing a pointer data type to a method. Pero java man gud ni, in java, there is no such thing as a pointer data type. There are only primitive data types and object data types.
    Yeah, its true, primitive values are stored in the stack while the objects are stored at heap.

    Quote Originally Posted by boxingfan529
    as far as i remember, only objects are passed as reference. primitive ones are not. primitives are loaded in the stack and not in the heap memory.


  2. #282

    Default Re: Java Programming

    so what should i do if i want to pass-by-reference primitive data types?

  3. #283

    Default Re: Java Programming

    Wala kay mahims bro kay dili jud na pwede.......Anyway, what you can do sguro is instantiate an array object which holds your primitive values and pass that array to the method. So ingon ana nga paagi, mura ug naka simulate na ka ug "pass by reference" (kung c/c++ pa) or, Pwede ka mo buhat ug wrapper class that will hold your primitve values. Instantiate an object of that wrapper class and fill that with the value you want and pass that object to your method.

    Quote Originally Posted by ares623
    so what should i do if i want to pass-by-reference primitive data types?

  4. #284

    Default Re: Java Programming

    what do you mean by wrapper class?
    so sa akong na-sabtan, only objects created with the "new" method are automatically passed by reference, otherwise they aren't/can't.. sakto bah? hehe.

  5. #285

    Default Re: Java Programming

    Quote Originally Posted by ares623
    what do you mean by wrapper class?
    so sa akong na-sabtan, only objects created with the "new" method are automatically passed by reference, otherwise they aren't/can't.. sakto bah? hehe.
    Correct me if I'm wrong. Wrapper class has a primitive equivalence (i.e. int = Integer).

    Objects are automatically passed by reference.

  6. #286

    Default Re: Java Programming

    in java, nothing is passed by reference.. everything is passed by value.. now, for primitives, this is quite easy to understand as this is exactly similar to C's. however, when it comes to objects, murag naay something nga kailangan jud ninyo isabot.. firstly, it is still passed by value.. meaning any changes to it inside the method will not be reflected once mu exit na sa method.. second, what is passed is the value of the reference which points to a memory in the stack which also contains the value of a reference which points to the actual location of the object in the heap.

    so ing ani ang mahitabo if imong i pass kay object... example JButton...
    Code:
    void changeText(JButton btn) {
      //btn = new JButton("new text");    //you are changing the reference to which this variable points to in the stack
      btn.setText("new text");          //you are changing the value of the property of the object in the heap
    }
    as you can see.. btn is an object that was passed from the calling method, now to change the text of the button, you have to access the object in the heap itself, and not just change the reference to which the variable points to in the stack.. you can do this by using methods or setters that the class provides..

    as for primitives, sakto si bcasabee, you can put it in an array and then pass the array.. this is because arrays in java are objects and are therefore stored in the heap. you can also use wrapper classes as what eax said. As of Java 5.0, you can already use the autoboxing and unboxing feature so codes like the ones below are legal..
    Code:
    int intMethod() {
      Integer i = 25;  //an int primitive is assigned to and Integer wrapper variable
      return i;       //an Integer wrapper object is returned instead of an int primitive
    }

  7. #287

    Default Re: Java Programming

    @Ares: Sakto cla bro ( bcasabee and zengatsu).
    http://java.sun.com/docs/books/jls/s...doc.html#37472

    Sayop ko. My bad..


  8. #288

    Default Re: Java Programming

    ^^^ Hope this eliminates confusion.

  9. #289

    Default Re: Java Programming

    Quote Originally Posted by eax
    Looking for the a design pattern. Try this book "Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides"
    hehehe this is the book im reading right now my boss is letting me study his book. dugay dugay napud ni nga book pro daghan kaau kog nakat-onan.

  10. #290

    Default Re: Java Programming

    OT:
    @silent-kill: Pa-xerox ko ani beh.

  11.    Advertisement

Page 29 of 34 FirstFirst ... 1926272829303132 ... LastLast

Similar Threads

 
  1. JAVA PROGRAMMING *****
    By bardnekom in forum Programming
    Replies: 20
    Last Post: 04-18-2013, 12:51 PM
  2. MOVED: JAVA PROGRAMMING *****
    By vern in forum Software & Games (Old)
    Replies: 0
    Last Post: 03-23-2008, 02:43 AM
  3. Java programming help pls...
    By mr_gwen in forum Programming
    Replies: 6
    Last Post: 11-03-2006, 12:30 AM
  4. nid help..java programming
    By ronninalpha in forum Programming
    Replies: 3
    Last Post: 09-13-2006, 07:55 PM
  5. MOVED: Java Programming
    By BadDudes in forum Software & Games (Old)
    Replies: 0
    Last Post: 04-28-2006, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top