Você está na página 1de 70

UNDERSTANDING

DOCUMENTS
JAVA,ORACLE,UNIX

HCL TECHNOLOGIES PUNE


APPALA VENKATA SATYANARAYANA CHITIKALA

1 | Page
JAVA

Page | 2
1. In
tr
od
uc
tio
n
to
Ja
va
2. O
O
PS
co
nc
ep
ts
3. Ac
ce
ss
M
od
if
er
s
4. Da
ta
Ty
pe
s
5. Ar
ra
ys

Introduction to Java:
Java is a object oriented language because it deals with objects i.e., like comparing
one object with other or call one object with other. Java is simple, robust, secure,
portable, object-oriented programming language, platform independent.

OOPS Concepts:
Class
Object
Abstraction

Page | 3
Encapsulation
Inheritance
Polymorphism

Object: An entity, which has state and behavior, is called Object.

Class: Class is a template or Blueprint of which objects can be created.

Abstraction: Hiding up the data and showing it properties.


E.g.: Phone which we are using in our day to day life, we dont know exactly what it
is going internally but can be able to see its functionality it is nothing but
Abstraction.

Encapsulation: Wrapping up the data in single unit is called Encapsulation.


e.g.: We can see a tablet, which has all the chemical properties, which is stuffed and
wrapped up in a capsule so that not to get loose of its properties.

Inheritance: Inheriting the properties of a parent class to child class.


e.g.: Generally, in a real scenario of developing a code there may be use of
properties which are also need to be use in another class, so that time we can use
the concept of Inheritance

Polymorphism: One name many forms it can be achieved by overloading and


overriding
1. Overloading: Increase Code readability.
2. Overriding: To provide the specific implementation of the method that is already
provided by its super class

Access Modifers: Provides scope of data member, constructer and method


There are four types of modifiers
1.Public
2.Private

Page | 4
3.Protect
4.Default

Business implementation: Access modifiers are the most important while we are
developing our code because it is the scope where we define the data that can be
retried globally or locally.

Strings: String is immutable class, it cannot be changed once we define.


String Types
1.String
2.String Builder
3.String Buffer
String Builder and String Buffer are used for creating string dynamically. Where
String Builder is non-synchronized and String Buffer is synchronized.
Data types: There are of two types
1.Primitive
2.Non-primitive

Arrays: Array is a collection of similar type of elements that have contiguous


memory location.
Here we can retrieve and sort the data easily.

Generally, we dont know where to use and how to use while we are developing a
code for an application. We need to follow the business requirements, Naming
conventions and keep the code in short and simple way for better way of
understanding. The coding should be simple and short.

List of Topics Technical course (java)


1.Generics
2.Annotations

Generics:

Page | 5
Generic methods and generic classes enable programmers to specify, with a
single method declaration, a set of related methods, or with a single class
declaration, a set of related types. Generics is used for sorting arrays of
objects.

All generic method declarations have a type parameter section delimited by


angle brackets (< and >)
Example: <T>
Class <?> in this <?> represents wild card.

Annotations:

Annotations form of metadata, provide data about a program that is not part
of the program itself. Annotations have no direct effect on the operation of
the code they annotate.

Uses of annotations:

Information for the compiler: Annotations can be used by the compiler to


detect errors or suppress warnings.

Compile-time and deployment-time processing: Software tools can


process annotation information to generate code, XML files, and so forth.

Runtime processing: some annotations are available to be examined at


runtime.

List of Topics Java


1. collections

Collections:
Collections is a single unit of objects and is a framework that provides an
architecture to store and manipulate the group of objects.
By using java collection you perform all the operations on a data such as
searching, sorting, insertion, manipulation, deletion etc.
1. Collections provides readymade architecture.
2.They represents set of classes and interface.

Page | 6
Iterator interface:
Iterator interface provides the facility of iterating the elements in forward
direction only.
It iterates the list of objects and removing can also be done.

we have three methods in iterator interface:


1. public Boolean has Next() : it returns true if iterator has more
elements.
2. public object next() : It returns the element and moves the cursor
pointer to the next element.
3. public void remove() : it removes the last elements returned by the
iterator. It is rarely used.

There are two ways to iterate the elements collections in java. They are:
1. By iterator interface
2. By for-each loop interface

There are two types of iterators:

Fail Fast iterator : Hash map - Fail fast contains the original collection of
objects we are unable to remove the objects.

Fail Safe Iterator : Hash table - Fail safe contain the copy of original
objects , so we are able to remove the objects easily by using Remove().

Comparable : It comes from java Lang package.When we need compare of


single object we use comparable. Compare To() method is used , to compare
the objects.

comparator: It comes from java Util package . It is used when we need to


compare more number of objects. Compare() method is used , to compare
more number of objects.

Lists:
Array List:

Page | 7
Java Array List class uses a dynamic array for storing the elements. It
extends Abstract List class and implements List interface. Java Array List
class can contain duplicate elements and also maintains insertion order.
1. Java Array List class is non synchronized.
2. It allows random access because array works at the index basis.
3. In this class, manipulation is slow because a lot of shifting needs to be
occurred if any element is removed from the array list.

There are two array lists in the java collections. They are:
1. Non-generic:

Array List al = new Array List ();


2. Generic:

Array List<String> al = new Array List<String>();


Linked List:
Whenever manipulation has to be done more then this list is used.This class
uses doubly linked list to store the elements.
1. It extends the Abstract List class and implements List and Deque
interfaces . It can contain duplicate elements and maintains insertion
order.
2. This class is non synchronized. In this class, manipulation is fast
because no shifting needs to be occurred and can be used as list, stack
or queue.

Synchronized: Synchronization in java is the capability to control the access


of multiple threads to any shared resource.

Sets:
Hash Set:
A hash set uses hash table to store the elements. It extends Abstract Set
class and implements Set interface and contains unique elements only.

Linked Hash Set:

Page | 8
A linked hash set contains unique elements only like Hash Set. It extends
Hash Set class and implements Set interface and maintains insertion order.

Tree Set:
A tree set contains unique elements only like Hash Set. The Tree Set class implements
Navigable Set interface that extends the Sorted Set interface. Maintainsascending order.

Maps:

A map contains values on the basis of key i.e. key and value. Each key and
value pair is known as an entry. Map contains only unique keys.Map is
useful if you have to search, update or delete elements on the basis of key.

Entry Interface:
Entry is the sub interface of Map. So we will be accessed it by Map.Entry
name. It provides methods to get key and value.

Methods of Map.Entry interface


1. public Object getKey(): is used to obtain key.

2. public Object getValue():is used to obtain value

List of Topics Java


1. Exception handling.

Exception Handling:
The exception handling in java is one of the powerful
mechanismtohandletheruntime errors so that normal flow of the application
can be maintained without any interruptions.
There are three types of exceptions:

