Java Tutorial For Beginners


Java Basics and OOPS Concepts
 

A) Java Fundamentals

1) Comments in Java
    

    > To make the Code Readable
    > To make the Code disable from Execution.

Java supports Single line comment and multiple line comments.
---------------------------------------------------
2) Data Types in Java
 

A Data Type is a classification of the type of data that a variable or object can hold in computer programming.

Example:

Character,

Integer,

String

Float

Boolean etc...

Java supports two categories of Data types.

a) Primitive Data Types

b) Reference Data Types.
---------------------------------------------------
3) Java Modifiers
 

Modifiers are used to set access levels for Classes, Variables and Methods etc...

Two types of Modifiers in Java

i) Access Modifiers (default, public, private and protected)

ii) Non Access Modifiers 9static, final, abstract, synchronized etc...)
---------------------------------------------------
4) Variables in Java
 

A named memory location to store temporary data within a program.

Three types of variables in Java

i) Local Variables

ii) Instance Variables

iii) Class / Static Variables
---------------------------------------------------
5) Operators in Java
 

Operators are used to perform Mathematical, Comparison and Logical Operations.

Categories of Operators in Java

i) Arithmetic Operators

ii) Relational Operators

iii) Assignment Operators

iv) Bitwise Operators

v) Logical Operators

vi) Miscellaneous Operators
---------------------------------------------------
Flow Control
    Conditional Statements
    Loop Statements
---------------------------------------------------
6) Java Conditional Statements
 

a) Two types of statements

i) if statement

ii) switch statement
-----------------------
b) Three types of Conditions

i) Single Condition (Positive/Negative)

ii) Compound Condition (Positive/Negative)

iii) Nested Condition (Positive/Negative)
---------------------------------------
c) Usage of Conditional Statements

i) Execute a block of statements when a condition is true.

ii) Execute a block of statements when a condition is true, otherwise execute another block of statements.

iiii) Execute a block of statements when a Compound condition is true, otherwise execute another block of statements.

iv) Decide among several alternates (Else if)

v) Execute a block of statements when more than one condition is true (Nested if).

vi) Decide among several alternates using Switch statement
---------------------------------------------------
7) Java Loop Statements
 

Used for Repetitive execution.

Four types of loop structures in Java

i) for loop

ii) while loop

iii) do while loop

iv) Enhanced for loop(Arrays)
---------------------------------------------------
8) Arrays in Java
 

> Generally, Array is a collection of similar type of elements.

> In Java, Array is an Object that contains elements of similar data type.

> Java Array is index based, index starts from zero.

> The length of an Array is established when the Array is created and Array length is fixed.

> Each item in an Array is called an Element.
---------------------------------------------------
9) String handling in Java
 

> Series of characters written ""

> String may contain Alfabytes or Alfa-numeric or Alfa-numeric and Special characters or only numeric.


"ABCD"
"India123"
"India123$#@"
"123"
---------------------------------------------------
10) IO Operations and File Handling in Java
 

The java.io package contains classes to perform Input and Output operations.

> Read data using Input devices.

> Display output on the Console.

> Read data from files / write data

Using Java File class we can handle Text files.
---------------------------------------------------
11) Java Methods
 

Methods are also known as Functions.

> In Structured Programming (Ex: C Language) we use Functions (Built-in and User defined)

> In Object Oriented Programming (Ex: Java Language) we use Methods (Built-in and User defined)

Two types of Methods in Java

a) Built in Methods
    Number Methods
    Character Methods
    String Methods
    Array Methods etc...

b) User defined Methods
    Method with returning value
    Method without returning any value.
---------------------------------------------------
12) Regular Expressions
 

It is a formula for matching patterns, A Regular expression defines search pattern for Strings.

Java provides java.util.regex package for pattern matching

Constant matching

india.doc - india.doc

Pattern matching

i*.

ia.....
ib....
.
.
india.doc
---------------------------------------------------
13) Exception Handling in Java
 

In Computer Programming, Exception is an abnormal condition.

> An exception is an event that occurs during the execution of a program, that disturbs the normal flow of instructions.

> The Exception handling in Java is one of the powerful mechanism to handle Run-time errors.
---------------------------------------------------
B) Java Object Oriented Programming System (OOPS) concepts.
 

Four fundamentals of OOPS

1) Inheritance

2) Polymorphism

3) Abstraction

4) Encapsulation
---------------------------------------------------
1) Inheritance
 

> Inheritance is a mechanism in which one Object acquires all the properties and behaviors of parent Object.

> Using Inheritance we can create classes that are built-in upon existing classes.

> When we Inherit from an Existing class, then we can reuse Methods and fields from Parent class and we can add New Methods and fields also.

Java Supports

i) Single Inheritance

ClassB extends ClassA

ii) Multi Level Inheritance

ClassB extends ClassA
ClassC extends ClassB

Java doesn't support Multiple Inheritance

ClassB extends ClassA
ClassB extends ClassZ
---------------------------------------------------
2) Polymorphism
 

Performing tasks in different ways.

Polymorphism derived from Two Greek words,

Poly - means Many

Morphs- means forms/ways

So Polymorphism means many ways.

Two types of Polymorphism

i) Compile Time Polymorphism / Method Overloading

ii) Run-Time Polymorphism / Method Overriding
---------------------------------------------------
3) Abstraction
 

> Abstraction is a process of hiding implementation details and showing functionality to the user.

> It shows important things to the user and hides implementation details

Ex:
Sending Email

> Abstraction focuses on what the Object does instead of how it does.

Abstraction can be achieved in 2 ways

i) Abstarct Class(1% to 100%)

ii) Interface (100%)
---------------------------------------------------
Class1
10 methods (10 concrete/complete Methods)

Class1 - Class
------------------------------
Class2
10 methods(1 Method -Abstact Method, 9 Methods concrete/complete Methods)

Class2 -Abstact Class
---------------------------
Class3
10 Methods (10 Methods -Abstarct Methods)

Class3 -Abstact Class
---------------------------------------------------

4) Encapsulation
 

> Encapsulation is a process of wrapping code and data together into a single unit.

Ex: Capsule (mixed of Several medicines)

Encapsulation provides control over the data.
---------------------------------------------------
Java Packages
A Java package is a similal type of classes, interfaces and sub packages.

Two types of packages

i) Built in
Ex: io, util, lang etc...

ii) User deined
-------------------------------------
Interfaces in Java
 

An Interface is a collection of Abstract methods.

An Interface is not a Class, writing an Interface is similat to writing a class, but two are different things.
----------------------------------------
Java Programming hierarchy:
Java Project
    > Java Package
        > Java Class /Java Interface
---------------------------------------------------

0 comments:

Post a Comment