March 31, 2012
The Kissing Cousins of Java and .NET
Object-oriented programming encompasses a wide swath of languages. Originally, Simula 67, Smalltalk, and C++ led the pack. Today, the predominate languages and frameworks are Java and Microsoft’s .NET with C#. With a few notable differences, these languages share much common ground and each has strengths and advantages for tackling different and complex application challenges.
The Java Story
James Gosling of Sun Microsystems, now a division of Oracle, developed Java as an object-oriented, cross-platform, processor independent environment as early as 1991. Originally termed “Oak”, it was intended to address interactive, handheld home-entertainment devices. It was considered a technology well ahead of its time, and remained tabled for several years. Cable companies were simply not interested at the time.
Java has been open-source from the start, although many add-on products and some components of the core technology are proprietary and licensed for a fee. The term “Java” typically refers to the Java programming language running in the Java Virtual Machine (JVM), which isolates Java programs from the operating system and hardware. It was this architecture that was responsible for the “write once; run anywhere” nature of Java.
Microsoft’s C# and .NET
Around 2002, in response to Sun’s success with Java, Microsoft hired Anders Heijlsberg from Borland, where he had created the Delphi programming language. At Microsoft, he created a new programming language, C#, along with the Common Language Runtime, CLR. C# combined many of the great features of Java and C++ and benefited from the knowledge of several shortcomings critics had identified with Java. The CLR performs a similar function as the Java Virtual Machine (JVM), isolating the language from the underlying system. Together, these technologies became known as the .NET framework.
As part of the Microsoft Windows product strategy, they chose a unique language portability feature over platform portability. With .NET, you can choose C#, C++, Visual Basic, J#, as well as many other language choices. One framework supports all. Microsoft submitted both of these technologies to the ECMA standards committee, however, they are not open source.
A notable feature addition to C# was the LINQ framework and the use of lambda expressions. With these extensions, data can be queried in a natural manner from collections, databases or XML documents.
Comparison
While criticisms exist for and against either language framework, both strategies clearly saw the future of an interconnected world and made huge strides with the network central to their frameworks.
While there are exceptional differences between C# and Java, for example, Java does not support unsigned integers, nor operator overloading, it’s noted there are far more similarities. Java and .NET both compile code to a machine-independent intermediate representation. Java uses the term bytecode; .NET coined the term Microsoft Intermediate Language: MSIL. This intermediate code is run within a virtual machine, isolating the program from the underlying platform. At runtime, the virtual machine reads the intermediate code and executes it. The code can be interpreted or just-in-time (JIT) compiled. Both frameworks also use garbage collection for automatic memory management.
In fact, C# and Java are so similar they use nearly identical syntax. Consider these c‑treeACE examples:
c‑treeDB Java
static CTSession MySession;
static CTTable MyTable;
static CTRecord MyRecord; /* main java class properties */
/* Initialization: */
MySession = new CTSession(SESSION_TYPE.CTREE);
MyTable = new CTTable(MySession);
MyRecord = new CTRecord(MyTable);
MySession.Logon("FAIRCOMS", "", "");
/* Table creation */
CTField field1 = MyTable.AddField("mt_custnumb", FIELD_TYPE.CHARS, 4);
MyTable.AddField("mt_custname", FIELD_TYPE.VARCHAR, 47);
MyTable.AddField("mt_custcity", FIELD_TYPE.VARCHAR, 47);
// index definition
CTIndex index1 = MyTable.AddIndex("mt_custnumb_idx", KEY_TYPE.FIXED_INDEX, false, false);
index1.AddSegment(field1, SEG_MODE.SCHSEG);
// table creation
MyTable.Create("custmast", CREATE_MODE.NORMAL);
// open table
MyTable.Open("custmast", OPEN_MODE.NORMAL);
// add records
MyRecord.SetFieldAsString(0, "1000");
MyRecord.SetFieldAsString("custame", "Bryan Williams");
MyRecord.SetFieldAsString(2, "Orange");
// persist record
MyRecord.Write();
// find and modify a record
MySession.Lock(LOCK_MODE.WRITE_BLOCK);
MyRecord.Clear();
MyRecord.SetFieldAsString(0, "1000");
// find record by customer number
if (MyRecord.Find(FIND_MODE.EQUAL)) {
MyRecord.SetFieldAsString(1, "BRYAN WILLIAMS");
// rewrite record
MyRecord.Write();
}
MySession.Unlock();
c‑treeDB.NET
static CTSession MySession;
static CTTable MyTable;
static CTRecord MyRecord; /* main java class properties */
/* Initialization: */
MySession = new CTSession(SESSION_TYPE.CTREE_SESSION);
MyTable = new CTTable(MySession);
MyRecord = new CTRecord(MyTable)
MySession.Logon("FAIRCOMS", "", "");
/* Table creation */
CTField field1 = MyTable.AddField("cm_custnumb", FIELD_TYPE.FSTRING, 4);
MyTable.AddField("mt_custname", FIELD_TYPE.VSTRING, 47);
MyTable.AddField("mt_custcity", FIELD_TYPE.VSTRING, 47);
// index definition
CTIndex index1 = MyTable.AddIndex("mt_custnumb_idx", KEY_TYPE.FIXED_INDEX, false, false);
index1.AddSegment(field1, SEG_MODE.SCHSEG);
// table creation
MyTable.Create("custmast", CREATE_MODE.NORMAL_CREATE);
// open table
MyTable.Open("custmast", OPEN_MODE.NORMAL_OPEN);
// add records
MyRecord.SetFieldAsString(0, "1000");
MyRecord.SetFieldAsString("custame", "Bryan Williams");
MyRecord.SetFieldAsString(2, "Orange");
// persist record
MyRecord.Write();
// find and modify a record
MySession.Lock(LOCK_MODE.WRITE_BLOCK_LOCK);
MyRecord.Clear();
MyRecord.SetFieldAsString(0, "1000");
// find record by customer number
if (MyRecord.Find(FIND_MODE.EQ)) {
MyRecord.SetFieldAsString(1, "BRYAN WILLIAMS");
// rewrite record
MyRecord.Write();
}
MySession.Unlock();
The Java programming language is the primary language supported by the JVM, although a few other languages are supported (Groovy, Scala, JRuby, Jython, etc.). The .NET framework is not limited to running C# programs. Over 100 programming languages are supported by.NET.
Feature |
.Net |
Java |
Compiled Code |
Both precompiled and dynamically compiled |
Both precompiled and dynamically compiled |
Object Oriented |
Yes |
Yes |
Supported Development Languages |
C++, C#, Visual Basic.NET, Jscript.NET, Python, Perl, Java (J#), COBOL, Eiffel, Delphi, and many others |
Primarily Java. Also AspectJ, Clojure, Groovy, JavaFX Script, JRuby, Jython, Oxygene, Rhino, Scala |
Browser Specific HTML Rendering to reduce incompatibility issues |
Yes |
No |
Open Source |
No |
Yes |
Interface to low-level C/C++ code |
Yes, using Platform Invoke. Also allows memory management outside of the garbage collector. |
Yes, using JNI (Java Native Interface) |
FairCom provides interfaces for both platforms including SQL and direct record oriented access: c‑treeDB Java and c‑treeACE SQL JDBC for Java applications and c‑treeDB.NET and c‑treeACE SQL ADO.NET for .NET applications.
The choice depends on your application and development environment. Java for a standardized development environment across many platforms, Microsoft .NET for Windows environments supporting many languages. Both are fully object oriented with extremely productive results. Either choice, FairCom has you covered!
See Also