Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comparison of C Sharp and Java
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Pointers === Java precludes pointers and pointer-arithmetic within the Java runtime environment. The Java language designers reasoned that pointers are one of the main features that enable programmers to put bugs in their code and chose not to support them.<ref name="oracle.com"/> Java does not allow for directly passing and receiving objects/structures to/from the underlying operating system and thus does not need to model objects/structures to such a specific memory layout, layouts that frequently would involve pointers. Java's communication with the underlying operating system is instead based upon [[Java Native Interface]] (JNI) where communication with/adaptation to an underlying operating system is handled through an external ''glue'' layer. While C# does allow use of [[Pointer (computer programming)|pointers]] and corresponding pointer arithmetic, the C# language designers had the same concerns that pointers could potentially be used to bypass the strict rules for object access. Thus, C# by default also precludes pointers.<ref>{{cite web |title=Unsafe Code and Pointers (C# Programming Guide) |url=http://msdn.microsoft.com/en-us/library/t2yzs44b(v=vs.80).aspx |publisher=Microsoft |access-date=11 March 2013}}</ref> However, because pointers are needed when calling many native functions, pointers are allowed in an explicit ''unsafe'' mode. Code blocks or methods that use the pointers must be marked with the {{mono|unsafe}} keyword to be able to use pointers, and the compiler requires the {{code|/unsafe}} switch to allow compiling such code. Assemblies that are compiled using the {{code|/unsafe}} switch are marked as such and may only execute if explicitly trusted. This allows using pointers and pointer arithmetic to directly pass and receive objects to/from the operating system or other native APIs using the native memory layout for those objects while also isolating such potentially unsafe code in specifically trusted assemblies.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)