0% found this document useful (0 votes)
74 views73 pages

New Microsoft Office Power Point Presentation

This document provides an overview of the Java programming language. It discusses Java concepts like data types, variables, operators, arrays, control statements, classes, methods, exceptions, threads, input/output streams, and collections. It also covers GUI components in Java like lists, trees, tables and Swing components. Key interfaces and classes involved in modeling lists, trees and other collections are described like TreeModel, DefaultTreeModel, TreeNode etc.

Uploaded by

Keshav Sen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views73 pages

New Microsoft Office Power Point Presentation

This document provides an overview of the Java programming language. It discusses Java concepts like data types, variables, operators, arrays, control statements, classes, methods, exceptions, threads, input/output streams, and collections. It also covers GUI components in Java like lists, trees, tables and Swing components. Key interfaces and classes involved in modeling lists, trees and other collections are described like TreeModel, DefaultTreeModel, TreeNode etc.

Uploaded by

Keshav Sen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 73

JAVA

Presented by: Keshav Sen HCL CDC(Fbd.)

UNIT 1: Core Java i. Introduction to java ii. Data types iii. Variables iv. Operators v. Arrays vi. Control Statements vii. Classes & Methods

JAVA

JSE

JEE

JME

Secure Portable Object Oriented Robust Multithreaded Architecture neutral Interpreted Distributed

Primitive

Non-primitive

Primitive:-

Integers: This group includes byte, short, int, and long. Floating-point numbers: This group includes float and double. Characters: This group includes char. Boolean: This group includes boolean.

i.
ii. iii.

Non-Primitive:
Class Array Stack

A variable is defined by the combination of an identifier, a type, and an optional initializer.

Instance/Global Class

variable

variable Local variable Reference variable

Arithmetic Operators The Bitwise Operators Relational Operators Boolean Logical Operators The Assignment Operator The ? Operator

An array is a group of like-typed variables that are referred to by a common name.

Types of Array:
One-Dimensional Arrays Multidimensional Arrays

if switch while do-while for break continue return

Class:
i.

ii. iii.

A non-primitive data type for its instances. Class is a template for its instance. Collection of variables and functions.

