33
Rajeev Gupta [email protected] What is software engineering the major problem in SW development is communication ... day-1 TOC oops api: multithreading, network programming, jdbc misc : if time permit Why Object- Oriented?

5 Day Java Training Disucssion and Important Points

Embed Size (px)

Citation preview

Page 1: 5 Day Java Training Disucssion and Important Points

Rajeev Gupta [email protected]

What is software engineering

the major problem in SW development is communication ...

day-1

TOC

oops

api: multithreading, network programming, jdbc

misc : if time permit

introduction:

jdk: Developer need it

Why Object-Oriented?

Page 2: 5 Day Java Training Disucssion and Important Points

jre: need to have an instance of jvm

jvm:virtual simulated os

java 1.6 vs java 6.0

J2SE, JEE, J2ME

J2SE: JAVA 2 STD EDITION, Core java

J2ME: java 2 micro edition

..mobile...

J2EE: ...enterprise edition,Web development

NOW 2 is droped...

JRE and JVM

jre=jvm+java api

jvm:

class loader

Byte code verifier

Exec Engine

GC

Security manager

JAVA=oops+api+jvm

platform=os+machine arch..

coding without analysis is crime

first do ooad* then do oops

i will go in depth depends on ur desire

dont run 2 if it is not there!!!

OOAD IS NOT IN TOC..WILL DISCUSS IF U NEED...AND ASK ME!!!

DEFINATION OF JAVA

Page 3: 5 Day Java Training Disucssion and Important Points

java is

platform independent

architectureal nutral

secure

wora

compiled as well interpreted

multithreaded inbuild..

support network programming buityfully..

support applet

support distributed programming*

..

..

PROCEDURAL VS OOPS

PROCEDURAL :focus on algo ,data is secondary...data may be mismunpulated ,global data problem

ex C: king of all procedural language

u can do anything in C possibly may not in java

C is faster

C is powerful

then java or kava then why java???

C:king of all procedural language

C++: big massay language

Java: best programmer supportive oop language

C# duplicate of java optimized for win...:)

Procedural programming

if ..else : conditional

for ,while, do..while: iteration

operators: mathmatical ,logical etc

Page 4: 5 Day Java Training Disucssion and Important Points

data type in java

Q: prime no checking

Q: divisibility by 11

Q: star questions

Array: one D, two D

call by value vs call by reference

notepad

edit +

ide: eclipse

Day 2

Object orientation

encapsulation

abstraction

polymorphism

inheritance

supportive concepts:

typing

persitance

message passing

Concept of class

object

reference

heap and stack

constructor

concept

this

Page 5: 5 Day Java Training Disucssion and Important Points

Constructor chaining

inheritance

various type of inheritance

why not multiple inheritance

constructor and parameter passing from derived const to base const

what u have done

if else

for loop

disadv of procedural langages

data security

global data problem...

procedural langages is not fitting to real world problems...

have a break.....

need of function

****************************************

Welcome to java

****************************************

i love to

****************************************

****************************************

will cover

function

array

oops concepts today

Page 6: 5 Day Java Training Disucssion and Important Points

function : a job is to be done

void printStar(int a)

OOPs

Object based programming language=oops-(run time polymorphism)

class: category

object : run time ex of class

a object is useless if it not communicate to other one!!!!!!-----------message passing

focus on essential things

abstraction

data hiding

message passing

encapsulation

inheritance

polymorphism

typing

persistance

etc....

i will run two if it is there....i belive it is there...

calculator program

add

substract

Page 7: 5 Day Java Training Disucssion and Important Points

multiply

divide

primeChecker

if i need repeated set of data: i need array…………….continuous hectrogenus set of data

int x[]=new int[4];

Assignment:

Q1. Calculator

Q2. Find max min from a array

Q3. Find avg of an array

Q4. Short notes

gc

abstaction

inheritance

polymorphism

class

object

Stack vs heap

Q5. Procdural vs oops

Topics day3

static method

array of objects

constructor

this

inheritance...super

abstract class, interface and final class

Page 8: 5 Day Java Training Disucssion and Important Points

