IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC#Language Details  Print This     

Cross Ref > Language Details

By Mike Prestwood

C# versus Java: A side by side comparison between C# and Java.

 
Language Details
 

Language Details is kind of a catch all for stuff that didn't make it into language basics nor any other category.

Custom Routines

[Other Languages] 

Languages Focus

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

C#: 

C# requires () in both the function declaration, and when it's invoked. Leave off the parens to signify a property.

ReturnType RoutineName()
Syntax Example:
void SayHello(String pName)
{
MessageBox.Show("Hello " + pName);
}
int Add(int a, int b) 
{
return a + b;
}
Java: 

Because java is an OOP language, all custom routines belong to a specific class and are therefore referred to as methods.

All methods in Java must return something so even with procedures, you return a "void".

Syntax Example:
public void sayHello(String pName) {
  System.out.println("Hello" + pName);
}
 

public int add(int p1, int p2) {
  return p1 + p2;
}




Inline Code

[Other Languages] 

Languages Focus

Also known as embedded code where you embed another syntax language within the native code of the development environment you are using. The inline code can be compiled by the current development's compiler or by an external compiler.

Do not confuse with inlining which is a coding technique where custom routines are moved inline where the code is executed either by you, by a compiler directive, or automatically by the compiler.

C#:   Not Supported

Since all the .Net languages compile into intermediate language (IL), and not to a specific CPU, they do not provide support for inline assembler code.

Java:   Not Supported

You cannot embed assembly in a java program but you can get system information via jni.





Inlining

[Other Languages] 

General Info: Inline Routines

Instead of calling a routine, you move the code from the routine itself and expand it in place of the call. In addition to manual inlining, some languages support automatic inlining where the compiler or some other pre-compiler decides when to inline a code routine. Also, some languages allow for developer defined inlining where the developer can suggest and/or force the inlining of a code routine. Inlining can optimize your code for speed by saving a call and return, and parameter management.

Languages Focus

Does it support inlining? If so, does it support developer defined inlining? Does it support automatic inlining? Both?

C#:   Automatic

In C#, inlining is automatically done for you by the JIT compiler for all languages and in general leads to faster code for all programmers whether they are aware of inlining or not.

More Info / Comment
Java:   Automatic

The Java compiler automatically inlines when it determines  a benefit. The use of final methods is considered a compiler hint to tell the compiler to inline the method if beneficial.

More Info / Comment




Overloading

[Other Languages] 

Types of overloading include method overloading and operator overloading.

Method Overloading is where different functions with the same name are invoked based on the data types of the parameters passed or the number of parameters. Method overloading is a type of polymorphism and is also known as Parametric Polymorphism.

Operater Overloading allows an operator to behave differently based on the types of values used. For example, in some languages the + operator is used both to add numbers and to concatenate strings. Custom operator overloading is sometimes referred to as ad-hoc polymorphism.

C#:   implicit

C# supports both method and operator overloading.

For methods, C# supports implicit overloading (no need for an overload keyword).

Java: 

Java Overloading

  • Operator - No. Sun deliberately chose not include operator overloading in the Java language.
  • Method - Yes.




Parameters

[Other Languages] 
C#: 

In C# the data type of each parameter must be specified, even if adjacent parameters are of the same type. To pass a parameter by reference, use the ref or out keyword.

Syntax Example:

integer Add(int a, int b)

[Not specified yet. Coming...]




Self Keyword

[Other Languages] 
C#:   this

To refer to the current instance of a class, use the this keyword. The this keyword provides a way to refer to the specific instance in which the code is currently executing. It is particularly useful for passing information about the currently executing instance.

The this keyword is also used as a modifier of the first parameter of an extension method.

You cannot use this with static method functions because static methods do not belong to an object instance. If you try, you'll get an error.

More Info / Comment
Java:   this




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]