Signature of method: type name(parameter-list) { // body of method } Method without parameter Method with parameter

Single Multiple Multilevel Hierarchical Hybrid

Throwable

Exception

Error

Compile time Run time


i. ii. iii. iv. v.

Five key Words to handle Exception:


try Catch Throw Throws Finally

Try with multiple catch Nested try User defined Exception

Thread: single sequential flow of control within a process. Process: self-contained running program with its own address space.

i. ii. iii.

Different States of a Thread:


New Runnable Dead Blocked

iv.

New Thread start

Run
notify

wait
resume

stop

suspend
After(t)

sleep

i.
ii.

Controlling the main thread Creating a Thread: By implementing the Runnable Interface By extending the Thread class Creating Multiple Threads Deadlock Synchronization InterthreadCommunication

Taking input from user


Commandline argument BufferedReader Console DataInputStream Scanner

i. ii. iii. iv. v.

i. ii.

The Stream Classes


The Byte Streams The Character Streams


i.
ii.

Streams
A stream is an abstraction that either produces or consumes information. Streams are a clean way to deal with input/output without having to know every part of your code.

Byte Stream
Byte streams provide a convenient means for handling input and output of bytes.

Character Stream
Character streams provide a convenient means for handling input and output of characters

A Framework The collections framework was designed to meet several goals:


First, the framework had to be high-performance. The implementations for the fundamental collections(dynamic arrays, linked lists, trees, and hash tables) are highly efficient.
Second, the framework had to allow different types of collections to work in a similar manner. Third, extending and/or adapting a collection had to be easy.

i.

ii.

iii.

Collection List Set SortedSet

i.
ii. iii. iv. v.

Collection: an interface which provides the methods to represent group of objects as a unit. Methods of Collection Interface: public boolean add(Object ob) Public void addAll(Collection c) Public Iterator iterator() Public Object remove() Public void removeAll()


i.

List Interface:
The List interface extends Collection and declares the behaviour of a collection that stores a sequence of elements. A list may contain duplicate elements.

ii.

i. ii. iii. iv.

Methods in List Interface:


void add(int index, Object obj) boolean addAll(int index, Collection c) ListIterator listIterator( ) Object remove(int index)


i.

Set Interface:
It extends Collection and declares the behaviour of a collection that does not allow duplicate elements.

i.

Sorted Set Interface:


The Sorted Set interface extends Set and declares the behaviour of a set sorted in ascending order.

i. ii. iii. iv.

Methods of Sorted Set Interface:


Comparator comparator( ) Object first( ) Object last( ) SortedSet subSet(Object start, Object end)

AbstractCollection-Implements Collection interface. AbstractList-Extends AbstractCollection and implements the List


interface.

AbstractSequentialList-Extends AbstractList LinkedList-Implements a linked list by extending


AbstractSequentiaList.

ArrayList-Implements a dynamic array by extending


AbstarctList

AbstractSet-extendsAbstarctCollection & implement Set Interface HashSet-Extends AbstractSet LinkedHashSet-Extends HashSet TreeSet-Implements a set stored in a tree. Extends AbstractSet.

i.

i.

Via Iterator Iterator an interface which provides functionality to travel objects in forward direction. Via ListIterator ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.

i.
ii. iii. i. ii. iii. iv.

Methods of Iterator boolean hasNext( ) Object next( ) void remove( ) Methods of ListIterator boolean hasNext( ) boolean hasPrevious( ) Object next( ) Object previous( )

i.

Storing User-Defined Classes in Collections Working with Maps


A map is an object that stores associations between keys and values, or key/value pairs.

i. ii.

Map Interface: Map: Maps unique keys to values. MapEntry: Describes an element (a key/value pair)
in a map. This is an innerclass of Map.

iii.

SortedMap: Extends Map so that the keys are


maintained in ascending order.

i. ii. iii. iv. v. i. ii. iii.

Methods of Map Interface: void clear( ) boolean containsKey(Object k) boolean isEmpty( ) Object put(Object k, Object v) Object remove(Object k) The SortedMap Interface Comparator comparator( ) Object firstKey( ) SortedMap tailMap(Object start)


i.
ii.

Map.Entry Interface:
boolean equals(Object obj) Object getKey( )

i.
ii. iii.

Classes for Map:


AbstractMap HashMap TreeMap

Comparators

i.
ii. iii. iv. v. i.

Classes: Dictionary Hashtable Properties Stack Vector Interfaces: Enumeration Interface

Component Container Windows Frame Panel Applet

i.
ii. iii. iv. v.

Applet Skeleton: Init() Start() Stop() Destroy() Paint() Overriding update( ) Requesting Repainting

Setting the Windows Dimensions Hiding and Showing a Window Setting a Windows Title Closing a Frame Window

Drawing Lines Drawing Rectangles Drawing Ellipses and Circles Drawing Arcs Drawing Polygons

Buttons Label TextField LayoutManager Menu MenuBar Panel List CheckBox Choice

List Trees Tables Styled Text Components Progress Indicator Component Organizers

ListModel:
JList by default uses the DefaultListModel class, an implementation of ListModel that stores a collection of data objects in a Vector. Selection Model: represents the user's selections. It also implements DefaultListSelectionModel. Cell Renderer: defines how each cell displays its data in the list, including when the cell is selected.

i. ii. i.

Swing uses one interface and two classes to maintain a model of the list elements.

i. ii. iii. iv.

The ListModel Interface:


Object elementAt (indexed) Int Size() addListDataListener() removeListDataListener()

i.

AbstractListModel Class DefaultListModel Class


class is based on the java.util.Vector class, a resizable array of
objects.


i.
ii. iii. iv.

Method of DefaultListModel Class


public void copyInto(Object anArray[]) public void trimToSize() public int capacity() public int size()

Swing uses a simple interface for models that handle list selections ListSelection-Model and also provides a default implementation DefaultListSelection-Model.

i. ii.

The ListSelectionModel Interface


public abstract void addSelectionInterval(int index1, int index2) public abstract void removeSelectionInterval(int index1, int index2)

i.

DefaultListSelectionModel Class
public Object clone() throws CloneNotSupportedException

i.

ListSelectionEvent
ListSelectionEvent specifies a change by highlighting those elements in the selection list that have altered.


i.

ListSelectionListener
The ListSelectionListener interface is the conduit for receiving the ListSelectionEvent objects. public abstract void valueChanged(ListSelectionEvent e)

ii.

A cell renderer is a component whose paint() method is called each time the component needs to draw or redraw an element. To create a cell renderer, you need only register a class that extends the ListCellRenderer interface.

i.

ListCellRenderer Interface
public abstract Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)

