Java and Java 8


Hello folks! I know I haven’t write anything for quite a while and some of you were actually worried I’d stopped but nope, still here.
I was really really busy with tons of projects, hangouts which will continue but I will try to write down at least an article per week.
Anyways, I am going to speak about Java today and Java 8 as it’s going to be released very soon and my impressions so far. I’d like to thank Java User Groups in Bucharest for reminding me of the Java 8 official webcast on 25th of March at 18:00 CET time, you can register and watch it here.

I am not an intensive Java user but I think I have a pretty good idea of its advantages and disadvantages. So for starters we all know it’s a cross-platform language because of the Java Virtual Machine(JVM), self-managed because we don’t have to worry about memory management, destructors, its syntax is very similar to one of the C++ and of course there is no multiple inheritance.  The problem of multiple inheritance has been solved by using of Interfaces.

In order to make everything clear here are the differences across Java variances.

  • JDK – Java Development Kit
  • JRE – Java Runtime Environment
  • Java SE – Java Standard Edition

SE defines a set of capabilities and functionalities; there are more complex editions (Enterprise Edition – EE) and simpler ones (Mobile Edition – ME – for mobile environments).

The JDK includes the compiler and other tools needed to develop Java applications; JRE does not. So, to run a Java application someone else provides, you need JRE; to develop a Java application, you need JDK.

Edited: As Chris Marasti-Georg pointed out in a comment, you can find out lots of information at Sun’sJava web site, and in particular from the Java SE section, (2nd option, Java SE Development Kit (JDK) 6 Update 10).

Within a given version of Java, this answer remains valid. JDK is the Java Development Kit, JRE is the Java Runtime Environment, Java SE is the standard edition, and so on. But the version 6 (1.6) is becoming antiquated.

Java has another great advantage: it’s free and open source meaning you can actually see the implementations of a sorting algorithm for example, though some implementations on Java EE(Enterprise Editions) are not available to the public.

Where do we use Java? Pretty much everywhere, every digital device has some Java built-in: PCs, laptops, phones, (smart)watches, tablets, air-conditioners, fridges, cars etc. Java really has this big advantage of working on everything that has some processing power. We use it in web, through applets or as powerful backends.

Performance? Though huge performance improvements have been done over the years, C++ still beats it and I think that’s natural, though Java has outperformed C++ in some cases, so I suppose if performance is not critical Java is going to be fast enough.
Java is also (almost) pure Object Oriented, exception made by the primitive data type and because of its high level of abstractisation it’s natural to write Programs in it. Everything looks great so far, however…

In my personal opinion Java lacks a great IDE(editor) such as Visual Studio though Net Beans does a fairly good job, Eclipse is out of the question.
Because of the backwards compatibility, Java looks like an old language and also lacks some features that modern programming languages do have for quite sometime; for example: LINQ, Lamba Expressions and Tail recursion.
You can’t mess up with pointers at all, you can’t overload operators nor make data conversions. You know that cross-platform operability I was talking about ? Meh…not so much, Java is not supported by Apple (iOS) or by Microsoft(Windows Phone).
Also in my personal opinion Sun was doing a much better job maintaining  Java than Oracle does now.

What can we expect from Java 8 ? Apparently, lambdas are going to be introduces as well as many new APIs and fixes. You can read more about it here.

I’ll make another post about Java after the official release with some examples and some books recommandations.


About C++

Today, I am going to speak up for C++ and the importance I see it has nowadays. I am going to assume you are fairly familiar with C/C++.

Some people say that learning C++ today is a waste of time and quite useless as we have much more powerful languages such as Java and C#, well I am against that wave. Though I agree that both above mentioned languages have more productivity and are somehow more powerful than C++ I still think that people should learn C++ no matter what.

The reason I think that is that C++ is so permissive and have so many concepts which in higher abstracted languages are invisible for the programmer that any coder should be really familiar with them.
Some other people say it’s just too hard. Well, I am not going to argue it’s easy but once mastered you can jump to other languages in a heartbeat so keep that in mind.

I will not bring up the “speed” argument because as of today both Java and C# are very fast, equally fast to C++ and even faster than C++ in some aspects. Though I have to say that using C++ you will be able to target a specific hardware and make necessary optimizations so that the execution speed would be truly amazing.

