For Developers

StringTokenizer in JAVA

The StringTokenizer class allows an application to break a string into tokens. The tokenization method is much simpler than the one used by the StreamTokenizer class. The StringTokenizer do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments.


The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.


An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnDelims having the value True or False :

  • If the flag is Flase , delimiter characters serve to separate tokens. A token is a maximal sequence of consecutive characters that are not delimiters.
  • If the flag is True , delimiter characters are themselves considered to be tokens. A token is thus either one delimiter character, or a maximal sequence of consecutive characters that are not delimiters.

A StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed.

A token is returned by taking a substring of the string that was used to create the StringTokenizer object.

Example without Delimiter:-


StringTokenizer st = new StringTokenizer("Example Of String Tokenizer");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}


Output
=====
Example
of
String
Tokenizer

Example with Delimiter:-


StringTokenizer st = new StringTokenizer("1$2$3$4","$");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}


Output
=====
1
2
3
4

What is IBATIS?

The iBATIS Data Mapper makes it easier to use a database with Java and .NET applications. iBATIS couples objects with stored procedures or SQL statements using a XML descriptor. Simplicity is the biggest advantage of the iBATIS Data Mapper over object relational mapping tools.

The iBatis framework is a lightweight data mapping framework and persistence API that can be used to quickly leverage a legacy database schema to generate a database persistence layer for your Java application. A set of XML encoded SQL Map files–one for each database table–holds SQL templates that are executed as prepared statements and map the expected results to Java domain classes. From application code, a layer of iBatis Data Access Objects (DAO) acts as the API that executes the SQL Map templates and assigns the results to the corresponding Java domain classes.

To enable communication among DAO layers and Sql Map layers, an XML configuration file describes each DAO interface and implementation class, as well as the location of a second XML configuration file that in turn points to each SQL Map file and contains the database connection information.

Create Database,Table and Procedure in Sql Server - Beginners

Database Creation :


CREATE DATABASE EMPLOYEE

Table Creation :

CREATE TABLE EMPINFO
(
ROWID INT IDENTITY(1,1) NOT NULL,
EMPID INT NOT NULL,
EMPNAME VARCHAR(50) NOT NULL,
EMPDEPT VARCHAR(3) NOT NULL,
EMPSAL INT NOT NULL,
EMPADDRESS VARCHAR(100) NOT NULL,
ACTIVE CHAR(1) NOT NULL DEFAULT ‘T’
)

Procedure Creation :

CREATE PROC EMPINFO_ADD_EDIT
(
@iEMPID INT,
@vEMPNAME VARCHAR(50),
@vEMPDEPT VARCHAR(3),
@iEMPSAL INT ,
@vEMPADDRESS VARCHAR(100),
@cACTIVE CHAR(1)
)
AS
DECLARE @CNT INT;
BEGIN
SET @CNT = 0;
SELECT @CNT = COUNT(*) FROM EMPINFO WHERE EMPID = @iEMPID;
IF(@CNT = 0)
BEGIN

INSERT INTO EMPINFO(EMPID,EMPNAME,EMPDEPT,EMPSAL,EMPADDRESS,ACTIVE)VALUES @iEMPID,@vEMPNAME,@vEMPDEPT,@iEMPSAL,@vEMPADDRESS,@cACTIVE)

END
ELSE
BEGIN

UPDATE EMPINFO SET EMPNAME = @vEMPNAME,EMPDEPT = @vEMPDEPT,EMPSAL = @iEMPSAL, EMPADDRESS = @vEMPADDRESS,ACTIVE = @cACTIVE WHERE EMPID = @iEMPID

END

END

What is Linked List ?

Linked list is one of the fundamental concepts in the data structure. It consists of a set of nodes, each containing a 'data' field and one or two references (pointing to adjacent nodes). It is a self referential datatype since it contains reference(s) of the adjacent (next or previous) datum of the same type.

Advantage :
Advantage of linked list compared to conventional array are

  • Insertions and deletions of nodes can be done at anywhere in the list.
  • List size can be increased and decreased in runtime.
  • Order of the linked items can be different from how it is stored in memory or disk, thus allowing the list of items to be traversed in different order.
Types of linked lists exist are Singly linked list, Doubly linked list and Circular linked list.

Swapping a Number

SWAPPING WITHOUT TEMP:


#include <stdio.h>

void main()

{

int a=20,b=30;

a=a+b;

b=a-b;

a=a-b;

printf("a=%d",a);

printf("b=%d",b);

}


SWAPPING WITH TEMP:


#include <stdio.h>

void main()

{

int a=20,b=30,temp;

temp=a;

a=b;

b=temp;

printf("a=%d",a);

printf("b=%d",b);

}