1. Checked Exception

2. Unchecked Exception

Page | 9
3. Error

1) Checked Exception:

The classes that extend Throwable class except Runtime Exception and
error are known as checked exceptions like IO Exception, SQL Exception etc.
these are checked at compile-time.
2) Unchecked Exception:

The classes that extend Runtime Exception are known as unchecked


exceptions like arithmetic Exception, Null Pointer Exception, Array Index
Out Of Bounds Exception etc. Unchecked exceptions are not checked at
compile-time rather they are checked at runtime
3)Error:
Error is irrecoverable. Some of the errors are out of memory error, virtual
machine error, Assertion error etc.

There are 5 keywords used in java exception handling.

1. try

2. catch

3. finally

4. throw

5. throws

1) Try block:A try block is used to enclose the code that might throw an
exception. It must be used within the method. Java try block must be
followed by either catch or finally block.

Page | 10
2) Catch block:Java catch block is used to handle the Exception. It must
be used after the try block only. Multiple catch blocks can also be used
with a single try.

3) Finally: Java finally block is a block that is used toexecute important


code such as closing connection, stream etc.Java finally block is always
executed whether exception is handled or not. Java finally block follows
try or catch block.

4) Throw: Throw keyword is used to explicitly throw an exception. We


can throw either checked or unchecked exception in java by throw
keyword. The throw keyword is mainly used to throw custom exception.
Custom exceptions are seen later.

5) Throws:Throws keyword is used to declare an exception. It gives


information to the programmer that there may occur an exception so it
is better for the programmer to provide the exception handling code so
that normal flow can be maintained. An exception is declared in the
method syntax itself.

Exception Propagation: Until caught the exception of stack, or until


reaches bottom of stack, it will propagate. This process is known as
Exception propagation.

Ex: stack m(); n(); p(); main();

Note: Exception is occurred at m(), but it is not handled. So it is propagate to


previous method n(). n() is also not handled. It is propagate to previous
method p(),where the exception is handled.

Number format exception: I have to convert variable into string


(typecasting)on that time number format exception occur or when there is a
string given but it is given some number or treating it as a integer normally
throws this type of exceptions.

Page | 11
Class not found exception: In jar files we have number of classes .Like a,
b, c, d. I am trying to call class E. There is no call E in jar file. On that class
not found exception occur. And also whenever the jar files misses some
classes when they are imported.

Custom Exception: These exceptions are created on our own.

List of Topics Java


1. File Handling i/o
2.Java Thread
File Handling:

Java I/O (Input and Output) is used to process the input and produce the
output based on the input.Java uses the concept of stream to make I/O
operation fast. The java.io package contains all the classes required for
input and output operations. Filehandling in javais performed by java IO
API. It is handled by I/o packages through which we can read and write.

Manipulation: The content can basically manipulated either by read or


write. Content can be copied also.

Stream:

A stream is a sequence of data.

There are three types of streams, they are:

1) System.out: standard output stream

2) System.in: standard input stream

3) System.err: standard error stream

Working of java input stream and output stream:

Input stream output stream


Java
SOURC Destinati
Application
E on

Read Write

Page | 12
Input stream:

Java application uses an input stream to read data from a source, it may
be a file, an array, peripheral device or socket.

Output stream:

Java application uses an output stream to write data to a destination, it


may be a file, an array, peripheral device or socket.

Multi-Threading:

Multithreading in java is a process of executing multiple threads


simultaneously. Thread is basically a lightweight sub-process, a smallest
unit of processing. Multiprocessing and multithreading, both are used to
achieve multitasking.

P11 P2

write

Read
P3

Upload

Switching from one process to another process is not possible in


processing but possible in threading.

Page | 13
Multitasking:
Multitasking is a process of executing multiple tasks simultaneously. We
use multitasking to utilize the CPU. Multitasking can be achieved by two
ways:

1. Process-based Multitasking(Multiprocessing)

2. Thread-based Multitasking(Multithreading)

1) Process-based Multitasking (Multiprocessing):


1. Each process have its own address in memory i.e. each process
allocates separate memory area.

2. Process is heavyweight.

3. Cost of communication between the process is high.

4. Switching from one process to another require some time for


saving and loading registers, memory maps, updating lists etc.

2) Thread-based Multitasking (Multithreading):


1. Threads share the same address space.

2. Thread is lightweight.

3. Cost of communication between the thread is low.

Thread Class:

A thread is a lightweight sub process, a smallest unit of processing. It is a


separate path of execution. Threads are independent, if there occurs
exception in one thread, it doesn't affect other threads. It shares a
common memory area.

Page | 14
Thread Life Cycle:

Start ()
Born State Runnable State

Run()

Running State

Sleep ()
Dead/Terminated Wait State

Stop ()

Page | 15
List of Topics Java
1.JDBC

JDBC:

Java JDBC is a java API to connect and execute query with the database. JDBC
API uses jdbc drivers to connect with the database.

JDBC API

Data Base

JAVA JDBC Driver


Application

API:

API (Application programming interface) is a document that contains


description of all the features of a product or software. It represents classes
and interfaces that software programs can follow to communicate with each
other. An API can be created for applications, libraries, operating systems,
etc.

JDBC Driver:
JDBC Driver is a software component that enables java application to
interact with the database. There are 4 types of JDBC drivers:
1. JDBC-ODBC bridge driver

Page | 16
2. Native-API driver (partially java driver)

3. Network Protocol driver (fully java driver)

4. Thin driver (fully java driver)

5 steps to connect to the database in java:

There are 5 steps to connect any java application with the database in
java using JDBC. They are as follows:
1. Register the driver class

2. Creating connection

3. Creating statement

4. Executing queries

5. Closing connection

1) Register the driver class:


The forName() method of Class class is used to register the driver class. This method is
used to dynamically load the driver class.

Page | 17
2) Create the connection object:
The getConnection() method of DriverManager class is used to establish connection with
the database.

3) Create the Statement object:


The createStatement() method of Connection interface is used to create
statement. The object of statement is responsible to execute queries with
the database.

4) Execute the query:

The executeQuery() method of Statement interface is used to execute


queries to the database. This method returns the object of ResultSet that
can be used to get all the records of a table.

5)Close the connection:

By closing connection object statement and ResultSet will be closed


automatically. The close() method of Connection interface is used to close
the connection.

To connect with oracle data base:

1. Driver class: The driver class for the oracle database is


oracle.jdbc.driver.OracleDriver.

2. Connection URL: The connection URL for the oracle10G database is


jdbc:oracle:thin:@localhost:1521:xe where jdbc is the API, oracle is
the database, thin is the driver, localhost is the server name on
which oracle is running, we may also use IP address, 1521 is the
port number and XE is the Oracle service name. You may get all
these informations from the tnsnames.ora file.

