You are on page 1of 15

Java Note’s Pavan

Unit 1
Java Introduction

¤ OOP CONCEPT ¤

● Encapsulation
● Inheritance
● Polymorphism

1. Encapsulation

The mechanism of providing protection to data &


methods of a program is called Encapsulation.

Class
Private
Data
Public
Method
Public
Data
Private
Method
Communication Channel to External Components
Access to External
Components
Data

● Access Specifiers
1. Default (Friendly)

2. Public

3. Private

4. Protected
Java Note’s Pavan
2. Inheritance

A class acquire the property of another class is


called Inheritance.

Note: Java provides Multilevel Inheritance but doesn’t


provide directly Multiple Inheritance.

● Inheritance provides reusability.


● Java is providing concept of abstract class.

3. Polymorphism

To take more than one form is called


Polymorphism.

Ex. 1) Method Overloading


2) Method Overriding

¤ Features of Java Language ¤

Java language has some special features, using which


programmer write fast, complex, safe and robust (strong)
program.

Some of such important features are:

1. Safe:
Java does not provide any pointer like C & C++. So a
memory location of system can not be access thought
Java program, therefore any program develop in Java can
not be use hack a system.
Java Note’s Pavan

2. Robust:
Errors that occur at runtime can easily handle in Java.

Java provides Exception Handling features to over many


runtime problems, like divide by 0, memory out of range,
file not found, etc.

With use of Exception Handling Feature user can


properly exit from program.

3. Multithreaded:
Java language provides an environment by which
several task can be initiated and managed easily, such a
feature is called Multithreaded.

4. Architecture Neutral / Platform Independent:


A program written & compile in one platform can run
other platform and running under any type of O.S.

5. Internet Ready:
Java has several classes for Internet Programming,
which can be used for client server programming.

6. Simple:
Java is using syntax like C & C++ and that’s why Java
is simple language.

¤ Types of Java Language ¤


Java Note’s Pavan

Using Java language 2 types of program can be written.

1. Application Program
Java can be use for writing programs that run in PC under the
control of the O.S. in that machine. Such programs are called
Application Program.

2. Applet Program
Programs can be written & compile to give what is called
Bytecodes.

This bytecode can be downloaded from server & run


under control of local O.S. Such programs are called Applet
Program.

Java provides one type of application which is GUI base &


used in Internet Programming to show different colors images
or different multimedia effects is called Applet Programs.

¤ Java Architecture ¤

● Bytecode is intermediate code.

● Object file is H/W dependent, but class file is not H/W


dependent.

● Java is portable from Bytecode & JVM.

● JVM providing Just-in-Time (JIT) compiler.


Java Note’s Pavan
.java
Local OS
Java
Platform
javac
.class file
O/P
Java Environment
Kit

O/S
API
JVM
Source
Compiler
Bytecode

Java Architecture

Java programming environment is based on four


technologies.

● Java source program is created using the features of java


language.
Java Note’s Pavan
● The source program is compiling using java compiler &
java class file is created.

● The class file is in form of bytecode.

● Bytecode is independent from O/S & H/W.

● Java Virtual Machine executes Java class file and Java API
require for Java class file.

● Java API interacts with local O/S and API files have native
methods.

● The combination of JVM & API is called Java platform.

● Java platform is different for different machine.

● Through different platform Java program should to write


once, compile once and run any where.

● The variation in the H/W environment is taken by different


JVM for different machines leaving in the source program
compitable to all types of machine.

● And so Java program becomes platform independent.

Java Program
Java Platform for Windows
Java Platform for Linux
Java Platform for Mac
Java
Program
Java Compiler
Virtual Machine
Java file
jdk
.class file
(byte code)
Java Note’s Pavan

● Explain JVM

Byte
code
Run with Java
Command
Machine Dependent
O/P
JVM + API

Byte code (Definition)

Byte code is instruction that is not for any specific CPU.


They are design to interpret by JVM.

Java Environment
Java is proving JDK-Java Development Kit to compile
Java source code. It provides number of commands.
Java Note’s Pavan

Unit 2
Java Language Overview

¤ Literals ¤

Entities that do not change their values in a


program are called literal or constants.
Java Note’s Pavan

¤ Data Types ¤

● In Java all types are sign and take positive & negative
values.

● The range of integer value for all integer type is defined


by Java language and does not depend on the computer
on which the members are generated.

● The width of each type is prefixed and is platform


independent.

● In Java character is 16 bit code, therefore it can represent


65536 disting characters.
Java Note’s Pavan
● This 16 bit representation of character is called Unicode,
which covered large set of language characters in the
world. (What is Unicode? Superset of ASCII)

● Java support Boolean values true & false.

● True & false are not associated with any numerical value.

 Default values for basic types

Data Types Default Values


Char Null
Byte 0
Short 0
Int 0
Long 0L
Float 0.0F
Double 0.0D
Boolean False

¤ Variables ¤
Java Note’s Pavan
Variables, as the name indicate take different
values during the execution of program.

 Rules

1. A variable is combination of letter, number, underscore (_)


& dollar sign ($).
2. There is no maximum limit on the total no. of character
that form the variable.

Chapter 3
The Structure of a Java
Program

 Print Single Line

Class FirstProg
{
public static void main(String args[])
{
System.out.println(“First Program.”);
}
}

● Package name start with small letter.


Java Note’s Pavan

● Class name start with capital letter.

● Method name, first word is always small letter and first


char of second word is capital letter.

● By default lang package is imported in all programs.

Why main method in Java is public?

1. All application programs must contain main method.

2. The main method is executed first.

3. A list of string type can be passed in to program thought


arguments array in command line.

4. Void: The word void is a key-word and informs that the


main method being not return anything.

5. Public: Public is an access specifier. We access main


method outside of class than it must be public, so main
method is public.

6. Static: Static is specific the storage type.

When we are calling main method, no object is created


and if we want to call main method without an object than it
must be static.

7. System.out refers standard output stream.

8. System.out is object of type print stream.


Java Note’s Pavan

¤ Comments ¤

How java is supported comment?

1. Single line comment (// … //)


2. Multi line comment (/* … */)
3. Documentation comment (/** … */)

¤ Expressions & Statements ¤

Java expression consists of variable & literals


separated by operators.

Ex. a+b, a*b, a*b/3+c

When a Java expression is assign to a variable it


becomes a statements.

Ex. X= a*b/3+c
Java Note’s Pavan

¤ Type Conversion ¤

Java has mechanism to handle different types present


in an expression chasing evaluation of expression or while
assignment.

Java does type conversion thought two mechanisms.

1. Automatic Promotion
2. Type Casting

1. Automatic Promotion (Widening)

Java automatically converts variables or literals of lower


precession type to a higher precession type during evaluation
of the expression or during assignment, this is knows as
automatic promotion or widening.

Byte & short type are automatically converted to integer


in an expression.

 Valid Type Conversion

Source Type Destination Type


Byte Short, int, long,
float,
Double
Byte 0
Java Note’s Pavan
Short 0
Int 0
Long 0L
Float 0.0F
Double 0.0D
Boolean False

You might also like