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 GuidesJavaLanguage Details  Print This     

Cross Ref > Language Details

By Mike Prestwood

Java versus Delphi: A side by side comparison between Java and Delphi.

 
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.

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;
}
Delphi:   procedure, function

Delphi is a hybrid language so you can create either class methods (functions and procedures) or you can create global functions and procedures. When a function or procedure is part of a class, it is a class method.

[function/procedure] RoutineName : ReturnType;

As with C++, your custom routine must come before it's first usage or you have to prototype it in the Interface section.

Note: Contrast Delphi with Delphi Prism which is an OOP language (everything is within a class). Both Delphi and Delphi Prism are based on Object Pascal but implement OOP features differently and have some syntax differences too.

Syntax Example:
procedure SayHello(pName: String);
begin
  ShowMessage('Hello ' + pName);
end;
 
function Add(p1, p2 : Double): Double;
begin
  Result := p1 + p2;
end;




Event Handler

[Other Languages] 

In computer programming, an event handler is part of event driven programming where the events are created by the framework based on interpreting inputs. Each event allows you to add code to an application-level event generated by the underlying framework, typically GUI triggers such as a key press, mouse movement, action selection, and an expired timer. In addition, events can represent data changes, new data, etc. Specifically, an event handler is an asynchronous callback subroutine that handles inputs received in a program.

A custom event is a programmer created event. For example, you can contrast an event handler with a member event, an OOP concept where you add an event to a class.

Languages Focus

Many development environments and compilers provide for event driven programming, a standard set of application events such as startup, end, on click of a button, etc. This section documents the applicaton event handler or an overview for each language.

For OOP languages, do not confuse this section with class member events discussed in the OOP Details section of our Cross Reference Coding Encyclopedia.

[Not specified yet. Coming...]
Delphi: 

Many objects in Delphi have events you can use to trigger code. For example, when you add a form to your project you have access to the form events such as onCreate, onShow, onHide, onDockDrop, etc. In addition, Delphi offers module level events initialization and finalization sections.

More Info / Comment




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.

Java:   Not Supported

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

Delphi:   asm

In Delphi, you can inline assembler code using the asm keyword.

More Info / Comment




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?

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
Delphi:   Inline

Delphi introduced developer defined function and procedure inlining with Delphi 2005. Use the inline keyword to tell the compiler to try to inline a routine (a compiler hint). Since Delphi will only try to inline the routine, make sure you test for speed because inlining a routine can lead to slower code under some circumstances.

Syntax Example:  
function Add(a, b: Integer): Integer; inline;
begin
end;




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.

Java: 

Java Overloading

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

Delphi supports both method and operator overloading.

For method overloading, you use the overload keyword (all versions of the routine must include the overload keyword). The compiler chooses the correct method first based on the number of parameters, then on the type so you can have two overloaded methods with the same number of parameters so long as at least one parameter is different.

Another form of method overloading is with the use of default parameters, a shortcut syntax, where you specify a default parameter value.

Delphi also supports operator overloading with some operators.

Syntax Example:
function Add(a, b: integer): Integer;  overload;
begin
Result := a+b;
end;
  
function Add(const msg: String; a, b: integer): String; overload;
begin
  Result := msg + IntToStr(a+b);
end;




Parameters

[Other Languages] 
[Not specified yet. Coming...]
Delphi:   var, const

Object Pascal allows parameters of the same type to be listed together, separated by commas, and followed with a single data type (more params of different data types can follow, after a semi-colon).

Delphi also supports default parameters (a form of overloading).

By Reference or Value (and by constant): The default for parameters is by value. For by reference, add var in front of the parameter. Object Pascal also offers constant parameters where you add const in front of the parameter. A constant parameter is like a local constant or read-only parameter the compiler can optimize. You cannot assign a value to a constant parameter, nor can you pass one as a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can still modify the object's properties.)

Syntax Example:
function Add(a, b: integer) : integer; 
begin
  Result := a + b;
end;
 
procedure ReplaceTime(var pDT: TDateTime; const pNewDT: TDateTime);
begin
end;




Self Keyword

[Other Languages] 
Java:   this
Delphi:   Self

Within the implementation of a method, the identifier Self references the object in which the method is called. The Self variable is an implicit parameter for each object method. A method can use this variable to refer to its owning class.

Syntax Example:
ShowMessage('Self=' + Self.ClassName);




Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


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