3. Username: The default username for the oracle database is system

4. Password: Password is given by the user at the time of installing the


oracle database.

Two ways to load the jar file:

Page | 18
1. paste the ojdbc14.jar file in jre/lib/ext folder

2. set classpath

1) paste the ojdbc14.jar file in JRE/lib/ext folder:


Firstly, search the ojdbc14.jar file then go to JRE/lib/ext folder and paste
the jar file here.

2) set classpath:
1.Temporary

2. Permanent

Methods used in connection interface:

1) public Statement createStatement(): creates a statement object that can


be used to execute SQL queries.

2) public Statement createStatement(int resultSetType,int


resultSetConcurrency): Creates a Statement object that will generate
ResultSet objects with the given type and concurrency.

3) public void setAutoCommit(boolean status): is used to set the commit


status.By default it is true.

4) public void rollback(): Drops all changes made since the previous
commit/rollback.

5) public void close(): closes the connection and Releases a JDBC resources
immediately.

6)Public void commit():Saves the changes made since the previous


commit/rollback permanent.

Page | 19
Java CallableStatement Interface:
CallableStatement interface is used to call the stored procedures and
functions.We can have business logic on the database by the use of stored
procedures and functions that will make the performance better because
these are precompiled.

Suppose you need the get the age of the employee based on the date of
birth, you may create a function that receives date as the input and
returns age of the employee as the output.

Transaction management:

Commit

Transaction succeeded Transaction

Initial State roll back

Transaction failed

List of Topics java


1. Multithreading
2. servelet

Multithreading:
Requires single memory space. Processor can handle the processes in one
second lag or any application running with web. Parallelism process can be
done without any interruption when more users are using.
servlet:

Page | 20
Server side program, here the client requires and the server responds.
Request comes to dispatcher servlet.
Servlet engine: As soon as the request comes creates a thread internally and
then it allocates servlet instance calls [Service method].
A thread could be extension of core java thread.
Thread safe: At time process happens but at time one users should not get
wrong information because of other user.
1.One servlet can handle multiple requests.
2.Object should be thread safe.
3.Minimal number of instances.

List of Topics Java


1. servlet
2. jsp

Servlet:
Dynamically generates HTML pages. Spring uses servlet as its base.
Life cycle:
1.Loading
2.Instantiating and initializing
3.Request processing
4.destroying
1.Loading:
Web application class loader.
2.Instantiating and initializing:
Class.forName
Call init() method
Pass the servlet config object
Initializing will be two types as per requirement

Page | 21
1. Eager: Deploying the application we use eager all the
files loading in the first request it comes.
2. Lazy: Dont want to load all the files during
deployement.

3.Requesting Processing:
Service method is used to handle all request service () should be
implemented thread safe.

4.Destroying:Stops incoming request. Complete the current execution


request either it is roll back or executed.

Instantiation doPost()

Initialization doGet()
Invokes init()

Page | 22
doTrace()

Service
request
Invokes destroy()
response doPut()

Destroy doDelete()

Invokes destroy()

doHead()

Unavailable doOptions()

servlet API:
It is a servlet interface.
Generic servlet:
It does not support Http servlet.
servlet API:
ServletsGeneric ServletHttp ServletMy servlet

Any object is passing from one class to other if it is serializable and then
sent, it would be safe.

Servlets

Generic servlets

Http servlets

Page | 23
My Servlets

JSP:
Java Servlet Pages.
Present dynamic content to users.
Life cycle:
1.Translation
2. Compilation
3. Loading
4. Instantiation and Initialization
5. Request processing
6. Destroy

Buffer:For loading of jsp it takes some memory and it would be defined by KB


by using buffer we can directly define.

List of Topics Java


1.Web application

Tracking session:

1. Cookies: communication between Client and request

2. Hidden form fields:

3. URL rewriting: ending of URL we write session id with number.

Page | 24
Introduction to web:

Web features:

1.Client/Server

2.HTTP

3.Hyper Text Markup Language

4.URL addresses

Web server - a computer program that is responsible for accepting HTTP


requests from clients and serving them HTTP responses

Web application - a dynamic extension of a web or application server

Web Application:

A web application is a collection of servlets, html pages, classes, and other


resources that can be bundled and run on multiple containers from multiple
vendors.

A Web application is located on a central server and provides service to a


variety of clients.

Web components are supported by the services of a runtime platform called


a web container

In J2EE, a web container "implements the web component contract of the


J2EE architecture

Web container services:

1. request dispatching

2. security

3. concurrency

4. life-cycle management

5. naming, transactions, email APIseb containers

ANT:

Page | 25
1.Build tool: it builds software according to a set of rules. An Apache Jakarta
project. Jakarta is an umbrella heading for all the Java related Apache
projects. Open source, Apache License

2. Automated tool

List of Topics Java Session


1.JVM Memory Management

JVM:

The Java Virtual Machine defines various run-time data areas that are used
during execution of a program. Some of these data areas are created on Java
Virtual Machine start-up and are destroyed only when the Java Virtual
Machine exits. Other data areas are per thread. Per-thread data areas are
created when a thread is created and destroyed when the thread exits.

Memory Management:

Heap Area Method Area Java VM Native


Stack Method
Stack

PC Registers

Page | 26
Types of Java JVM Run-time Memory Areas

1. Heap Area

2. Method area

3. Java VM Stack

4. Native method stack

5. PC Registers

1. Heap Area:

The heap area represents the runtime data area, from which the memory is
allocated for all class instances and arrays, and is created during the virtual
machine startup.

2. Method area:

Method area stores per-class structures such as the runtime constant pool;
field and method data; the code for methods and constructors, including the
special methods used in class, instance, and interface initialization.

3. Java VM Stack:

Each of the JVM threads has a private stack created at the same time as that
of the thread. The stack stores frames. A frame is used to store data and
partial results and to perform dynamic linking, return values for methods,
and dispatch exceptions.

4.Native method stack:

Native method stacks are called C stacks; it supports native methods


(methods written in a language other than the Java programming language),
typically allocated per each thread when each thread is created. Java Virtual
Machine implementations that cannot load native methods and that do not
themselves rely on conventional stacks need not supply native method
stacks.

5. PC Registers:

Page | 27
Each of the JVM threads has its own program counter (pc) register. At any
point, each of the JVM threads is executing the code of a single method,
namely the current method for that thread.

Garbage collection:
Garbage collection is the process of automatically detecting memory that is
no longer in use, and allowing it to be used again. Java employs garbage
collection to free memory that has been used by objects, saving
programmers having to explicitly dispose of them.

