Core Java Programming I: Karimullabasha (Technoschool)
Core Java Programming I: Karimullabasha (Technoschool)
KarimullaBasha (TechnoSchool)
October 17, 2015 TCS Confidential
Objectives of Session
Introduction to OOPs(Object Oriented Programming)
Why JAVA?
Learning JAVA
Classes &Objects
Object Creation
New operator
Cloning
Serialization
Class.forName("classname").newInstance()
Inheritance
Single,Multiple,Multilevel,Hybrid
Data Abstraction
Data Encapsulation & Data Hiding
Polymorphism
Static (Overloading Early Binding),
Dynamic( Overriding Late Binding)
Reusability
Why JAVA ?
C++ Vs JAVA
In C++, we can write programs with out class but in Java any code that we
write, must be inside a class and the name should be same as program
name.
JAVA Programming
Primitive Data Types
Integers
byte
Short
int
long
Real Numbers
float
double
Other Types
char
Boolean
8-bit
16-bit
32-bit
64-bit
32-bit
64-bit
16-bit
true/false
Arrays
Strings
Objects
Interfaces
JAVA Programming
Java variable Modifiers
JAVA Programming
Local variables
Instance variables & Instance Methods
Static variables(Class variables or Global variables)
It is shared among all instance of a class. A local variable declared within a method cannot be
static.
JAVA Programming
Arrays
Wrapper Classes
Integer, Float, String (immutable) & String Buffer (mutable)
Abstract & Concrete Classes & Final Classes
Nested Classes (Static, Non-static or Inner Classes) & Anonymous Inner Classes
Object creation for Static Nested Classes & Inner classes
Inner classes cannot have static declarations (variable/method)
Interfaces
can contain only constants & method signatures
implicitly variables are public ,static ,final & methods are public
Markup Interfaces (SingleThreadModel, Serializable, Cloneable)
Markup Interface is a Java Interface which has nomethods & and whole responsibilty on you to create method
super
Final
Native Method JNI(Java Native Interface)
Volatile (This variable modified by other parts of the program un expectedly ex:Threads)
persistence & serialization(Ex:RMI)
Serialization is the process of wiring the state of an object to a byte stream.
static and transient variables are not saved by the serialization facilities.
Object Graph (All Base Classes which extends Serialized will be serialized)
transient
This
Reflection
Packages & import
Java.lang(classloader,object,process,runtime classes Runnable,Clonable Interfaces)
java.util(Date,Calender,Random)
java.io(Bytes-I/OStreams,Character-Reader/writer)
java.sql,java.net
Java.awt,java.swing
Exception
RuntimeException
IOException
Error
AWTError
ThreadDeath
OutOfMemoryError
10
11
Threads
Thread Lifecycle
Born
start
ep
sl
e
I/O completes
acquire lock
interrupt
en
te
Running
r
stasyn
iss
te chr
re ue
m on
qu I
en iz
es /O
t ed
t
te
sleep interval
expires
interrupt
thread dispatch
(assign a
processor)
ple
Waiting
it
wa
com
notify
notifyAll
timeout expires
interrupt
Ready
quantum expiration
yield
Sleeping
Blocked
12
Threads
Methods in Threads
start(): is responsible for starting a thread and calls the run() method of the thread.
Thread creation
13
Collection Framework
Collection Framework Asynchronous (Java.util)
List (ArrayList,LinkedList)
- Allows duplicate elements
- Array List -> implements a dynamic array. Fast iteration and fast random access. It can be created with
an initial size. When this size is exceeded, the collection is automatically enlarged and when objects are
removed the array may be shrunk.
Hashing
Set (HashSet,TreeSet)
- No duplicate elements
Map (HashMap,TreeMap)
- Key/value pair * No duplicate keys
- Hash Map -> allows one null key, many null values
Collection
Iterator
Legacy Classes
Design Patterns
14
Applet
Applet??
Applet LifeCycle
Init ->start->stop->destroy
Applets run in
appletviewer (test utility for applets)
Web browser (IE, Communicator)
15
JDBC
JDBC??
Drivers & Types
Type1: JDBC-ODBC Bridge
This driver translates all JDBC calls into ODBC calls & sends them to ODBC driver
Type2: Native-API/Partly Java driver
This driver converts JDBC calls into database-specific calls such as SQL server,Oracle,sybase.This driver communicates directly
with the database server.
Type3:Net-Protocal/Pure java driver
JDBC requests are passed through the n/w to middle-tier server. This server translates to db specific connectivity interface to
further the request to db server.
Type4:Native-Protocal(Pure Java Driver)
It converts JDBC calls into vendor specific DBMS protocol, so that client applications can communicate directly with DB server.It
pure jave driver to achieve platform independence.
Simple JDBC Connectivity
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url,"North","Ken"); //Register Driver with DriverManager
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT Surname,FirstName,Category FROM Per");
PreparedStatement pstmt=Con.prepareStatement( "UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");
pstmt.setInt(1, carNo);
pstmt.setInt(2, empNo);
pstmt.executeUpdate();
CallableStatement cstmt = con.prepareCall( "{call getTestData(?, ?)}"); //call Stored Procedures
cstmt.registerOutParameter(1, java.sql.Types.TINYINT);
16
Thank You