What's the difference between primitive and reference types?
What's the difference between primitive and reference types?
This is a past exam question and I was wondering what a primitive type and reference type are first off? With an array I know the a reference type is where the array is composed of objects or variables, but a primitive type is where you would create the array with just int or strings. (right?)
How do you think you would answer the question on the test and be given good credit? Without really referring directly to an primitive ARRAY type... Is there a way to do it without that? Or do you think it would be fine to just explain it with the array.
Answer by iamaaron for What's the difference between primitive and reference types?
Refer to this Article to give you some insight on the difference... Compared and Contrasted.
http://pages.cs.wisc.edu/~hasti/cs302/examples/primitiveVsRef.html
Answer by JB Nizet for What's the difference between primitive and reference types?
These are the primitive types in Java:
- boolean
- byte
- short
- char
- int
- long
- float
- double
All the other types are reference types: they reference objects.
This is the first part of the Java tutorial about the basics of the language.
Answer by jamesTheProgrammer for What's the difference between primitive and reference types?
The short answer is primitives are data types, while references are pointers, which do not hold their values but point to their values and are used on/with objects.
Primatives:
boolean
character
byte
short
integer
long
float
double
Lots of good references that explain these basic concepts. http://www.javaforstudents.co.uk/Types
Answer by MuStafa HuSsain for What's the difference between primitive and reference types?
these are primitive data types
- boolean
- character
- byte
- short
- integer
- long
- float
- double
saved in stack in the memory which is managed memory on the other hand object data type or reference data type stored in head in the memory managed by GC
this is the most important difference
Answer by Berguiga.M.Amine for What's the difference between primitive and reference types?
From book OCA JAVA SE 7
Just as men and women are fundamentally different (according to John Gray, author of Men Are from Mars, Women Are from Venus), primitive variables and object reference variables differ from each other in multiple ways. The basic difference is that primitive variables store the actual values, whereas reference variables store the addresses of the objects they refer to. Let?s assume that a class Person is already defined. If you create an int variable a, and an object reference variable person, they will store their values in memory as shown in figure 2.13.
int a = 77; Person person = new Person();
Answer by Paras Singh for What's the difference between primitive and reference types?
In short, At the lowest level we have group of primitive types like "byte, short, int, long, float, double, boolean, char" and Reference types are mostly designed to group primitive types together. So you can have group of int as list, group of char as string, class of the primitives etc.
Another important factor is about primitive type holding a value and reference holding address.
int item = 3; int item2 = item;
Making item2 hold a value 3 still. But for reference type say
Point p = new Point(1.0, 2.0); Point q = p;
q will be holding address of object p and in VM its still one point. Similarly the address is passed to methods for reference type whereas value will be passed for primitive type. Most other differences are also associated with value and address.
Answer by Sachindra N. Pandey for What's the difference between primitive and reference types?
Primitives vs. References First :- primitive types are the basic types of data byte, short, int, long, float, double, boolean, char primitive variables store primitive values reference types are any instantiable class as well as arrays String, Scanner, Random, Die, int[], String[], etc. reference variables store addresses
Second:- primitive types stores values but reference type stores handle to object in heap space. Remember, reference variables are not pointers like you might have seen in C and C++, they are just handle to object, so that you can access them and make some change on object's state.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment