Hello friends,
Is pointer concept is there in java? If so how to use? if not why?
12 1524
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.
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.
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
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.
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
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".
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
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.
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
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 ...
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>
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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.
|
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...
|
by: Alfonso Morra |
last post by:
Hi,
I have the ff data types :
typedef enum {
VAL_LONG ,
VAL_DOUBLE ,
VAL_STRING ,
VAL_DATASET
}ValueTypeEnum ;
| |
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...
|
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...
|
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...
|
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...
|
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.
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |