JAVA
TRAINING

Abdullah Fathi

JDK 1.8 (Windows)

JDK 1.8 (Linux)

sudo apt-get install openjdk-8-jdk

Java Path (Windows)

Windows 10

 

Windows 7

 

Test 

echo %JAVA_HOME%

 

Java Path (Linux)

  • Locate installed java path:

  • sudo update-alternatives --config java

  • sudo vim /etc/environment

  • JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

  • Reload file : source /etc/environment

  • echo $JAVA_HOME

Java Path (Mac)

Eclipse

JAVA BASIC

Object

Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class.

Class

A class can be defined as a template/blueprint that describes the behavior/ state that the object of its type supports.

Methods

A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.

Instance Variables

Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables

JAVA BASIC SYNTAX

Java Basic Syntax

  • Case Sensitivity: Identifier Hello and hello would have different meaning in Java
  • Class: All class name's first letter should be in Upper Case. Ex: class MyTestApp
  • Method: All method should start with Lower Case.
    Ex: public void myMethodName()
  • Program File Name: Name of the program file should exactly match the class name.
  • public static void main(String args[])
    eclipse shortcut (main ctrl+space)

Java Identifier

  • All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).
  • After the first character, identifiers can have any combination of characters.
  • Identifiers are case sensitive.

Object & Classes

Classes

JavaClassExample.java

Variable Type in Class

  • Local variables: Variables defined inside methods
  • Instance variables − Instance variables are variables within a class but outside any method.
  • Class variables − Class variables are variables declared within a class, outside any method, with the static keyword.

Constructor

Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class

Create an Object

  • Declaration − A variable declaration with a variable name with an object type
  • Instantiation − The 'new' keyword is used to create the object.
  • Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.

Access instance variable

  • Declaration − A variable declaration with a variable name with an object type
  • Instantiation − The 'new' keyword is used to create the object.
  • Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.

First Java Program

  • Create Java Class
  • Compile
  • Run

Basic Datatypes

Primitive Datatypes

  • byte
  • short
  • int
  • long
  • float
  • double
  • boolean
  • char

Download Jar

Java Servlet

Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server

Java Training (Basic)

By Abdullah Fathi

Java Training (Basic)

  • 427