ORACLE
Page | 28
List of Topics Technical course (oracle)
1. Introduction to oracle 10g
2. Application server and
database.
3. System development life
cycle
4. Data Storing on different
models
5. Sql statements

Introduction of oracle 10g:


Oracle offers a comprehensive high performance infrastructure for e-
business.

Page | 29
Oracle 10g include everything needed to deploy, develop and manage
internet applications.
Other benefits like scalability, reliability and secure architecture.
Application server and database:
Oracle 10g Application server runs all internet applications.
Oracle 10g database stores all data.
Oracle 10g Application server provides integration between users,
applications and data.
System Development Life Cycle:
From idea to final production we can develop a data base by using system
database life cycle.
Stages of SDLC
1. Strategy and Analysis
2. Design
3. Build and document
4. Transactions
5. Production.
Data Storing on different models:
1. Electronic spread sheets( Excel sheets)
2. Filing cabins
3. Database
Sql statements:
1. Data Definition Language.
2. Data Manipulation Language.
3. Data Control Language
4. Transaction control.

List of Topics Oracle


1.Data storage structures

Data storage structures:

There are two types of data storage structures:

1. Physical storage structure

Page | 30
2. Logical storage structure

1. Physical storage structure:

We can see the storage is done in a file which is nothing but the physical
appearance.

There are so many types of files:

1. Data files: Files where we can store the data in data base.

2. Control file: It contains basic information of the data base which is also the
binary file.

3. Redo log file: The changes that had been done in the data base that would
be stored in other file which is nothing but the Redo files.We can also recall
the information or data whenever the data base crashes.

4. Archive File:

2. Logical storage structure:

Oracle database allocates space for all the data in the data base. There is
Table space, Segment, Extent, Block in the logical storage stucture.

Logical storage hierarchy

Blocks ExtendsSegments

1. Data blocks: Data blocks area the smallest unit of storage that oracle data
base can use.

2. Extent: An extent is a set of logically contiguous data blocks allocated for


storing in specific information.

3. Segment: A segment is a as setoff extents allocated for a specific


database object such as tables.

4. Table Spaces:

Page | 31
These are categorized into four types:

1. System Table Space:

2. Syntax table space: it is auxiliary.

3. Undo table space: Roll back can be done when required.

4. Temp table space: Can handle more space.

Parsing:

1.SQL Parsing:

StatementSyntax checkSymanteccheck (object)

2.Soft Parsing:

Schematic check

3.Hard Parsing:

Check query optimization.

Keys:

1) Primary Keys: All tables have unique keys called Primary keys which do
not allow null values.
2) Unique Keys: These keys are unique but these keys allow null values.
3) Not null keys:

List of Topics Oracle


1. Joins

ORACLE
Joins: Joins are used to combine two are more tables.

Inner joins: Returns all rows when there is at least one match in BOTH
tables.

Page | 32
Outer joins: Return all rows from the left table, and the matched rows from
the right table.
left join: Return all rows from the right table, and the matched rows from
the left table.
right join: Return all rows when there is a match in ONE of the tables.

List of Topics
Materialized view, indexes
(oracle)

Materialized view:
Snapshot logs create procedure for refresh.
Constraints : constraints are used to restrict the data.
Indexes : To improve the performance.
Objects : objects are 3 types
User objects: We used in user schema.
DBA Objects: We can get all objects ,if we have access are not.
All Objects : we can get all objects , if we have access.

Topic Oracle
1.Tables
2.sequences
3.views
4.Index

1. Tables:

Tables are data base objects that stored the data.

Page | 33
Tables are data base objects that store the information in a form of rows and
columns.

Rows are also called as record.

Columns are also called as field.

Tables are schema object that are stores in a data Dictionary.

2. Sequences:

Sequence is an oracle schema object that facilitates auto numbering.

A Sequence is used to generate integers sequentially.

Oracle pseudo columns help to access sequences values.

By Default, sequence increment by 1, minimum value for a sequence 1.

Cycle: Specifies whether the sequence continues to generate value after


reaching its maximum or minimum value.

No Cycle: Specifies whether the sequence cannot generate more values


after reaching its maximum or minimum value.

3. Views:

View is nothing but an imaginary one means which is not real.

View is another way that can store the query for us.

Apart from saving our query view can also be used to secure the data.

Types of views:

Simple view:

Simple view is one which is created on basis on simple table.

We can do DML operations through the view.

Simple view does not contain any function or groups of data.

Complex view:

Complex view is one which is created by using more than one table.

Page | 34
Complex view does contain any function or groups of data.

We can restrict DML operations through the complex view.

Force\No Force:

If we create a view on a table which is not available in data base then it is


called view created with a force.

If we create a view on a table which is available in data base then it is called


view created with a no force.

Drop view:

To remove a view definition from database we use drop command.

4. Index:

Indexes are optional structures associated with tables and clusters that allow
SQL statements to execute more quickly against a table.

Oracle Database provides several indexing schemes that provide


performance functionality.

There are

B-tree: Default and common.

Bitmap:

Bit map index will create separate index for each unique type of column
work best for columns with a small set of values.

When dealing with bit map index, RDBMS will actually matrix algebra to find
rows that to be locked.

Simple-index column:

Simple-index column is one that is created based on the one table column.

Composite index column:

Composite -index column is one that is created based on the one or more
than one table column.

Impact indexes:

Page | 35
Impact indexes are the indexes that are automatically created by oracle
database when an object is created.

Indexes are automatically created by the primary key constraint and unique
key constraint.

List of Topics Oracle


1. Constraints
2. joins

Constraints and joins :-

NOT NULL : - Indicates that a column cannot store NULL value.

UNIQUE :- Ensures that each row for a column must have a unique value.

PRIMARY KEY :- A combination of a NOT NULL and UNIQUE. Ensures that a


column (or combination of two or more columns) have a unique identity
which helps to find a particular record in a table more easily and quickly.

FOREIGN KEY :- Ensure the referential integrity of the data in one table to
match values in another table.

CHECK :- Ensures that the value in a column meets a specific condition.

DEFAULT :- Specifies a default value for a column.

Joins :-

INNER JOIN: Returns all rows when there is at least one match in BOTH
tables.

LEFT JOIN: Return all rows from the left table, and the matched rows from the
right table.

RIGHT JOIN: Return all rows from the right table, and the matched rows from
the left table.

FULL JOIN: Return all rows when there is a match in ONE of the tables.

SELF JOIN: The SQL SELF JOIN is used to join a table to itself as if the table
were two tables, temporarily renaming at least one table in the SQL
statement.

Page | 36
Oracle: Data Base Objects

Table

Views

Index

Constraints

Procedures

Functions

Packages

Materialized Views

Refresh Options in Materialized Views:

On Demand & On Commit.

User_ Objects: All objects of current schemas in which user is working.

All_ Objects: All accessible objects objects of all schemas.

DBA_ Objects: All objects of database.

User_ sorts: All procedures and functions are stored in it.

Index, constraints & triggers will drop if the table will drop. & View will
get invalid but not dropped.

Page | 37
select * from recycle_ bin to get dropped table info then it can be
restore again.

but purged table can not be retrieved again.

In procedure grant execute for other schemas like grant select, insert
for table.

Grant should be given from user itself. But synonyms should be given
which is created in that other user.

Create or replace for procedures, functions & triggers are there so that
without dropping the query it can be updated without revoking the
permission for other users. [which have grant permission on those
objects.]

We drop a materialized view there is a prevailed option for saving the


data. so that saved data can be used in another materialized view
created on that same table which have now more data than previous
time.

User_ Dependency: Check all dependents objects

Which user is using which objects. Like if same procedure named as P1


used by USER 1 and that same procedure named as P2 by USER 2,
both can use that procedure but in the list it will be shown as Un
compiled.

Data Base Objects

List of Topics

Page | 38
INDEX: Types of indexes are:

B-TREE: By default, the Oracle creates a b_ tree index. In a b-tree, you walk the
branches until you get to the node that has the data you want to use. In the classic
b-tree structure, there are branches from the top that lead to leaf nodes that
contain the data. If I wanted to find the row - id for the number 28 in the b-tree, I
would start at the top or header block.

BITMAP: Oracle bitmap indexes are very different from standard b-tree indexes. In
bitmap structures, a two-dimensional array is created with one column for every row
in the table being indexed. Each column represents a distinct value within the
bitmapped index. This two-dimensional array represents each value within the index
multiplied by the number of rows in the table.

At row retrieval time, Oracle decompresses the bitmap into the RAM data buffers so
it can be rapidly scanned for matching values. These matching values are delivered
to Oracle in the form of a Row-ID list, and these Row-ID values may directly access
the required information.

FUNCTION BASED: Rather than indexing a column, you index the function on that
column, storing the product of the function, not the original column data. When a
query is passed to the server that could benefit from that index, the query is
rewritten to allow the index to be used.

VIEW: Types of views are:

Simple View

Complex View

Materialized View: A materialized view is a database object that contains the


results of a query. For example, it may be a local copy of data located remotely, or
may be a subset of the rows and/or columns of a table or join result, or may be a
summary using an aggregate function.

Sequence: Like : Increment By 1

Cycle

Maximum Value

Minimum Value

Page | 39
Current _ Value

Next _ Value

Synonyms: A synonym is an alias or alternate name for a table, view, sequence, or


other schema object. They are used mainly to make it easy for users to access
database objects owned by other users.

Database Triggers: Before DML

After DML

For Each Row

For Each Statement

Partitioning: Partitioning allows a table, index, or index-organized table to be


subdivided into smaller pieces, where each piece of such a database object is called
a partition. Each partition has its own name, and may optionally have its own
storage characteristics.

Types Of Partitioning are:

Range Partitioning: Range partitioning maps data to partitions based on ranges of


values of the partitioning key that you establish for each partition.

It is the most common type of partitioning and is often used with dates.

For a table with a date column as the partitioning key, the January-2005 partition
would contain rows with partitioning key values from 01-Jan-2005 to 31-Jan-2005.

List Partitioning: List partitioning enables you to explicitly control how rows map
to partitions by specifying a list of discrete values for the partitioning key in the
description for each partition.

The advantage of list partitioning is that you can group and organize unordered and
unrelated sets of data in a natural way.

Page | 40
For a table with a region column as the partitioning key, the North America partition
might contain values Canada, USA, and Mexico.

Hash Partitioning: Hash partitioning maps data to partitions based on a hashing


algorithm that Oracle applies to the partitioning key that you identify. The hashing
algorithm evenly distributes rows among partitions, giving partitions approximately
the same size.

SQL Constraints:

Constraints are nothing but restriction on data.

If there are any violation between constraint and data, the action is
aborted by the constraint.

We can specify constraints at the time of table creation and after


creating table also with alter command.

The constraints are 2 types.

1) Column level 2) Table level

1) Column level:

Column level constraints refers to a single column in the table.

Syntax:

CREATE TABLE [schema_name] tablename (Column_namedatatype [DEFAULT expr],


Column_name [CONSTRAINT Cons_Name] Constraint_type);

2) Table level:

Table Level constraints refers to one or more columns in the table.

They specify the column names to which they apply.d

Syntax:

Page | 41
CREATE TABLE [schema_name] table_name (Column_namedatatype [DEFAULT
expr],Column_name [CONSTRAINT Cons_Name] Constraint_type(column_name));

The main used constraints are

1) Not Null:

In not null the field cant be blank or field is mandatory.

While creating table we have to mention the constraint with column


name.

Ex: create table emp(eid number(5) Not null,ename varchar2(20));

In the above query for eid we mentioned not null with column. Which means that
eidshoud contain a value. Which cant be a null value.

2) Unique:

Unique key ensures that no two values are the same in the table.

It allows NULL values.

They can be defined either at column / table level.

We can define a composite unique key on the columns.

An index is automatically created on a Unique constraint.

Oracle does not allow Primary & Unique key to be defined on the same
column.

Syntax:

CREATE TABLE Patient(ptno Number(5), drname VARCHAR2(20) UNIQUE, gender


CHAR(1),

qual VARCHAR2(10));

In the above query drname is declared with unique constraint which


means that field notallows duplicate values.

We can also add the UNIQUE constraint through ALTER command.

Example:

Page | 42
SQL> ALTER TABLE Product ADD CONSTRAINT

cons_pname UNIQUE (pname);

3) Check Constraints:

Check constraint allows to specify a condition that every row in the


table must satisfy.

It ensures that all the values entered by the user for that column
satisfy the certain conditions.

It is based on the Boolean condition TRUE or FALSE.

They can be defined either at column / table level.

We cannot call or use functions like SYSDATE, USER, UID inside the
check condition.

References to Pseudo columns like ROWNUM, CURRVAL, NEXTVAL are


not allowed.

Ex: create table emp(eid number(3),ename varchar2(20),gender varchar2(2),add


varchar2(20), check(gender in(M,F));

In the above ex we add check constraint for gender column. Which means user can
enter either M or F only.

We can also add the Check constraint through Alter command

Ex: ALTER TABLE emp ADD CONSTRAINT CHECK(gender in(M,F));

4) Default:

The DEFAULT constraint is used to insert a default value into a column.

The default value will be added to all new records, if no other value is
specified.

Ex:

CREATE TABLE Persons(PId number NOT NULL, LastName varchar2(25) NOT NULL,
FirstName varchar2(20),Address varchar2(20),City varchar2(20) DEFAULT
'Sandnes');

