473,507 Members | 5,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About pointers

129 New Member
Hello friends,
Is pointer concept is there in java? If so how to use? if not why?
Feb 26 '08 #1
12 1524
sukatoa
539 Contributor
Hello friends,
Is pointer concept is there in java? If so how to use? if not why?
Pointer is not on java.

The language designers decided to abstract memory management to a higher level in Java than in C. The reason for this is that it is easy to make mistakes using pointers and other lower level memory management techniques. These mistakes can lead to bugs. hard to read code, memory leaks that waste system resources, and security issues.
Feb 26 '08 #2
Laharl
849 Recognized Expert Contributor
Java actually does have pointers. When you declare an object without initializing it, eg String str;, you're actually getting a pointer. Using new returns a pointer as well to help with stack space when passing large objects to functions. The "pass by reference" method that Java uses to pass objects to functions? It's "pass by pointer" under the hood. Java hides all this pointer functionality to avoid the pitfalls of detailed memory management.
Feb 26 '08 #3
JosAH
11,448 Recognized Expert MVP
Pointer is not on java.
Java is full of pointers (every object is actually a pointer to an object state (value)).
Java just doesn't have pointer arithmetic but pointers are all over the place.

kind regards,

Jos
Feb 26 '08 #4
BigDaddyLH
1,216 Recognized Expert Top Contributor
Java actually does have pointers. When you declare an object without initializing it, eg String str;, you're actually getting a pointer. Using new returns a pointer as well to help with stack space when passing large objects to functions. The "pass by reference" method that Java uses to pass objects to functions? It's "pass by pointer" under the hood. Java hides all this pointer functionality to avoid the pitfalls of detailed memory management.
Java does not have pointers. The word "pointer" only occurs twice in the JLS, and then only informally. To say Java has pointers would only confuse C programmers and frighten the children.
Feb 26 '08 #5
JosAH
11,448 Recognized Expert MVP
Java does not have pointers. The word "pointer" only occurs twice in the JLS, and then only informally. To say Java has pointers would only confuse C programmers and frighten the children.
Say no more about that darn NullPointerException then :-)

kind regards,

Jos
Feb 26 '08 #6
BigDaddyLH
1,216 Recognized Expert Top Contributor
Say no more about that darn NullPointerException then :-)

kind regards,

Jos
This is one of those moments that .NET got it right when it was plagiarizing Java. They renamed it "NullReferenceException".
Feb 26 '08 #7
JosAH
11,448 Recognized Expert MVP
This is one of those moments that .NET got it right when it was plagiarizing Java. They renamed it "NullReferenceException".
I consider that name even more obfuscating because it has nothing to do with
references as C++'s T& reference to a type T. It's my constitutional fundamental
right to consider them pointers but no 'rithmetic ;-)

kind regards,

Jos
Feb 26 '08 #8
edwardrsmith
62 New Member
Everyone who said that every object in Java is a pointer is correct. A pointer is just an address in memory at which information is stored. Unlike C and C++, pointers are abstracted. That means that it is impossible to explicitly declare a pointer. At the same time it is also easier because there is no need to worry about memory management because of the garbage collector takes care of clearing memory and memory allocation is automated as well.
Feb 26 '08 #9
sukatoa
539 Contributor
Everyone who said that every object in Java is a pointer is correct. A pointer is just an address in memory at which information is stored. Unlike C and C++, pointers are abstracted. That means that it is impossible to explicitly declare a pointer. At the same time it is also easier because there is no need to worry about memory management because of the garbage collector takes care of clearing memory and memory allocation is automated as well.
since sasimca007 ask about pointers, i think he/she knows C or C++, he/she was just asking if the pointer he/she have used in C/C++ was also in java...

A pointer is just an address in memory at which information is stored. Unlike C and C++
You're correct, but no abstract pointer in java that can be used to link such addresses...

Correct me if im wrong,
Sukatoa
Feb 27 '08 #10
BigDaddyLH
1,216 Recognized Expert Top Contributor
since sasimca007 ask about pointers, i think he/she knows C or C++, he/she was just asking if the pointer he/she have used in C/C++ was also in java...



You're correct, but no abstract pointer in java that can be used to link such addresses...

Correct me if im wrong,
Sukatoa
The best advice you can give a C/C++ programmer moving to Java is to forget ever thing they know about pointers; every hack and fudge and weird pointer arithmetic, and void*, and arrays via pointers and function pointers and ...
Feb 27 '08 #11
Ganon11
3,652 Recognized Expert Specialist
In other words, whether you are learning Java by your own free will, or are required to learn Java, Welcome; Welcome to Java. It's safer here.

</half-life 2 quote>
Feb 27 '08 #12
BigDaddyLH
1,216 Recognized Expert Top Contributor
In other words, whether you are learning Java by your own free will, or are required to learn Java, Welcome; Welcome to Java. It's safer here.

</half-life 2 quote>
I recall that when I moved from C++ to Java, I kissed the ground like the old pope.
Feb 27 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

9
1507
by: wongjoekmeu | last post by:
Hello All, I am learning C++ at the moment. Going through the book of SAM of learning C++ in 21 days I have learned about pointers that it is good custome to always initialise them and to use...
7
2189
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
50
2789
by: Joseph Casey | last post by:
Greetings. I have read that the mistake of calling free(some_ptr) twice on malloc(some_data) can cause program malfunction. Why is this? With thanks. Joseph Casey.
47
2590
by: sunglo | last post by:
Some time a go, in a discussion here in comp.lang.c, I learnt that it's better not to use a (sometype **) where a (void **) is expected (using a cast). Part of the discussion boiled down to the...
11
1963
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
24
2080
by: venkatesh | last post by:
hai, any can tell what is the advantge of using pointers?any increase in speed or execution time? if you know please tell what are the real time applications of data structure? thanks in...
9
2296
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new...
21
1810
by: Bo Yang | last post by:
As long as I write c++ code, I am worry about the pointer. The more the system is, the dangerous the pointer is I think. I must pass pointers erverywhere, and is there a way to ensure that every...
4
3494
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
4
1720
by: Deep | last post by:
I'm in doubt about what is smart pointer. so, please give me simple description about smart pointer and an example of that. I'm just novice in c++. regards, John.
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.