i.

DefaultListCellRenderer Class
public Component getListCellRendererComponent(JList list, Object value, int index,boolean isSelected, boolean cellHasFocus)

i. ii. iii. iv. v. vi. vii.

Any data that contains parent-child relationships between chunks of information can be displayed as a tree. Tree Terminology
Node Root Child Parent Sibling Level Path


i.
ii. iii.

The TreeModel Interface:


public Object getChild(Object parent, int index) public int getChildCount(Object parent) public boolean isLeaf(Object node)

i.

DefaultTreeModel Class
public void insertNodeInto(MutableTreeNode child, MutableTreeNode parent, int index) public void removeNodeFromParent(MutableTreeNode node)

ii.


i.

TreeNode Interface
public int getIndex(TreeNode node)

i. ii.

MutableTreeNode Interface:
public void insert(MutableTreeNode child, int index) public void remove(int index)

i. ii.

DefaultMutableTreeNode Class:
public void add(MutableTreeNode child) public boolean isLeaf() public boolean isRoot() public void remove(int index)

iii.
iv.

i.

The TreePath Class: public boolean equals(Object otherPath)

a.
b.
i. ii. iii.

Table Columns TableColumn Class TableColumnModel Interface


public void addColumn(TableColumn column) public void moveColumn(int index, int newIndex) public void removeColumn(TableColumn column)

c.
i. ii.

DefaultTableColumnModel Class
public void addColumn(TableColumnColumn) public int getColumnIndexAtx(int xPixell)

d. i. ii.

TableColumnModelEvent Class public int getFromIndex() public int getToIndex()

a.
b.
i. ii.

Table Data TableModel Interface AbstractTableModel Class


public int findColumn(String columnName) public String getColumnName(int index)

c. i. ii.

DefaultTableModel Class public void addColumn(Object columnID) public void addRow(Object[] rowData)

i.

JTable Class JTableHeader Class


i.
ii.

JTextComponents:
JTextField JtextArea

i.

Styled Text Components


JEditorPane extends the JTextComponent

JEditorPane does not display the contents of applet.

Split pane: a mechanism for splitting an area into multiple parts


whose boundaries can be adjusted.

Tabbed pane: which uses tab dividers to allow a user to flip


through multiple panels.

Desktop pane: which can be used to implement applications that


display multiple internal frames.

Design of JDBC Structured Query Language JDBC Installation Basic JDBC Programming Concepts Query Execution


i.
ii. iii. iv.

Types of JDBC
Type-1:JDBC-ODBC Bridge Part Java Part Native Intermediate Data Acess Server Pure Java Driver

JDBC URL: <protocol>:<subprotocol>:<subname> How to Load Drivers:

Scrollable Result Sets (JDBC 2) If you want the result set not to be scrollable than use:

ResultSet.TYPE_FORWARD_ONLY.

If the result set is scrollable, than use:


ResultSet.TYPE_SCROLL_INSENSITIVE

If you simply want to be able to scroll through a result set but you don't want to edit its data, you use: Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE,ResultSet.CONCUR_READ_ONLY);

If you want to be able to edit result set data and have the changes automatically reflected in the database, you need to create an updatable result set.
To obtain updatable result sets, you create a statement as follows. Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

The structure of a database and its tables can be obtained by using the Metadata. For example, you can get a list of the tables in a particular database or the column names and types of a table. To find out more about the database, you need to request an object of type DatabaseMetaData from the database connection: DatabaseMetaData meta = conn.getMetaData();

i.

Now to call : ResultSet rs = meta.getTables(null, null, null, new String[]{ "TABLE" });

There is a second metadata class, ResultSetMetaData, that reports information about a result set.

ResultSet rs = stat.executeQuery("SELECT * FROM " +tableName); ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { String columnName = meta.getColumnLabel(i); int columnWidth = meta.getColumnDisplaySize(i); Label l = new Label(columnName); TextField tf = new TextField(columnWidth); ... }

i. ii. iii. iv.

Transaction is a group of statements which will either succeed or fail depending upon the condition. A valid transaction must follow the following properties: Automiticity Consistent Isoloation Durable

Connecting to a Server Implementing Servers Sending E-Mail

The bootstrap class loader; The extension class loader; The system class loader (also sometimes called the application class loader).

You might also like