Table level constraints:

Table Level constraints refers to one or more columns in the table.

Page | 43
They specify the column names to which they applied.

Syntax:

CREATE TABLE [schema_name] table_name(Column_namedatatype [DEFAULT


expr],Column_name [CONSTRAINT Cons_Name]
Constraint_type(column_name));

1) Primary Key:

Primary key is used to identify a record in an unique manner. In other


words no two records can have the same values in all the columns.

It does not allow NULL values.

A table can have only one Primary Key.

Primary Key constraint can be defined either at the column level or


table level.

A Primary Key can be defined on a single or multiple columns of a


table.

A Primary Key with multiple columns is called Composite Key.

To create a Primary Key on the column order_number for the table Orders

At column level

SQL> CREATE TABLE Orders(order_number NUMBER(5) PRIMARY KEY,cust_number


VARCHAR2(10),order_dateDATE,bill_amt NUMBER(6));

At table level

SQL> CREATE TABLE Orders(order_number NUMBER(5),cust_number


VARCHAR2(10), order_dateDATE,bill_amt NUMBER(6),PRIMARY
KEY(order_number) );

2) Foreign Key:

A foreign key creates a relationship between two tables .

They enforce what is called as Referential integrity.

Page | 44
The tables in the relationship are child table and parent table.

A column is a foreign key in a table if it is a primary key in another


table.

The table containing the primary key then becomes the Parent table
(Master table).

The table that contains the foreign key becomes the Child table.

The foreign key can values could be one of the values that are in
primary key or null.

A table can have multiple foreign keys.

It goes without saying that the Primary key constraint defined on the
table must already exist before to create a foreign key.

Syntax:

CREATE TABLE parenttablename( [field declarations], FOREIGN KEY (field name)


REFERENCES childtablename);

And

By using Alter

ALTER TABLE table_name ADD [CONSTRAINT Cons_Name] FOREIGN KEY

(Column_name) REFERENCES parent_table;

Specify the child table name with the column names and its datatype.

Specify FOREIGN KEY to ensure that it establishes a relationship


between the Parent table. Parent table must be created before.

REFERENCES clause is used to refer to the column in which parent


table is referenced.

Ex:

Foreign Key for Items table

At table level:

CREATE TABLE Items(order_number NUMBER(5), pid NUMBER(4), quantity


NUMBER(4), unit_cost NUMBER(7,2), PRIMARY KEY (order_number, pid ),

Page | 45
FOREIGN KEY(order_number) REFERENCES Orders(Order_number),

FOREIGN KEY (pid) REFERENCES Product(pid) );

At column level:

CREATE TABLE Items(order_number NUMBER(5) REFERENCES


Orders(Order_number),pid NUMBER(4) REFERENCES Product(pid), quantity
NUMBER(4), unit_cost NUMBER(7,2), PRIMARY KEY (order_number, pid ));

3) Composite Constraint:

Composite key can be created only at the table level.

To create a composite primary key for the order_number and pid.

SQL> CREATE TABLE Items(order_number NUMBER(5),pid NUMBER(4), quantity


NUMBER(4), unit_cost NUMBER(7,2), PRIMARY KEY (order_number, pid ) );

Oracle:

Coding Standards in PL/SQl:

These PL/SQL coding standards were written to allow for consistency in PL/SQL code
written by various developers while allowing for some individual styles and
preferences to be expressed. The central purpose of any coding standard for SQL
and PL/SQL must deal with database performance, clarity of code, and
maintainability of code. This standard should be considered a guideline for
developing easily maintainable SQL and PL/SQL applications in a high-performance
Oracle database.

PL/SQL Naming Conventions:

Using a set of naming conventions for PL/SQL objects tends to create more
meaningful identifiers. This section of the standard will come into play most often
when creating identifiers (variables and constants) inside blocks of code.

It is common to utilize abbreviations to shorten identifiers. When doing so, the


abbreviations should be meaningful and used consistently (e.g., do not use both
ADDR and ADRS as an abbreviation for ADDRESS).

Page | 46
-Packages: Whenever create a file stored in two Packages. Its stored in database.

(1) Package specification

(2) Package body.

-Cursors

-Procedure

-Function

-Exception.

SQL - Functions :

Oracle Built in Functions :There are two types of functions in Oracle.

1) Single Row Functions: It returns a value for every row that is processed in a
query.Numeric Functions:

CEIL (x) Integer value that is Greater than or


equal to the number 'x'
FLOOR (x) Integer value that is Less than or equal
to the number 'x'
TRUNC (x, y) Truncates value of number 'x' up to 'y'
decimal places
ROUND (x, y) Rounded off value of the number 'x' up
to the number 'y' decimal places

Character Functions :
Case Manipulation Functions:
Lower, upper, Initcap

Ex: select lower('GOD') from dual;

Page | 47
god

Ex: select upper('God') from dual;

GOD

Ex: select initcap('GOD') from dual;

God

Character Manipulation Functions:


Ltrim, Rtrim, Lpad, Rpad, Trim, Substr ,Instr, length.

Date Functions:

Add_Months('XX-XXX-XXXX',n): Returns a date value after adding no of months.

Ex: select add_months(sysdate,6) from dual;

31-JUN-2017

Next_day('XX-XXX-XXXX') : Returns the next date of the week.

Months_between('XX-XXX-XXXX','XX-XXX-XXXX') : It will returns the no of months


between 2 dates.

Last_day('XX-XXX-XXXX') : Returns the last day of that month date

Page | 48
Conversion Functions:
To_char :Converts Numeric and Date values to a character string value.
To_number: Converts a character string value to Numeric values .
To_date: Converts a valid Numeric and Character values to a Date value

2) Group Functions: These functions group the data based on the values returned
by the query. The group functions are used to calculate aggregate values like total
or average, which return just one total or one average value after processing a
group of rows.

Aggregate functions:
Also Known as Multi value function or multi row function.
1. SUM: we can add the value of entire column
2. Max : we can get max value of column
3. Min: we can get min value of column
4. AVG: we can get average value of column
5. COUNT: In this null values are not countable.

Options in Aggregate functions:


1. Group BY: It is used to grouping of data and apply aggregate functions on
grouped data.
Ex: select dept,sum(salary) from emp1 group by dept;
Ex: select dept,count(*) from emp1 group by dept;
2. Roll up: It is used to generate subtotal and grand total of the grouped data.
Ex: select dept,sum(salary) from emp1 group by rollup(dept);
3. Having :It is used to filter grouped data as where clause is used to filter normal
tables data.

Ex : select dept , max(salary) from emp1 group by dept having count(id) >1;

Page | 49
UNIX