final keyword: final variable !, final method, final class...

polymorphism

call by value vs call by reference

String

Wrapper class

if time permit:....

IO

Exception Handling

collection -ready made ds

and

multithreading: game programming, simulation, mobile ,server programming

Summary till now.....

array

int x[]={1,3,5,6}

for(int i=0;i<4;i++)

sop(x[i]);

heap vs stack

primitives: stack

object: heap

ref: stack

int x[]=new int[5];

Static method

a method declared static is ...

static method can only access static data..imp

u cant access non static data in a static context.........

most imp.....

class Demo

Page 9: 5 Day Java Training Disucssion and Important Points

{

public static void main(String args[])

{

System.out.println("hi");

}

}

this:

to resolve confusion bw instance variable and local

constructor chaining: calling one const from other

this is implicit argument to every method call

ie when we call a method (any non static method)

java implicitly pass a ref to the object on which method is fired ..very imp concepts even u will find developer of 3 year exp are not aware....

recursion...if time permit

Demo()

{

Demo();

}

inheritance

Father

|

Son

stupid to use parent and child termonology

better to use Base class and Derived Class

NB: We cant write any class in java without inheritance

every class inherit a class called Object...

class A extends Object

{

Page 10: 5 Day Java Training Disucssion and Important Points

}

class A {

}

are equivalent statements..having same sementics

how to pass value from derived const to base const...

son 1kg sweet

before eating myself my moral resp.. (in oops it is must)

to pass on portion of father ....

package com.oops1;

class A

{

int i;

int j;

public A(){}

public A(int i,int j)

{

super();

this.i=i;

this.j=j;

}

public void showA()

{

System.out.println("value of i:"+i);

System.out.println("value of j:"+j);

Page 11: 5 Day Java Training Disucssion and Important Points

}

}

class B extends A

{

int k;

public B(){}

public B(int i,int j,int k)

{

super(i,j);

this.k=k;

}

public void showB()

{

showA();

System.out.println("value of k:"+k);

}

}

public class DemoInheritance {

public static void main(String[] args) {

B b=new B(23, 45, 78);

b.showB();

}

}

Page 12: 5 Day Java Training Disucssion and Important Points

Q1. Simple question on constructior, cont chaining

Q2. Simple Question on inheritance

Single ,multiple ,multilevel, heri....

Q3. use of super

Q4. Array..array of object...try dog example...ie create a array of dog objects…

Q5. use of super

Q6 try R and D

................................................................................................................................................

final class

normal class

abstract class

interface

flexibility is very difficult to achieve u have to earn it...

The purpose of declaring a method final is to stop polymorphism comment on this?

//single line comment

/*

multiline comment

*/

/**

java doc

*/

@Override

annotation

to be discuss latter

Page 13: 5 Day Java Training Disucssion and Important Points

interface :

B a=new B()

C c=new C();

We can assign base class pointer with the derived class object but reverse is not true....

child has more then father has!!!!

Day-4

Interface

Polymorphism

io

Exception handling

interface

multiple inheritance

global constant

call back*

support design to interface

IS-A: inheritance

Has-A

strong: like room in building

weak: a emp works in a company

Use-A

Practical ex of USE-A

Page 14: 5 Day Java Training Disucssion and Important Points

a passanger use a car to reach from railway station to hotel

to understand user requrments…………..Analysis is imp

but………….Analysis Analysis Analysis leads to paralysis

coding: just a small part of sw deve...

OOA

find the domain model

find the classes or interfaces

OOD

find the realationship bw those classes or interfaces

Coding

then think about java...

testing

RAD

RUP: relational unified process

the most costly activity of sw development is maintance

interface A

{

int i;

}

i is in fact

Page 15: 5 Day Java Training Disucssion and Important Points

public static and final==>global const

how to solve diamond problem: multiple inheritance

IO

decorator design pattern is the key concepts

ex:

BufferedReader br=new BufferedReader(new InputStreamReader

(System.in));

easy way :

Scanner class in java 1.5

magic of decorator design pattern

IO

console

File handling

Read and Write

File f=new File("c:\\raj.txt");

