Java is not a difficult language to learn, even if you are a complete beginner. There are a few concept however that we must get out of the way in order to get started.
In this tutorial we will cover the absolute basics of Java and programming in general, so if you already know what Java is, what a development kit is, you have a JDK installed and ready to run, then go ahead and Skip to the next tutorial.
What is Java?
Java is two things: it is both an Object-Oriented Programming language and a Platform.
Object-Oriented Programming (OO) Language .
When writing code, or programming, a programmer writes that code using a specific syntax and grammar that he and other programmers understand called the Programming Language. In the particular case of Java, it is an Object-Oriented programming language, which means that it is based around the notion of Objects that may have data inside and also may contain code instructions (like methods).
Object-Oriented programming is one of several programming paradigms, but there are others, like Functional Programming (like Lisp and Haskell) , Logic Programming (like Prolog), etc. It is simply a set of concepts and rules on how to structure an idea or problem.
So, when we say that Java is an Object Oriented Programming Language, we are just expressing the way that code is structured, and what is the expected behavior of that code. This will be covered more indepth in the next tutorials of this series, while writing some code and getting some hands-on experience.
But Java is also a Platform,
When someone makes a program in Java, for it to be executable it needs to be compiled. Compiling code is basically translating the human readable source code, which is the writing the programmer does, into a "format" that the computer can make sense of. This is called compiling to Native code, and it has the following particularities:
- Code compiled natively is usually faster, at least at startup
- Code compiled natively is architecture and OS specific (must be compiled independently for each OS : windows, Linux, etc)
- Code compiled natively do require an interpreter.
Java in particular (and some other languages as well) is an interpreted programming language, which means that the Java Source code is compiled into intermediate "format", and then for it is run, the computer must have an interpreter. In Java this is called Compiling to Java bytecode, and has the following particularities:
- Java Bytecode requires an interpreter to be installed ( Java must be installed on the running machine)
- Java Bytecode is not architecture or OS specific. It can run in any arch. or Os that has an interpreter
So, when we talk about Java there is this distinction, it is a programming language, but also a Platform (or runtime environment).
To start programming in Java, the first thing that a programmer needs is the Java Development Kit (also known as JDK) and to run a program made in Java, a user needs the Java Runtime Environment (also known as JRE).
The JDK has the compiler, and all utilities needed to transform Java Source Code into Java Bytecode, and also brings a JRE inside so the developer can run the application he is coding. As a developer you'll only need to install the JDK on your computer.
The JRE has the interpreter, that is called the Java Virtual Machine (or JVM for short). We'll talk more about the particularities of the JVM as we move along.
So, to get the JDK you can go to the Oracle JDK 8 Download Page . We are looking for the Java SE Development Kit 8u73 . Download the version for your platform and follow all the steps to install it.
Once the JDK is installer, you'll need an editor to write the Source Code for the projects you'll be programming.
Any text editor will do, you can code Java using the Windows Notepad, or linux Vi if you want. But sometimes it is helpful to have an editor that can verify straight away the syntax you are using to program, and warn you of any errors you might have made. It is also useful to have a text editor that writes some boilerplate code that you don't want to be writing all the time, and that allows for the code to be compiled automatically from inside the editor, to save time and for convenience. These are called Integrated Development Environments, or IDEs for short.
There are many many IDEs for Java, like NetBeans, Eclipse, etc etc etc.
For the first tutorials there is no need for a fancy IDE. We could use a simple text editor and everything would be fine.
Some recommended text editors are :
But don't get lost in the choice of text editor. It really makes no difference, you can do it with Notepad.
After the first beginner tutorials, the IDE that will be used is IntelliJ Community Edition . Any other can be used, but the examples will be made using IntelliJ. There is a Community Edition of IntelliJ that is free, and that is the one that will be used on the tutorials.
Before the next tutorial you should:
- install the specified JDK.
- install a text editor , an IDE (or decide to use notepad or something for now)
Once you are ready, next tutorial: Tutorial 2 - Hello World