Java Introduction

Java Tutorial


What is java?

java is a popular programminhg language, created in 1995.
it is owned by Oracle, and more then 3 billion devices run Java.

It is used for:

  • Mobile application(specially Android apps)
  • Desktop applications
  • Web applications
  • Web servers and application Servers
  • Games
  • Database connection etc.

Why Use Java?

Java works on different platforms like windows, Mac, Linux, etc.
  • It is one of the most popular programming language in the world
  • It is easy to learn and simple to use
  • It is open-source and free
  • It is secure, fast and powerful
  • It has a huge community support (tens of millions of developers)
  • Java is ab object oriented language which give a clear structure to programs and allows code to be reused, lowering development costs
  • As java is close to C++ and C#, it makes ir easy for programmers to switch to Java or Vice versa

Java Install

Some PCs might have Java already installed.

To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command prompt (cmd.exe)




If Java is installed, you will see something like this (depending on version):




If you do not have Java installed on your computer, you can download it for free at oracle.com.



How To Install Java on Windows

To install Java on windows:

  1. Go to "System Properties" (can be found on control panel > System and Security > System > Advanced System Setting)

Step 1:



     2. Click on the "Environment variables" button under the "Advanced" tab




    3. Then, select the "path" variable in System variables and click on the "Edit"                 button




    4. Click on the "New" button and add the path where Java is installed, followed by \bin. By default, Java is installed in C:\Program Files\Java\jdk-16(if nothing else was specified when you installed it). In that case, You will have to add a new path with: C:\Program Files\Java\jdk-16\bin Then, click "OK", and save the settings.




    5. At last, open Command Prompt (cmd.exe) and type Java -Version to see if Java is running on your machine.

Write the following in the command line (cmd.exe)




If Java was successfully installed, you will see something like this (depending on version):






In Java, every application begins with a class name, and that  must match the filename.

Let's create our first Java file, called Main.java, which can be done in any text editor (like Notepad).

The file should contain a "Hello World" message, which is written with the following code:

Main.java

 public class HelloWorld{  
    public static void main(String []args){  
     System.out.println("Hello World");  
    }  
 }  



 
Don't worry if you don't understand the code above - we will discuss it in detail in later chapters. For now, focus on how to run the code above.

Save the code in Notepad as "Main.java". Open Command Prompt (cmd.exe), navigate to the directory where you saved your file, and type "javac Main.java":