Results 1 to 3 of 3

Thread: Parameters

  1. #1
    MIA6 is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default Parameters

    Describe the differences that can occur during parameter passing in Java when the parameters are variables that store primitives vs. non-primitives.

    So the parameters that store primitives basically store numbers, Double, int, etc. They pass by values. Non-primitives include objects i think, does it also include String? Objects pass by values too, but objects always object reference, so I'm bit confused. So what's the difference if I say objects pass by values and objects pass by reference? Thanks.

  2. #2
    renamed is offline Member
    Join Date
    Dec 2009
    Location
    Rio de Janeiro
    Posts
    38
    Rep Power
    0

    Default

    In Java, if you change the value of a variable passed by argument inside a method , it will not change its value.

    Java Code:
    public class Numbers extends JFrame {
    	
    	public void a (int x){
    		x = 3;
    	}
    	
    	public void a(String x){
    		x = "eu";
    	}
    	
    	public static void main(String[] args) {
    		int x = 0;
    		String xx = "vc";
    		System.out.println(x);
    		System.out.println(xx);
    		new Numbers().a(x);
    		new Numbers().a(xx);
    		System.out.println(x);
    		System.out.println(xx);
    	}
    }
    Below a list of primitive types in Java
    • boolean
    • char
    • byte
    • short
    • int
    • long
    • float
    • double


    Any other value is considered non-primitive... including String.
    Please don't laugh at my English... I'm trying my best! :)

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,998
    Blog Entries
    7
    Rep Power
    19

    Default

    Java has only one parameter passing mechanism: pass by value; all objects in Java are manipulated through their references (or 'pointers' in C-lingo). Those pointers are also passed by value.

    kind regards,

    Jos

Similar Threads

  1. How to add two other parameters?
    By albi_87m in forum Advanced Java
    Replies: 3
    Last Post: 05-18-2009, 01:25 PM
  2. NULL Value Of parameters
    By riders in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-14-2008, 02:29 PM
  3. Hiding parameters from URL
    By Saurabh321 in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 12:43 PM
  4. get parameters in jsp
    By cecily in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-05-2007, 04:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •