Complex object-oriented qore programs/scripts are more similar to Java programs than to perl scripts, even though the fact that variable names always begin with a "$" will continue to remind one of perl. 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 referenced unless explicitly copied in a manner very similar to java.
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)
Differences from Java
Java is a strongly-typed language and qore is a weakly-typed languange. This means that many programming mistakes in Java can be caught at parse time, while in qore the same mistake may be a run-time error. However, qore's weakly-typed nature can allow much more elegant solutions to some kinds of problems (there are advantages and disadvantages to each approach).
Java's exception handling is strongly typed, supporting multiple catch blocks, requiring methods to declare the exceptions they can throw, etc. Qore supports only one catch block due to the weakly-typed nature of the language.
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.).
Qore provides no way of overloading methods (including constructor()
methods); Java does
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
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 in a virtual machine. Qore parses (very quickly) normal text data to an internal compiled representation which is executed; no virtual machine is necessary (just the qore binary compiled for the target platform), and no formal byte code exists in Qore.