You are on page 1of 10

Java programming

Introduction

There are two types of program. One focuses on data where as other focuses on function. It can also be
written as what is happening and who is being affected. There are two paradigms that govern how a
program is constructed. They are process oriented[i.e. c] and object oriented[i.e. c++, JAVA].

Object oriented programming principles

1. Encapsulation= The process of hiding some of part is encapsulation


2. Inheritance= The process of transferring same features of class are inheritance
3. Polymorphism= The process of carrying more than one feature is polymorphism

JAVA is the object oriented programming. Properties of JAVA are

1. Simple
2. Object oriented
3. Robust
4. Multithreaded
5. Architecture neutral
6. Interpreted and high performance
7. Distributed
8. Dynamic

Basic terminologies used in JAVA

1. Object
2. Class
3. Method
4. Instance variable
i. Separators/Words
ii. White space
iii. Literal
iv. Identifier
v. Keyword[50 out of which 48 is only use]
vi. Comment line
vii. Data type
viii. Variable

Data type in JAVA

1. Integer[sign]
a. Byte=It use 8bit[1 byte]. The range from -27 to 27-1
b. Short=It use 16bit[2 bytes]. The range from -215 to 215-1
c. Int=It use 32bit[4 bytes]. The range from -231 to 231-1
d. Long=It use 64bit[8 bytes]. The range from -263 to 263-1
2. Float[sign]
a. Float=It use 32bit[4 bytes]
b. Double=It use 64bit[8 bytes]
3. Character
• Character=It use 16bit[2 bytes]
4. Boolean
• Boolean=It use 1 bit

Downloaded from Saral Notes Learn something new today. Join Group
Keywords

Abstract Assert boolean break byte


Case Catch char class const
Continue Default do double else
Enum Extends final finally float
For Goto if implements import
instanceof Int interface long native
New Package private protected public
Return Short static strictfp super
Switch synchronous this throw throws
transient Try void volatile while

#underline keywords are not in use

Type of type conversion

• Implicit conversion=The conversion done by program itself is called implicit conversion. This is done
for same type of data from small data type to larger type of data
• Explicit conversion=The conversion made by programmer is called explicit conversion. This can be
done in different data type and also from larger to small data type

Array

➢ Same type of data


➢ In Java memory allocation is done by new keyword

Data_type variable_name[]=new data_type[number of data

➢ Types
• One dimensional array
• Multi dimensional array

Operators

1. Arithmetic operator=The operands of arithmetic operators must be of numeric type. We cannot use
them in Boolean type
2. Module operator=The module operator ‘%’ returns the remainder of division operator
3. Assignment operator/short hand notation=Java programs special operations that can be used to
combine an arithmetic operators with an assignment operator
4. Increment and decrement operator=This is denoted by ++ or --. There are two types: pre and post

For example

int x=42 int x=42


int y=x++ int y=++x
Output Output
x=43 x=43
y=42 y=43
In the example first is post increment and second one is pre increment operator

5. Relational operator=It determine the relationship, the one operand has to other. The result produced by
a relational operator is a Boolean value
6. Boolean operator=The logical operator inverts the Boolean state

A B A/B A&B A^B !A


Downloaded from Saral Notes Learn something new today. Join Group
0 0 0 0 0 1
0 1 1 0 1 1
1 0 1 0 1 0
1 1 1 1 0 0

7. Ternary operator=The ternary operators(?:) is used for basic conditional expression. So it is also called
conditional operator
8. Bitwise operator=The bitwise operator is used for integer type

Control statement

• Selection statement
➢ If
➢ Nested if
➢ If else-else if ladder
➢ Switch
• Iteration statement
➢ While
➢ Do-while
➢ For
➢ For-each version of loop

Jump statement

• Break
• Continue
• Return

Class

Object

Method

Parameters

The number of argument pass in function

Constructors

It is method with class name

Method overloading

The use of same method with different parameter

Conflict

The use of same method with same parameter

Constructor overloading

The use of same constructor with different parameter

Garbage collection

Downloaded from Saral Notes Learn something new today. Join Group
Garbage collection is a form of memory management. The garbage collector attempts to reclaim or memory
occupied by object that are no longer in used by the program

Argument passing

Call by value
Call by reference
Recursion

Access control

Public
Private
Protected

Static[variable, method]

String

Varargs[variable length argument]

Inheritance

The process of carrying some of common feature from super class to sub class is inheritance. It can be
remove with final keyword

Super class

It is the class from which sub class inherited

Type of inheritance

Single inheritance
Multiple inheritance
Multilevel inheritance
Hybrid inheritance

Super keyword

It help to carry the attribute from super class

Method overriding

The use of same function with same parameter

Dynamic method dispatch

Abstract class

Exception

Exceptions is an object that describe an exceptional(i.e. error) condition that occur in a code

Exception handling keywords

Try
Catch
Finally

Downloaded from Saral Notes Learn something new today. Join Group
Throw
throws

Thread

It is the process of running more than one program at same time

Synchronization

It is the process of management of thread one after another

Enumerations

An enumeration is a list of named constants. In Java, an enumeration can have constructors, methods, and
instance variables.

Autoboxing

Autoboxing is the process by which a primitive type is automatically encapsulated (boxed) into its
equivalent type wrapper whenever an object of that type is needed. There is no need to explicitly construct
an object.

Auto-unboxing is the process by which the value of a boxed object is automatically extracted (unboxed)
from a type wrapper when its value is needed. There is no need to call a method such as intValue( ) or
doubleValue( ).

String

It is the character array which can’t be change once it declare

String buffer

It is the character array which can change

File

The class File is used for creation of files and directories, file searching, file deletion etc. The File object
represents the actual file/directory on the disk. There are following constructors to create a File object

Package

Downloaded from Saral Notes Learn something new today. Join Group
1. Hello world

Answer

class Example

public static void main(String args[])

System.out.println(“hello world”);

Output

2. Declaration of variable

Answer

class Example

public static void main(String args[])

int num=100;

System.out.println(“this is num:”+num);

num=num*5;

System.out.println(“this is num*5 is”+num);

Output

Downloaded from Saral Notes Learn something new today. Join Group
3. Use of if

Answer

class Sample

public static void main(String args[])

int x, y;

x=10;

y=20;

if(x<y)

System.out.println(“x is less than y”);

x=x*2;

if(x==y)

System.out.println(“x is now equal to y”);

x=x*2;

if(x>y)

System.out.println(“x is now greater than y”);

x=x*2;

if(x==y)

System.out.println(“you can’t see this”);


Downloaded from Saral Notes Learn something new today. Join Group
}

Output

4. Use of integer

Answer

class Light

public static void main(String args[])

intlightspeed;

long days;

long seconds;

long distance;

lightspeed=186000;

days=100;

seconds=days*24*60*60;

distance=lightspeed*seconds;

System.out.println(“in”+days);

System.out.println(“days light will travel about”);

System.out.println(distance+“miles”);

Output

Downloaded from Saral Notes Learn something new today. Join Group
5. Use of character

Answer

classCharDemo

public static void main(String args[])

char ch1,ch2;

ch1=88;

ch2=’y’;

System.out.println(“ch1 and ch2”);

System.out.println(ch1+“”+ch2);

Output

6. Use of character

Answer

class CharDemo2

public static void main(String args[])

char ch1;

Downloaded from Saral Notes Learn something new today. Join Group
ch1=’x’;

System.out.println(“ch1 contains”+ch1);

ch1++;

System.out.println(“ch1 is now”+ch1);

Output

Downloaded from Saral Notes Learn something new today. Join Group

You might also like