Perbedaan kata kunci antara C# dan Java

Berikut adalah perbedaan kata kunci yang digunakan di C# dan Java untuk tujuan atau maksud yang sama.

C# Keyword Java Keyword Notes C# Example Java Example
Base super

Prefix operator that references the closest base class when used inside of a class’s method or property accessor. Used to call a super’s constructor or other method.

public MyClass(string s) : base(s)

{

}

public MyClass() : base()

{

}

Public MyClass(String s)

{

super(s);

}

public MyClass()

{

super();

}

Bool boolean Primitive type which can hold either true or false value but not both. bool b = true; boolean b = true;
Is instanceof Boolean binary operator that accepts an l-value of an expression and an r-value of the fully qualified name of a type. Returns true iff l-value is castable to r-value. MyClass myClass = new MyClass();

if (myClass isMyClass)

{

//executed

}

MyClass myClass = new MyClass();

if (myClassinstanceof MyClass)

{

//executed

}

lock synchronized Defines a mutex-type statement that locks an expression (usually an object) at the beginning of the statement block, and releases it at the end. (In Java, it is also used as an instance or static method modifier, which signals to the compiler that the instance or shared class mutex should be locked at function entrance and released at function exit, respectively.) MyClass myClass = new MyClass();

lock (myClass)

{

//myClass is

//locked

}

//myClass is

//unlocked

MyClass myClass = new MyClass();

synchronized (myClass)

{

//myClass is

//locked

}

//myClass is

//unlocked

namespace package Create scope to avoid name collisions, group like classes, and so on. namespaceMySpace

{

}

//package must be first keyword in class file

package MySpace;

public class MyClass

{

}

readonly const Identifier modifier allowing only read access on an identifier variable after creation and initialization. An attempt to modify a variable afterwards will generate a compile-time error. //legal initialization

readonly int constInt = 5;

//illegal attempt to

//side-effect variable

constInt = 6;

//legal initialization

const int constInt = 5;

//illegal attempt to

//side-effect variable

constInt = 6;

sealed final Used as a class modifier, meaning that the class cannot be subclassed. In Java, a method can also be declared final, which means that a subclass cannot override the behavior. //legal definition

public sealedclass A

{

}

//illegal attempt to

//subclass - A is

//sealed

public class B: A

{

}

//legal definition

public final class A

{

}

//illegal attempt to

//subclass - A is

//sealed

public class B extends A

{

}

using import Both used for including other libraries into a project. using System; import System;
internal private Used as a class modifier to limit the class’s use inside the current library. If another library imports this library and then attempts to create an instance or use this class, a compile-time error will occur. namespace Hidden

{

internal class A

{

}

}

//another library

using Hidden;

//attempt to illegally

//use a Hidden class

A a = new A();

package Hidden;

private class A

{

}

//another library

import Hidden;

//attempt to illegally

//use a Hidden class

A a = new A();

: extends Operator or modifier in a class definition that implies that this class is a subclass of a comma-delimited list of classes (and interfaces in C#) to the right. The meaning in C# is very similar to C++. //A is a subclass of

//B

public class A :B

{

}

//A is a subclass of

//B

public class Aextends B

{

}

: implements Operator or modifier in a class definition that implies that this class implements a comma-delimited list of interfaces (and classes in C#) to the right. The meaning in C# is very similar to C++. //A implements I

public class A :I

{

}

//A implements I

public class Aimplements I

{

}

Sumber : https://msdn.microsoft.com/en-us/library/ms836794.aspx#tchcjavakeywordcomparison