Page | 50
List of Topics 1. Introduction to unix
2. Unix command structure
3. File and directory related
commands
4. Shell Meta characteristics
5. Building block Primitives

Unix:

Unix is a very popular multi-user, multitasking, time-sharing operating


system.

It is portable(run on any machine) basically written in c language.

Security:

Without the proper username and password, it is not possible to work on


Unix.

Access permissions are given to prevent unauthorized access of files.

Background tasks:

Multiple tasks can be run simultaneously.

Pipes:

Work with multiple commands at the same time.

File system:

The file system is in the form of Tree structure. Mainly based on root.

The root can split into many partitions but root file is mandatory.

Page | 51
UNIX has multiple file systems

A file system

is a formatted partition of the disk.


Is a group of files having relevant information.

Boot block:

Occupies the beginning of the root file system.

Super block:

Has the state of the file system-its size, where to find the free space on the
file system, how many files it can store etc.

Inode block:

It follows the super block-Gives the internal representation of the file.

Data Block:

Contains data.(Size of blocks can vary from 512 bytes to 4K)

Hierarchy:

/ (root)

usr

bin dev etc temp


lib

sh ls
shadow

tty lp password

Non leaf nodes:

Page | 52
Here bin, dev, etc are the non leaf nodes because these contain other
dictionaries.

Leaf nodes:

Here sh, ls, tty, lp are leaf nodes because they do not have any other
directories.

File access permissions can be set for 3 classes of users:


1.File Owner
2. File Owners Group
3. Others

The Absolute Path:


1.The entire pathname starting from root(/).
Example: /home/training/priya

The Relative Path:


1.The path relative to your present working directory.
Example: training/priya

.. : Represents the Parent Directory.


. : Represents the Present Working Directory.

Unix Command Structure:

[options] [arguments]
Specific commands are the options file1 and file2 are the
arguments

2 types of commands:

Internal command External command


1.Shell built in command not stored. 1. Stored as files having an
independent existence.

2.Without any process these are


2.Process will be created for
executed.
execution.
Ex: cd, echo
Ex: cat, ls

Page | 53
Shell Scripts:
The shell executes these scripts by spawning another shell. The child shell
becomes the parent of the commands that feature in the script. The child
shell executes the commands in the script.

Commands/Utilities:

Clear command:

Clear the terminal screen.

$ clear

date command:

1. To print system date and time in default format.

$ date

2. To print only system time

$ date +%T

3. To print only system date

$ date +%D

4. To print only year value

$ date +%Y

5. To print only month name

$ date +%B

Note: Nearly every lowercase and uppercase alphabet is having some format
meaning with date command. To find out all the options, use man command.

Page | 54
cal command:

1. To display the calendar for current month

$ cal

2. To display the calendar for Jan month(month value 01) for 2002 year

$ cal 01 2002

3. To display the complete calendar of year 2009

$ cal 2009

who command:

1. To display the details of all the users who are currently logged in

$ who

2. To display the details of your self

$ who am i

type command:

1. To check whether clear command is internal or external

$ type clear

It will display one path in output, means it is stored as a file, so clear is


external command.

2. To check whether alias command is internal or external

$ type alias

It will display the message alias is a shell built-in, so alias is internal


command.

alias command:

Page | 55
1. To create alias name of an existing command

$ alias d=date

Now this d will work as date command.

2. To see the list of all alias names

$ alias

cat command:

Example 1: If file1 is not present in current directory:

$ cat > file1

Ctrl+d

1. cat command will create an empty file with name file1 in current
directory

2. Now user can give some data as input on terminal screen

3. As soon as user will press ctrl+d, all the data entered by the user on
the terminal will be saved in the file

Example 2: If file1 is already present in current directory:

$ cat > file1

Page | 56
.

Ctrl+d

1. All the data entered on the screen will be saved in this existing file.

2. If file1 is already having some data, new data given by user will
overwrite the previous data.

Example 3: Display the content of file1

$ cat file1

1. Complete file1 data will be printed on the screen

Example 4: Display the content of two or more files

$ cat file1 file2

1. file1 data followed by file2 data will be printed on the screen as shown
below:

$ cat file1

first line in file1

second line in file1

$ cat file2

first line in file2

second line in file2

$ cat file1 file2

first line in file1

second line in file1

first line in file2

second line in file2

Example 5: to append some data in file1

Page | 57
$ cat >> file1

Ctrl+d

1. All the data entered on the screen will be saved in this existing file.

2. If file1 is already having some data, new data given by user will be
appended with the previous data.

mkdir command:

$ mkdir d1

It will create a directory d1 in current directory

$ mkdir path/d1

It will create a directory d1 in the mentioned path

$ mkdir p d1/d2/d3

-p means parent

mkdir command with option p is used to create complete hierarchy in one


go.

cd command:

$ cd dir1

This will change current directory to dir1 if dir1 is present in current directory

$ cd path/dir1

Page | 58
This will change current directory to dir1 if dir1 is present in the mentioned
path

$ cd OR $ cd ~

Changes to the home directory

$ cd /

Changes to the root directory (i.e. />)

$ cd ..

Changes to the Parent director

List of Topics 1. Text processing commands


2. Process Related commands
3. MemoryRelated commands
4. Compression Utilities

Text processing commands:


Paste:
Combines the content of the files line by line. Prints the files content
horizontally.
Syntax: $ paste file1 [file2]

head:
Display the first count lines of file. If count is not specified, then first ten
lines are printed by default. If no files are specified, head asks for the input
from the standard input.

Syntax: $ head [-n] file_name

tail:
Display the last count lines of a file. If count is not specified, then last ten
lines are printed by default. If no files are specified, tail asks for the input
from the standard input.

Page | 59
Syntax: $ tail [n/+n] file_name

wc:
Displays total no of lines, words and characters in any data.
Syntax: $ wc [lwc] file_name

tr:
Translate characters. Used on output of some other command.
Syntax: $ cmd_output | tr [option] src_charset tar_charset

Cut:
Retrieves specific fields or characters from the data. Used on output of some
other command or file content.

Syntax: $ cmd_output | cut [option]

$ cut [option] file

Sort:
Used to order the data. Used on output of some other command or file
content. Default sorting is as per the English dictionary.
Syntax: $ cmd_output | sort [option]
$ sort [option] file

grep:
Used for pattern search in the given data. Global Regular Expression Parser.
Syntax: $ grep [option] pattern data
Prints lines starting with any pattern : $ grep ^pattern file_name
Prints lines ending with any pattern : $ grep pattern$ file_name

Uniq:

Page | 60
Removes adjacent repeated lines in the given data.
Syntax: $ uniq [option] data

Cmp:
Compares two files and give the first difference that encounters.
Syntax: $ cmp file1 file2

