Qore Programming Language

  • Increase font size
  • Default font size
  • Decrease font size

How Does Qore Compare to Java?

E-mail Print PDF

How Does Qore Compare to Java?

Java Logo

Java and Qore appear to be complete different languages when viewed together for the first time, however complex object-oriented qore programs/scripts are more similar to Java programs than to perl scripts, especially if you use the "%new-style" parse directive that prohibits the use of "$" and "$." prefixes in Qore code.

This section will attempt to outline the similarities and differences between qore and Java, however, because I'm not a Java expert, it will definitely be incomplete, and may be inaccurate in some cases.

 

Similarities to Java

  • when executed with the --exec-class or %exec-class options, a qore program/script will disable the use of top-level statements and instantiate the class with the same name as the input file (stripping the suffix and the path of course) in a manner similar to executing a java program.
  • Objects in qore are always "copied by reference" unless explicitly copied in a manner very similar to java.  This means that if you pass as object to a function or another object method in Qore without using the reference operator, if you modify the object in the function or method, you will modify the original object, as with Java.  Like in Java, by default in Qore a copy of a reference to the object is passed when an object is passed as an argument to a function or class method.
  • qore implements the synchronized keyword in a manner similar to Java, using a reentrant thread lock to ensure that only one thread can execute the function or method at one time (but still allowing recursive invokations in that thread).
  • qore and Java implement exception handling with try catch blocks (however, see differences below)
  • qore and Java implement class inheritance (however, see differences below)
  • as of Qore 0.8.0, qore supports hard typing of variables and parameters
  • Qore and Java both support overloading methods (in Qore parameters must be typed in order to overload a function or method)
  • When the Qore parse directive "%new-style" is used, variables, method names, and object members are referred to directly without any "$" or "$." prefixes

Differences from Java

  • Java is a strongly-typed language and qore also allows weakly-typed elements.  Qore's strong-typing support is not as complete as Java's, for example, you cannot declare element types of lists or hashes in Qore (yet).

  • Java's exception handling is strongly typed, supporting multiple catch blocks, requiring methods to declare the exceptions they can throw, etc. Qore currently supports only one catch block due to the fact that exceptions are not yet typed in Qore.

  • Qore implements multiple inheritance in a manner more similar to C++; overriding base class constructor arguments is supported. Java implements single class inheritance and multiple interface inheritance.

  • All methods and members of Qore objects are public by default unless declared private, Java implements finer grained control (the protected keyword, etc.).

  • In Qore, any base class method can be overridden in a derived class; also in Qore there is a special syntax that allows explicit calling base class methods from within derived classes. In Java, methods declared as final cannot be overridden, and for those that can, there is no way to call overridden base class methods (as far as I am aware).

  • Java uses this as a reference to the current object, Qore uses "$.self" (or just "self" with the "%allow-bare-refs" or "%new-style" parse directives)

  • Qore has no concept of interfaces; Java does.

  • Java uses the clone method and a special interface to provide a mechanism to copy objects; qore uses the copy() method, which is run in the copy of the object after all members have been copied (although members that are objects get a new reference to the object, so it's not a deep copy -- basically Qore executed an equivalent of Java's Object.clone() call, and then allows the new object to make changes to the new data). Qore's copy() methods are inherited and run in the same order as constructor() methods in class hierarchies.

  • Java is based on byte code and requires classes to be compiled to byte code before they are run. Qore parses (very quickly) normal text data to an internal compiled representation which is executed; there is no byte code in qore (yet).

  • Qore supports exception-safe and exception-aware cleanup code similar to D's "scope guards" with on_exit, on_success, and on_error statements, while Java implements the finally keyword instead.
  • Qore also allows procedural programming styles (or even linear programming), all Java code is implemented in classes (as far as I'm aware)

  • Java has a wide variety of APIs, classes, etc available for just about anything a programmer could want to do (as long as you want to do it in Java), whereas Qore's API and module set is considerably more limited.  However, now that Qore has a public, documented, and stable ABI, you can help change this by extending Qore by writing new Qore modules! :-)
Last Updated on Friday, 16 December 2011 20:22