Hello friends,
Is pointer concept is there in java? If so how to use? if not why?
12 1526
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 NullPointerExce ption then :-)
kind regards,
Jos
BigDaddyLH 1,216
Recognized Expert Top Contributor
Say no more about that darn NullPointerExce ption then :-)
kind regards,
Jos
This is one of those moments that .NET got it right when it was plagiarizing Java. They renamed it "NullReferenceE xception".
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 "NullReferenceE xception".
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
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 delete before you try to
give it a new address.
Can anyone explain to me why this code below which seems to voilate
this rule works ?
...
|
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 http://www.eskimo.com/~scs/C-faq/faq.html
but it doesn't seem to answer my questions...
So, I've made an example behind, with some included questions...
|
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 rule: if I cast a
(sometype **) to a (void **) I am making a number of assumptions about
the implementation's (void **) representation and length....
|
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 advance
|
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 CMyClass());
//???? Required ??????????????//
|
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 object pointered by any pointer will
be deleted and only be deleted once?
|
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
vector_static_function.c:21: 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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |