Java Critique
In this blog I will point out why java is bad and is my least favourite language in desktop programming and in language level. I don’t go to server-side programing because I don’t have much experience about it.
What is Java
Java is not only a OOP language, it is also an entire platform with virtual machine, garbage collection, just-in-time compiler and enormous class library.
First I want to say the good things about java and then start ranting
The Good Parts
- Importing other external libraries is easy with importing jar files
- It easy to create documentation java in IDEs when you use the commenting features such as @param and @author when you comment your code.
- Language is simple. The syntax is very simple.
- Deploying built applications is easy.
- The idea of code once run everywhere is great.
- Threading is in best order in java at the moment.
The Bad Parts
- Java is a proprietary language. Why? Because it is owned by SUN. Unlike C and C++ they are not owned by anyone. Not even Bjarne Stroustrup owns the C++, if it would be anyone then it would the ISO committee.
- The Java is not platform free – it is a platform! Java byte code only runs where the Java VM runs.
- When you write java you are forced to write object oriented programming. This is because the language developers have decided that “We are smarter than anyone and they must write code like we do to get benefit.”.Object oriented programming does not make everything better. There is still a lot of procedural programming in the world. OOP fanatics tend to read 1000 page books about “how to think naturally” and never read a single page about good procedural programming. And then they end up saying that this
System.out.println("Hello, world!"); is more natural then printf("Hello, World!");
- Somebody might say: “It’s good that java doesn’t have pointers so you don’t need to worry about them.”. That might be okay for a beginner but in the reality every object passed to a method is passed as a pointer. They are just called references
. If you want to pass a copy to a method you must make a copy of your object and pass that, because you cannot write copy constructors in java.
- You cannot pass a primitive types such as: ints and doubles as pointers or references
- Garbage collection makes programmers sloppy. How hard is it to write delete?
- Only dynamic allocation is available in java.
- Because of the language design java does not decrease the total lines of code. This is just my experience – I cannot show you real statistic proof ( but then again aren’t all statistics damn lies
). This is one problem in IT: “How to measure software?”.
- You can’t write destructors in java – wrong. You can, BUT you can never be sure that your object destructor is called when the object falls out of scope or when the application exits with
System.exit( int );. But to enable calling of an object destructor on exit you must use something infernal like this: Runtime.addShutdownHook method Uagh… That’s horrible. Why is this so important then? Isn’t all the memory that the application has allocated released when the applications is quit? Yes, BUT! Memory is not the only resource you can reserve. For example you could reserve a printer or a file handle and you wanted those resources to be released when the object using them falls out of scope.
- You can’t use function or member function pointers.
- There is no macro system of what so ever guide. I must say that I don’t like if someone overuses #define macros in C. Also macros are evil 4 ways if you don’t know what you are doing or using
- Nor is there any template system java like C++
- No operator overloading. As a C++ fan I find of not being able to overload operators in java to be a huge pain. For example consider:
Complex complex1( 2, 3 );
Complex complex2( 7, 5 );
Complex complex3 = complex1 + complex2;
complex3 /= complex1 * complex2;
complex3 -= complex1 - complex2;
if( complex1 == complex2 )
std::cout << "complex1 and complex2 are equal." << std::endl;
else
std::cout << "complex1 and complex2 are not equal." << std::endl;
std::cout << "the complex numbers are:\n";
std::cout << complex1 << '\n' << complex2 << '\n' << complex3 << std::endl;
Versus
Complex complex1 = new Complex( 2, 3 );
Complex complex2 = new Complex( 7, 5 );
Complex complex3 = new Complex();
complex3.setValue( complex1.add( complex2 ) );
complex3.divedeBy( complex1.multiply( complex2 ) );
complex3.decrease( complex1.decrement( complex2 ) );
if( complex1.isEqualTo( complex2 ) == true )
System.out.println( "complex1 and complex2 are equal." );
else
System.out.println( "complex1 and complex2 are not equal." );
System.out.println("the complex numbers are:\n";
System.out.println(complex1.toString());
System.out.println(complex2.toString());
System.out.println(complex3.toString());
- Why to put main function inside a class?
- Java programs tend take a lot of memory. Just look at the memory use of NetBeans – it’s more than 400 MB.
- In theory java is only 10% more slower but in practice all java programs are slow. Especially when loading.
- Java has built in GUI library “swing”. OK, nice. BUT, I think it’s the worst library to write a GUI. You should always the native look to make java GUIs to at least look nice.
- Java code gets old very fast. Not all companies are willing to upgrade their java VM every year and change their code to use the new methods instead of the now deprecated ones.
- Almost everything in java is wrapped around in try-catch statements. This is bad for program performance even if the exception never happened, because the program has to keep a lot of book keeping in order to recover from exception.
- In java a lot of casting is made and every good programmer knows that casting is a no-no or at least they should know to avoid casts.
Conclusion
Java is a really bad for P/R programming and is not very good for OOP. Code is bloat, apps are slow and memory comsuming hogs. OK, so why is java so popular when it has so many flaws? This is because java has a marketing campaign, where C and C++ don’t have one.
How Would You Make It Better then?!
Like my dad always asks me when I complain about something: “How would you have made it better?”. How should code be written then if not with java or java-style? Well, in my opinion you should write as portable code as possible and compile it on different platforms and distribute the binaries. Also testing is vital, must test test and test. Give your piece of software to be tested by “normies”. Make it clear what is wanted out of software and do those functionalities properly. Also try save as much as memory as possible and avoid dynamic memory allocation and type casting. To know what your compiler and libraries does is very important skill. There are a lot of C and C++ open source libraries to be used for making GUIs, networking and everything. The problem with the libraries is that they usually are so damn difficult to setup for your environment. But libraries like SDL and Qt are very simple and fast to setup. C/C++, SDL, Qt and OpenGL FTW!!! I also like PHP, XML techniques and AppleSript