And now comes that awful and painful moment(for others not for me) to speak about pointers. Well, pointers are the crown of C++ as most people have a hard time with them and even very experienced programmers get their necks twisted in large programs.
Because of the so permissive C++ compiler and the manual memory management pointers have given programmers lots of headaches. There are advantages and disadvantages of pointers and just to be clear you don’t have to deal with them in C# or Java for that manner.

As I previously said, Java and C# are more productive due to their huge libraries. You can do complex things with just a few lines of code whereas in C++ the same effect would need a up to 10x more code lines, but some things are harder to code in Java or C# than in C++. Here are some examples I could find:

  1. Generics are not as powerful as templates (try to write an efficient generic Parse method (from string to T), or an efficient equivalent of boost::lexical_cast in C# to understand the problem)
  2. RAII remains unmatched (GC still can leak (yes, I had to handle that problem) and will only handle memory. Even C#’s using is not as easy and powerful because writing a correct Dispose implementations is difficult)
  3. C# readonly and Java final are nowhere as useful as C++’s const(*) (There’s no way you can expose readonly complex data (a Tree of Nodes, for example) in C# without tremendous work, while it’s a built-in feature of C++. Immutable data is an interesting solution, but not everything can be made immutable, so it’s not even enough, by far).

Of course if you want to develop end users apps with GUI probably C# WPF or JAVA Swing is the the way you want to do it though C++ also offer the QT library, however it’s less intuitive and fun than the other two.
For servers, C++ is still the best bet because there every millisecond counts and you really need to max out the performance.

So why do I recommend people to get started with C++ and master it:

  • because it’s helping you thinking of optimizations
  • it’s sometimes faster
  • pointers – we love them !!
  • understanding of low level PC arhitecture

It’s much easier for someone to switch languages if you know how data is represented in hardware and how things are going “under the hood” and as I always say use the right tool(PL) for the right job, you should not be restricted by a programming language when you have to solve a task.

There is also the matter of static compiler vs JIT about which you can read about here.
You can also find more opinions on this matter

So maybe C++ is old and “not cool” but is still alive and kicking (pretty hard if you ask me) and you should get a few keyboard smashed before going up for some of the more enjoyable languages out there.
PS: There are probably more things to say on this topic so feel free to share!

Object oriented programming

Lately I’ve seen a lot of people struggling with this concept and being the very base of modern programming I think I should talk about it.
OOP, formally called Object Oriented Programming it’s a paradigm that helps the programmer to express himself in a more natural way with concepts he already knows from daily life. This also dramatically increases the level of understanding of the code written, maintainability and further code addition.

Basically you have classes with methods, properties and member variables to designate objects. This principle is called encapsulation. Methods are functions through which the user interacts with the object. Note the difference between properties and member variables. Though it’s language dependent, a property often designates a variable with GET and SET (mutator and accessor functions) and does not have memory allocated on its own however the associated filed does and a member variable or field designates a class variable. Look at the example below:
[gist id=8675207 file=OOP]

We also have at least two special functions(methods) in a class, those are the constructor and destructor, their role is to initialize the object(allocate memory in non managed languages – C++ and members initialization) and to destroy the object(free allocated memory in non managed languages, not really used in managed languages) respectively. The compiler provides an empty constructor and destructor by default, they don’t anything. Pay attention that a constructor has the same name as the class and it does not return anything. The destructor has a “~” in front and has the same name as the class. The destructor makes no sense in managed languages because the garbage collector is in charge of when an object is destroyed.

Another principle of OOP is security. Often we use access modifiers to accomplish this (private, protected, public and internal in C#).

  • public – can be accessed by anyone in or outside the class.
  • protected – can be accessed by anyone in the same class or in a class that inherits the containing class.
  • private – can be accessed by anyone in the same class.
  • internal (C# specific) – can be accessed only from the same assembly, but not other assemblies. Java has this by default in packaging.

As I already stated abstraction was the main reason of OOP, because a more natural, faster and easier way to code was needed. Programmers needed to avoid “spaghetti code” to make their programs easier to understand and easier to maintain. I will talk about inheritance a bit later as it is a vast subject and it’s language dependent(C++ allows native multiple inheritance while C# and Java require Interface to accomplish this).

Will talk about polymorphism, abstract classes, overloading and templates on a future article.
Finally some of the OOP languages out there are: C++ (C is not), PHP, Java, C#, Ruby, Python etc.

If you are anxious and want to learn faster you can find a good resource here

Simple Share Buttons