CPSC 259 Chapter Notes - Chapter 7.4: Operand

31 views2 pages
Java pointer coding and the idea behind pointers
Difference in Java and C with pointers
In java, the operands * and & are not used for indicating pointers. Essentially, pointers
are used as variables. If you have more complicated types like arrays or objects, then
pointers are automatically used for them.
This approach leads to fewer bugs, as the main error that can occur when coding in
pointers, that is when a pointee is not assigned to a pointer is eliminated. Also, if you
defer a NULL pointer, then that would be a real time error, but in Java owing to real
time processing, this error is avoided as they occur.
However this also means that java runs slower, since the additional resources required
for checking the consistency of pointers, take more time. However, the increased time
of the program can be compensated by the increased efficiency and speed of the
Idea behind pointers
In a computers memory, every area has a specific address like 12212. So when you use a
variable, you assign that particular address the variables name and then the values of
the variable are stored in that address. So, a pointer essentially is given the address. So
when you defer a pointer, the operand looks up the address and the value associated in
the address. A bad pointer is assigned a random address like 32123 and so they act
weird because they can be assigned any random address, which is then manipulated.
Assigning two pointers as the same, such as a = b, means that both get the same
address. Assigning two variables the same, however means that two addresses are used
up and contain duplicate information.
Reference is more or less like pointers. Like there is no need to have separate terms for
the two. However, reference is used when talking about languages generally but
pointers is a term specific to C and C++.
The most common bug you will come across is when pointers are not assigned variables.
This happens because pointers and variables look similar, but have key differences.
After assigning variables, you are free to use them in operations without any added
manipulations but with pointers, you need to associate them with a variable before you
can make use of them. This additional step is often forgotten, and should leads to
program crashing in languages like C.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
1 Booster Class