1. Introduction into Java - ZolotovaNatalia/JavaCourse_2017 GitHub Wiki
Introduction into Java
Java is a computer programming language. It is intended to let application developers "write once, run anywhere". This means, that Java applications can run on any platform where Java Virtual Machine is installed.
As of 2016, Java is one of the most popular programming languages in use, with a reported 9 million developers.
History
JAVA was developed by Sun Microsystems Inc in 1995, later acquired by Oracle Corporation. It was conceived by James Gosling and Patrick Naughton. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. Gosling designed Java with a C/C++-style syntax that system and application programmers would find familiar.
Possibilities of Java:
- Desktop applications - everything that we can load from the Internet and install on our local computer
- Web applications
- Web services
- Mobile applications
- Games
- Business solutions
For more information see here : Java Programming Language
The main goals, that were achived in the creation of the Java language::
- Simplicity
- Compatibility: Java code that is written on one machine can run on another machine. The platform independent byte code can be carried to any platform for execution that makes java code portable.
- Multithreading : Java supports multithreading. It enables a program to perform several tasks simultaneously.
The Java Virtual Machine
Java is platform independent. This means that it will run on just about any operating system. So whether your computer runs Windows, Linux, Mac OS, it's all the same to Java! The reason it can run on any operating system is because of the Java Virtual Machine. The Virtual Machine is a program that processes all your code correctly. So you need to install this program (Virtual Machine) before you can run any Java code. Java is owned by a company called Oracle, so you need to head over to Oracle's website to get the Java Virtual Machine, also known as the Java Runtime Environment (JRE). This will help you to run Java programs, but not develop them. Since, we want to create our own applications, we need the Java Software Development Kit as well. It includes compiler, standart libraries useful for developing and testing programs written in the Java programming language and running on the Java platform.
Install JDK and set Environment Variable
Oracle provides JDK, that includes the JRE, so you do not have to download both separately. To download it go here : JDK . Press checkbox 'Accept License Agreement' and download a file that fits to your computer architecture. For Windows choose jdk-8u144-windows-i586.exe, for Mac OS - jdk-8u144-macosx-x64.dmg.
After downloading you need to install JDK.
For Windows see here a helper video : how to install Java on Windows. Then, you have to determine environment variable. You can find how to set environment variable here : Environment Variables. In the system variables create JAVA_HOME and set the path to the jdk (for example: C:\Program Files\Java\jdk1.8.0_91) and add this variable to the PATH variable : %JAVA_HOME%\bin.
For Mac OS : how to install Java on Mac OS.
This is it. Now you can open the command line at write your first program.
Writing the first program "Hello, World!"
Three steps in programming:
- Create source code with the extension .java
- Compile it to transform from Java language into Java Byte Code, that is understandable to Java Virtual Machine
- Execute/Run your program
To write your first program you can use any text editor, for example Sublime.
After downloading install it.
For Windows see here a helper video : how to install Sublime on Windows.
For Mac OS : how to install Sublime on Mac OS.
Write the following text into a new text file and save it with the name HelloWorld and .java extension:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
This program prints "Hello World!" Names for the file and for the class should be equal. In our case HelloWorld. Don't use spaces in names - it's not allowed in Java. For now, don't pay attention on what is written in the code sample. It will be explained later.
No you need to compile your source code to transform it into Java Byte Code. This can be done, by using java compiler javac.
Open command line and go to the directory with your source code. Type javac HelloWorld.java and press Enter. No you can see, that a new file is created HelloWorld.class. This is binary file that can be executed by Java Machine.
Now run your program by entering in the command line: java HelloWorld. You can notice that this time we use command java . This command run JVM and loads the program into JVM.
Working with Intellij IDEA
Intellij IDEA is an integrated development environment (IDE) used in computer programming, and is the most widely used Java IDE. It consists of a source code editor, build automation tools and a debugger and has intelligent code completion. It helps developers to write their programs in fast and effective way.
For more information see here : Intellij IDEA.
Download and install Intellij IDEA
You can download Intellij IDEA from the site JetBrains: Intellij IDEA Download.
After downloading install as a normal program.
For Windows : how to install Intellij IDEA on Windows.
For Mac OS : how to install Intellij IDEA on Mac OS. You can of course follow all instructions in the video and create your first project.
After installation, open Intellij IDEA.
Open Intellij IDEA:
Press "Create Project".
In the field "Project SDK" add JDK. For that open "New..." and choose the directory where JDK locates.
Then press "Next" -> "Next" , select "Project Name" and location where it will be located.
Press "Finish" and you can see your project created.
Congratulations! You've created your first project!
In order to right your first source code in the project use helper videos:
For Windows : Hello World project
For Mac OS (if you haven't yet created a project): Hello World project.
Congratulation! You've learnt how to configure environment for Java development, create and run your first java application in Intellij IDEA.