Results 1 to 6 of 6

Thread: Input and output arguments in java

  1. #1
    Join Date
    Dec 2009
    Posts
    204

    Input and output arguments in java

    Hello,
    I have not much experience with Java, as will show my newbie question, I want to make a method that takes as arguments a number of things, and change. In C++ I spent the arguments References with the "&". I note that the "&" does not exist in Java, or the "inout" style which I used in C++. The arguments are inout they default? Any help on this is highly appreciated. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    356

    Re: Input and output arguments in java

    Hello,
    You can build a specific object that contains attributes like whatever you want to edit. You can do the get / set methods for these attributes in order to access and modify. But in general, it depends on what you want to conceive. Anyway, if you want to change a parameter of a method, you can do so only if it is an object. You can not change and the reference passed as a parameter of a method.
    Code:
    Public void tri(Object o){
    ...
    o = new Object(); / / Prohibited!
    ...
    }

  3. #3
    Join Date
    Dec 2009
    Posts
    192

    Re: Input and output arguments in java

    Hello,
    I think even I have a similar kind of a problem in my code and I have no solution for it, if you can help then it would be great.
    This is what I am trying to do.
    Code:
    Public static void hand(String args[]){
    ...
    int temp =0;
    Widget = mbid new Bidule();
    MyMethod(temp mbid);
    ...
    / / mbid has been changed without my explicitly specifies
    / / As temp passed by myMethod References rather than copy
     
    / / temp have not been changed! He passed by copy, not References!
    }
    If you have any solution for this then please help me. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    347

    Re: Input and output arguments in java

    Hello,
    Primitive types are passed by value and objects by reference is as simple as that. If you would like your primitive types are modified, encapsulates in an object (classes Integer, Double, Float, etc.): version 1.5 of java you have the autoboxing which enables you to avoid some cumbersome WRITE. If you need more information on the primitive types in java then you can view the java api on the sun's official site.

  5. #5
    Join Date
    Nov 2009
    Posts
    359

    Re: Input and output arguments in java

    Hello,
    Just have a look at the following code, this might help you.
    Code:
    Public class MyIntWrapper{
     
    	
    	private int val;
    
    	Public MyInt(int val){
    		this.val = MyValue;
    	}
     
    	Public int getMyValue(){
    		return val;
    	}
     
    	Public void setMyValue(int val){
    		this.val = MyValue;
    	}
     
    }
     
    / / To declare an instance of that class would be:
    	MyIntWrapper wrp = new MyIntWrapper(5);
     
    / / now such a method of any class changing the value of an object MyIntWrapper
     
     
    Public 	MyOtherClass{
     
    	Public static void addOne(MyIntWrapper wrp){
    		wrp.setMyValue(getMyValue()+1)
    	}
    }
     
    / / example of use
    	MyIntWrapper wrp = new MyIntWrapper(5);
    MyOtherClass.addOne(Wrapper);
    System.out.System.out.println(wrp.getValue); / / returns 6

  6. #6
    Join Date
    Nov 2009
    Posts
    583

    Re: Input and output arguments in java

    Hello,
    Just take a look at the following example, see if this helps you
    Code:
    Public class Wrapper <X>{
     
    	
    	private X val;
    
    	Public Wrapper(X value){
    		this.val = Value;
    	}
     
    	Public X getValue(){
    		return val;
    	}
     
    	Public X void setValue(X value){
    		this.val = Value;
    	}
     
    }

Similar Threads

  1. What is Input Output Operator in C++?
    By Shiva$m in forum Software Development
    Replies: 4
    Last Post: 29-12-2010, 02:33 AM
  2. Command Line Arguments in java
    By Vipul03 in forum Software Development
    Replies: 2
    Last Post: 22-02-2010, 04:39 PM
  3. What are Command-Line Arguments in Java?
    By Beter 2 Burn Out in forum Software Development
    Replies: 8
    Last Post: 20-02-2010, 03:37 PM
  4. Exception in java input/output
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 22-01-2010, 12:05 PM
  5. How to pass runtime arguments to JAVA Application
    By Nihar Khan in forum Software Development
    Replies: 2
    Last Post: 30-03-2009, 01:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,275,165.83026 seconds with 16 queries