One of the good thing with Java, is its documentation. I don't have to write a full tutorial on learning Java, since the creator of Java already did it. So I will mostly describe why you should learn Java, and how to get started up either with Eclipse, or Netbean. I will also explain on how to compile Java to Java bytecode, from command line(Linux only, won't waste time explaining how to do it from windows, CMD not powerful enough, but its also possible to do it on windows, not hard). Its also its documentation that make it great to learn OOP, because its very complete. Most of C++ tutorial are really bad on the OOP part. C++ could be a good language to learn OOP if it could have an official documentation and tutorial. But once you learn Java, you are almost ready for C++.
I recommend before learning to learn Java to learn C. Java is a good second or third language. Java is a C like language, being one of its descendant. Curly brace, and very similar syntax. Another reason to learn C first, its because to learn OOP, we should know why OOP is actually useful, and why it was created, and the only way to know that, its by learning a language with no OOP. C is imperative.
One of the great thing about Java is portability. In fact, a Java program can run in any OS, without modification, as long as the Java virtual machine is installed. (Exception if it use a library that is OS specific, it can happen, but very rarely. One of the example(not a good example) is swt, a widget library. Although that library is available on all major OS, each OS got its native library. If we forgot to include the right library, the program could not run. The solution: Include the Linux's library, the Windows's library and mac library all at once in the package, or do a package specific for each platform. There are also library only available on one OS, but most of the time, everything is portable). Also, Java has a documentation maker, Javadoc, but if you prefer, you can also use doxygen. Java is not the fastest of available language, a compiled language will almost always be faster (there can be exception if the language is very slow...). Also, Java is a general purpose language, it can fit almost all our need: it can be a server-side language, with Apache, it can be a client-side language trough applet, it can desktop application (Minecraft is a good example), and it can also make command line program.
Some people don't like the idea to sort language either as low level or high level, but I will, to help to explain. Its always useful to learn a high level language. High level language usually have a framework around it(the Java's framework is called the Java platform), lot of function in its standard library, garbage collection, and lot other toy, helping accelerated development. Also, high level language are more secured, less vulnerability for buffer overflow(advantage of interpreter or virtual machine) and other. Most of the time, those language are interpreted, or run in a virtual machine like Java. On the other hand, low level language are faster, we have more freedom to do whatever we want, like writing an OS, but we also need to be more careful, because bug are more crucial. Low level language usually has a pointer notion. There is no extra security to help you(Interpreter usually have some feature to prevent the program from doing bad thing). And there is also machine language, either in readable format (assembly), or in raw binary (machine native code). If we use that vision to sort language, Java is a high level language, while C and C++ are more low level language. But how does Java denote itself from other major interpreted language?
Java VS other High level language
Java VS C#:
- C# faster
- Java more portable
- C# harder to decompile (Its possible to decompile Java byte code to almost the original source file, without any knowledge in programming, while with C#, we need more patience to decompile an application)
- Both have a great framework. By framework I mean the standard library around it. Lot of function available.
- Both have much the same toy available (like Garbage collection)
- Easier to compile Java, no hard time linking library. Creating and linking library with C# can be harder for newcomer.
- More IDE to work with Java
- C# can also work under GNU/Linux, trough Mono implementation, but a little buggy, not all feature available, mono tend to be outdated
- Java need only to be compiled once to be run anywhere where a Java virtual machine is available.
Java VS Python
- Python interpreted
- Java compiled to Java Bytecode
- Java is more mature
- Java is more friendly to those that come from C, Java is a descendant of C after all. Python can be a little weird when starting, because of its syntax. Python is not curly brace, but work with lot of indentation.
- Java is faster
- Both have good community behind it that can help you
- Python is like the programming language of the moment (very popular)
- Python can be used as a scripting language in another program
- Python is write once, run anywhere, no need to compile, while Java is write and compile once, and then run anywhere.
- Java more portable. Java virtual machine is on more OS and device than Python interpreter
- Python could be considered even higher level than Java and C#. We don't even have to specify the type of variable we want.
- Because python is higher level, it can lead to faster development.
- With python, can also play in the interpreter. No need to always write source in a file when we want to do test.
- With Java, we usually take latest version
- With python, 2 major version available. the 3.x and the 2.x Compatibility is not guaranteed between these two version.
- Java is targetting total portability, python is cross platform, but integrate better with OS, having some function specific to some OS. Python is a better choice when it come to write thing like plug in for your desktop, or some system program, where Java will be more suited for desktop program. For example, if you want to write a package manager, or a auto installation tool, or a screen saver, or a new toolbar, menu for your desktop, widget... Python is better suited, for its integration with the rest of the OS. Ubuntu is a perfect example for that, they use lot of python to make the system working.
- Python can also used for web development, like Java.
Java VS Perl
- Perl can be seen more like a scripting language by some people, like a way to replace the shell script. But it can also be used as a programming language, and its quite capable of producing some good program. Like python, better integration with the OS, so also perfect to write some plugin, and other for the OS.
- Java more popular
- Perl is less common on windows
- Perl is interpreted (But perl is really fast, because of its simple syntax easy to parse)
- Perl is one of the best language to make automated tool for GNU/Linux, has everything you need
- Perl is very good, just don't know how to describe it, too much to say, without the right word to explain it...
- Perl is more used on command line, than GUI program
- But Java may also be used from Command Line, don't worry
As you can see, Java compare well to other language, its not the best, some other may perform better at some task (like C# faster, but more specific to windows), but it can almost be used for anything. Its why I recommend learning Java, as it can almost always be usuful in almost any situation. Java + either Perl or Python is a good combo to do most of the thing, with C to do program that need more speed.
Example of program made using Java are Netbean and Eclipse, the best IDE available out there, Minecraft, the game of the moment, runescape... Java is also a lot used in industry.
Contrary to C++ and C#, you only need to compile Java once, and just copy the file on other OS, and it will work, if they have Java installed. Very ideal if you do like me, having your development environment in Linux, do all your programming under Linux, and just copy the result on windows. I try to install only game on windows, because installing something on windows do so much garbage in registry, appdata and other directory. So no IDE on windows, or maybe just 1 for C and C++. I really try to avoid bloating windows. Windows is so fragile. But everyone may have its reason to develop on a given system, and deploy on another. Maybe you just hate GNU/Linux, or you don't have it, and you want to write a program for your friend. Its when Java can be handy. No need to mess up with cross compiler, that can be hard to configure.
When combined with PHP and javascript(very easy to learn if you know java), it can make miracle, Applet allow very good interaction with people visiting your website. So if you mostly want to be a webmaster, Just learn Java, PHP, javascript, HTML, MySQL/PostgreSQL and CSS, and you can do almost anything. PHP with Javascript do the dynamic part, PHP on the server, java script on the client side. Java applet is like a program running inside the browser... Thus enabling you to do game, chat, program to do fractal, do calculation, form to log-in. Java applet is also secure. But sometime, it may also work not well enough. For example, minecraft don't always work in my browser.
Also Java is a big + on a CV. Many enterprise and business use it. So very good to find carer. In fact, C# is also good on a CV. But python... Not at the moment, maybe later, it will be more renowned in business and enterprise. But Java is not only a + on a CV, but also in almost every programmer toolbox.
Java actually come in several version. I recommend to read this: Difference between the different Java version. I recommend to learn JavaSE then after JavaEE. Other can be ignored, or learned if you want. To resume what is said in that link, JavaSE is for general purpose use, while JavaEE is more for web use, like professional applet. But its worth learning both. JavaFX is made to create easy interface for web and Micro Edition for platform limited on resource, like embedded system, like some cellular and router.
Tutorial & Documentation:
- JavaSE (Standard Edition)
- JavaEE (Enterprise Edition)
- JavaFX
-JavaME(Micro Edition)
Installing Java and/or OpenJDK
[spoiler][/spoiler]
A small Helloworld, and some remark to get started
[spoiler]First, before all, you must know that every program must contain the main method. Main is the entry of the application. If you forget it, you won't be able to compile. The main is generally either declared as public static void main(String[] args) or static public void main(String[] args), but we prefer to write public first. As like in any language, we need a hello world to test the installation. Copy and past that hello world (Hello world are one of the only thing I recommend to copy, instead of rewriting, as its for testing purpose, and not learning purpose. But generally, you must try to experiment, not just copy and past.)
Code: Select all
public class MyApplication {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}In java, we can do comment in the same way as in C and C++, either after // or encapsulated between /* and */. I also recommend you to check out how javadoc work, a nice tool to generate high quality documentation page, without much effort.[/spoiler]
Java and command line(Linux and BSD only)
[spoiler]
Its better to either use official Java implementation from oracle, or to use OpenJDK. Both are almost identical. OpenJDK can also considered official, since Oracle (Sun micro-system before oracle bought them) work on the project.Beware, GCJ is not a certified JVM. It is the GNU Classpath for Java project which has partial Java compatability under a GNU license. You should stay clear of it unless you are certain it meets your needs and you have a reason you cannot use another complete Java implementation. Shane on stackoverflow.
Both are stable, have the same function... But there could be bug on one implementation not here on the other. So up to you. You can also use both.
So stay away from GCJ and use java and javac, except if you know what you do. Its not dangerous, but just not as complete as the official utility.
To compile and run your program, its relatively easy, especially if java and javac are in your PATH environment variable. First, you need to compile your application to Java-byte code. This can be done easily by just opening a terminal, and do this:
Code: Select all
javac MyApplication.javaCode: Select all
java MyApplicationEclipse and Java
[spoiler][/spoiler]
Netbean and Java
[spoiler][/spoiler]
Available good library:
[spoiler]Widget library (GUI library)
- swt
- swing (Widget library, the most portable one, work over awt. Its the standard library for widget, since its part of Java fundation class. Its like the native library for widget when using Java)
- awt
Multimedia and Game library
Other[/spoiler]