Comm:
Compares two files and the result will be given in 3 columns.
1st column: uniq dada from file1.
2nd column: uniq dada from file2.
3rd column: uniq dada from both the files.

diff:
Used to get all the difference in between the two files.
Syntax: $ diff file1 file2

Process Related Command:


A process is a program in execution. Each process is allocated a process identifier or
PID. In general, each process is started by another, known as parent process. So
every process is also have one parent process identifier or PPID

Ps:
Displays the list of processes submitted to kernel
Syntax: $ ps
$ ps f :Full Listing showing PPID
$ ps e :Including user and system processes

bg:
Used to see the status in the background.

Page | 61
Syntax: $bg

Fg:
Used to bring any background job in foreground.
Syntax: $ fg %JobID OR fg #PID

nice:
Execute a command with updated scheduling priority.
Syntax: $ nice [option] [command]

nohup:
Executes the command in background even after log out from the session.
Syntax: $ nohup command

kill:
Used to send a signal to a particular process.
Syntax: $ kill [signal_info] PID
$ kill [signal_info] %JobID

Memory Related Command:

df:
Prints file system disk space usage.
Syntax: $ df [FILE]

du:
Estimates file space use.
Syntax: $ du [FILE]

Page | 62
Compression Utilities:
Used to compress the files and directories.

gzip:
Utility for compression and decompression of files. Compressed files have
.gz extension.
Syntax: $ gzip file1 [file2]
$ gzip d file1.gz
gunzip:
Utility for decompression of files having extension .gz
Same as gzip d
Syntax: $ gunzip file1.gz

zcat:
Used to view the content of compressed file.
Syntax: $ zcat file1.gz

zmore:
Used to view the content of the compressed file pagewise.
Syntax: $ zmore file1.gz

tar:
Creates a tape archive file. Extracts from archive file.
Syntax: $ tar -cvf file1.tar file1
$ tar -xvf file1.tar

untar:
Used to unzip the files or untar.

Page | 63
List of Topics 1. Communication commands
2. File Transfer commands
3. Telnet
4. Unix Security
5. Changing Passwords
6. File security
7. File Permissions

Communication commands:
Write:
Writes a message to another user who is logged in. Can be used by any
user.
Syntax: $ write user_id

mesg:
Changes permission for receiving messages. Gives permission status.

Syntax: $ mesg

$ mesg y[or n]

wall:
Writes a message to all users who are currently logged in.
Syntax: $ wall [g group] message

File Transfer Commands:

put:
Used to transfer a file from the source terminal to the destination terminal.
Syntax: $ put filename

Page | 64
get:
Used to transfer a file from destination terminal to source terminal.
Syntax: $ get filename

mput:
Used to transfer multiple files from the source terminal to the destination
terminal.
Syntax: $ mput file1 [file2]

mget:
Used to transfer multiple files from destination terminal to source terminal.
Syntax: $ mget file1 [file2]

bye:
Used to close the FTP session.
Syntax: $ bye

close:
Also used to close the FTP session. System will give Good Bye message
then type bye.
Syntax: $ close

help:
This command displays the list of FTP commands that can be used by the
user. User can also type ? symbol for the same.
Syntax: $ help

$?

Page | 65
![Command]:
Used to execute some commands in local machine. Shifts the control from
ftp prompt to local machine.
Syntax: $ ![Command [arg]]

Telnet:
Used for connecting to UNIX .
telnet [hostname]

File Security:
Classes of users for a file.
Owner
Group
Others
Classes of Permissions for a file.
Read (r)
Write (w)
Execute (x)

File Permissions:

Two modes of setting file permissions


1. Absolute Mode (Octal Integer)
2. Symbolic Mode (String)

List 1. vi editor & its important features


2. Introduction to Shell
Programming
3. Types of shell
4. Shell variables

Page | 66
1.vi editor & its important features:
Features:
Omnipresent: vi Editor works on different UNIX flavors.
Fast: In vi editor, Editing and various operations are very fast.
Powerful UNDO features: In vi Editor, text in lines could be undone with very
less effort.
Limitations:
Less User-friendly: As vi Editor does not have a graphical user interface,
hence the user needs to have a knowledge of the commands before the user
works on the editor.
Highly case-sensitive: vi Editor is highly case-sensitive. i.e. a letter in small
case would has a different meaning in comparison with the same letter in
upper case.
E.g. a appends the data after the current character, whereas A appends
the data after the current line.
Keystrokes: As vi Editor operates in various modes, a letter could have
different meaning in different modes.
E.g. In command mode, a stands for append operation, whereas in insert
mode, a stands for data.
vi operating mode:

start

Command mode
I,I,o,O,a,A Insert mode

esc

enter

Escape mode
end

Page | 67
:q

Whenever a particular file is opened using the vi editor, it opens up in the


Command mode. In this mode, the keyboard-character represents command
and not data. A user cannot enter the data in the Command mode. The user
has to switch over to the insert mode to enter the data. This could be done
using the letters like a, i, etc. Once the user is in insert mode, the data
could be entered. The user could switch back to the Command mode. For
saving or exiting the application the user has to get into the Escape mode by
pressing Esc key.

vi editor commands:
These commands are used to move, change, replace or manipulate a file.

Introduction to Shell Programming:

Shell allows three types of commands:


1. An internal command
2. An executable file that contains a sequence of shell command lines
3. An executable file that contains object code produced by compilation

Features:
1. Interactive and background processing
2. Input/output redirection
3. Pipes
4. Wild card matching
5. Programmable
1. Shell Variables
2. Programming language constructs
3. Shell Scripts

Day 15 Tuesday,
November 29, 2016

Page | 68
List of Topics 1. Positional Parameters
2. Special Parameters
3. Selectional Constructs
4. Iterational Constructs

1.Positional Parameters:
A command in UNIX is interpreted by the shell. When a command is entered and
<Enter> key is pressed, the shell puts each word on the command line into special
variables as follows
1. The command name is put into the variable called $0
2. The first argument is put into the variable called $1
3. The second argument is put into the variable called $2 and so on.
The UNIX shell creates variable up to $9
These variables are also called positional parameters of the command line.
set file1 file2 file3
$0 bash, $1- file1, $2 file2, $3 file3

2.Special Parameters:
Besides the variables $0 to $9, the shell also assigns values to the following
variables, called Special Parameters
$$ PID number of current shell
$# contains the number of Command Line Arguments
$0 Command Name
$* contains the entire string of arguments
$? Exit Status of the last executed command
$! PID number of the last background command
$@ Same as $* but fetches each argument separately when enclosed in double
quotes

3. Selectional Constructs:
-if
-case

Page | 69
4.Iterational Constructs:

-for

-while

-until

Page | 70

Você também pode gostar