FileReader fr=new FileReader(f);

BufferedReader br=new BufferedReader(fr);

public class IODemo {

public static void main(String[] args) {

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String a=null;

try {

a=br.readLine();

} catch (IOException e) {

// TODO Auto-generated catch block

Page 16: 5 Day Java Training Disucssion and Important Points

e.printStackTrace();

}

System.out.println(a);

}

slip bw cup and sip....

Exception handling

Checked

Unchecked: generally due to poor logic

Java cant help us...

All happen at run time

Ex of Unchecked

the problem cant be suggeted by compiler

logical problem of programmer java has nothing to do with that....

try

{

a=br.readLine();

}

catch(Exception ex)

{

ex.toString();

}

catch(IOException ex)

{

System.out.println(ex);

}

Page 17: 5 Day Java Training Disucssion and Important Points

finally

{

System.out.println("i am here");

}

Latent errors

Business Analysist

|

|

|

System Analysist

this is difficult field .....

Equality of primitive vs Equality of objects

Equality of primitive

==

not wise to check for == in the case of two double or float

rather check for inEquality

2.0 2.0000 not a good thing to compare two double or float

2 2

Summary till now:

...................................................

Exception handling

...................................................

key words:

try: put risky code under observation

Page 18: 5 Day Java Training Disucssion and Important Points

catch: possible remedies

throw: explicitly throwing exceptions, user defined exception

throws: throwing responsibilities our problem to someone else

finally: whether exception occur or not finally is going to be executed...

...................................................

we disucss about exception handling

collection

next day plan

:---------------------

visibility levels

multithreading

jdbc if time permit....

----------------------------------------------------------

Exception handling is not same as function calling!!!!!!!

try

{

tatement1

statement2--problem1

statement3

statement1

statement1

}

catch(Problelm1...)

{

sop("hi");

}

Page 19: 5 Day Java Training Disucssion and Important Points

catch(Problelm2...)

{

}

catch(Problelm2...)

{

}

In the case of exception handling if exception occur at statement2 ..it would be handled by catch for problem1 and now control will not go back in the try block…

Q. if finally is going to execute always then why hell we are using it?

finally

{

sop("india");

}

sop("india");

fun()

{

statement1

fun2();

statement2

statement3

}

fun2()

{

...

...

}

Page 20: 5 Day Java Training Disucssion and Important Points

- Type mismatch: cannot convert from boolean

to String

try {

br = new BufferedReader(new FileReader("c:\\raj\\abc1.txt"));

System.out.println("hi i am not going to printed");

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

System.out.println("file not found");

}

How to learn an new technology

First have a concept then u must have POC (Proof of concepts) then only u can thought applying it to ur job

throw: explicitly throwing exceptions, user defined exception

user define exception

if balance is less then 1000 i want to throw an exception

Accouting sw

NotSufficientFundException

i am near reality

oops is nothing but our life....

class Account

{

int accNo;

int fund;

Page 21: 5 Day Java Training Disucssion and Important Points

public void withdrawMoney(int money)throws

NotSufficientFundException

{

int temp=fund-money;

if(temp<=1000)

throw new NotSufficientFundException();

System.out.println("money is withdrawn");

fund=fund-money;

}

public Account(){}

public Account(int accNo, int fund) {

super();

this.accNo = accNo;

this.fund = fund;

}

public void showFund()

{

System.out.println("the current balance is:"+fund);

}

}

public class UserDefineEx {

public static void main(String[] args) {

Account ac=new Account(23434554,5999);

try {

ac.withdrawMoney(4000);

} catch (NotSufficientFundException e) {

// TODO Auto-generated catch block

Page 22: 5 Day Java Training Disucssion and Important Points

e.printStackTrace();

}

}

}

When to use try ..catch when to use throws/throw not a esay ans....

Design to interface

Separation of concern

imp topics:

arrray

Serious limitation of array

can’t grow at run time i.e. size is fixed

Removing and inserting and new element is not cup of tea...

collection

Readymade data structure.....

stack, queue,set, map etc

Q What is the diff between array and array list

array array list

size is fixed not fix...

finding is easy

removing and inserting dam easy

and new element is

not cup of tea...

fast slow

Page 23: 5 Day Java Training Disucssion and Important Points

in core java: collection and multithreading is most imp topics for any serious interviewer

package called

java.util

Q. difference between collection, Collection, Collections…

collection:

name of topics

<<Collection>>

an base interface

Collections:

static utility class

There are various type of ds like

LinkedList, DoublyLinkedList, Tree, Stack, Queue, Forest, Graph, Heap, Map, Set

Java makes our life easy as it provided almost all the ds readymade to us...

What is the challenge of collection? There is many readymade ds ...where to use what

Page 24: 5 Day Java Training Disucssion and Important Points

leftover : otherwise imp topics.....

Collection and Object class, comparable and comparator interface

topics :

jdbc

revision collection

collection

readymade datastructure

link list:

grow dynamically at run time

single-in one direction , doublely-both direction

tree:-

Page 25: 5 Day Java Training Disucssion and Important Points

ArrayList: single

LinkedList: doubly l...list

hashing make program faster.....

program without generics and with generics

with generics

j d b c tm

Java Data base conn

Way to connect to db...

DBMS: SQL, PL/SQL

9i internet

10g grid computing

11app

grid computing is father of cloud computing…which is the future....video on utube.. …check out…

client===========server

java code db stored in oracle mysql etc

Page 26: 5 Day Java Training Disucssion and Important Points

2-tier arch....

java gives specification and people follows it...

ie every vendor has its own implemention of driver..and related classes

they pack it into a formate that is called jar file

connector-j.jar for mysql

class123.jar for oracle

jdbc is subset of ODBC (Open dbc.. ms)

hibernate is some ORM(obejct relation mapping )used professionally for commercial projects......

database operation:-

DML: data manipulation language

DDL: data defination language

TCL: transaction control lang...

CURD

that u cant eat....

c: create

u:update

r: read

d: delete

package com.jdbc;

import java.sql.Connection;

Page 27: 5 Day Java Training Disucssion and Important Points

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class DemoConn {

public static void main(String[] args) {

Statement stmt=null;

ResultSet rs=null;

Connection con=null;

try

{

try

{

Class.forName("com.mysql.jdbc.Driver");

}catch(ClassNotFoundException ex){System.out.println("driver is not installed");}

con=DriverManager.getConnection("jdbc:mysql://localhost:3306/raj","root","root");

stmt=con.createStatement();

rs=stmt.executeQuery("select * from dept");

//rs is like a pointer

//till table not finish.. trevers it..process it..save it..

//jdbc in nutshell

while(rs.next())

{

System.out.println(rs.getInt("deptid"));

System.out.println(rs.getString("deptName"));

}

}

catch(SQLException ex)

Page 28: 5 Day Java Training Disucssion and Important Points

{

System.out.println("no db");

}

//should always be executed....

finally

{

if(con !=null)

{

try

{

con.close();

}catch(Exception e){}

}

if(rs!=null)

{

try

{

rs.close();

}catch(Exception e){}

}

}

}

}

what is db programming

Page 29: 5 Day Java Training Disucssion and Important Points

You are already aware of file handling file handling…

Db programming is sort of client server program…u should know IP address where server is running and port no ie tell about service we want to access…

What is the algo………….

open a connection

read the file till not end

that manipulte the records

finally close the connection..

ip port no.....

TCP/IP

ip: network layer

tcp: transport layer

first i have ip /port of server(ie db server)

name of bdase and usernane password

mySql : 127.0.0.1: 3306

root,root

name of dbase to be connection: raj

table to connected : emp

Statement

: for simple queries

PreparedStatement

:little faster and more flexible then Statement

Callable Statements:

Strored procedure.. sort of function on server side

Page 30: 5 Day Java Training Disucssion and Important Points

futher references:--------------

jdbc tutorial on visualbuilder.com

roseindia jdbc tutorial u find good code...

-------------------------------------

End of the session

i hope u have enjoyed with me

and finally

Semantic is more imp then syntax....it depends...on which side of table u are....