Ip Notes XI
Ip Notes XI
Ip Notes XI
(INFORMATICS
PRACTICES)
Class – XI
2016 - 17
PREPARED BY
SACHIN KALRA
D.A.V PUBLIC SCHOOL
SAHARANPUR
CONTENTS
01 Hardware Concepts
04 Programming Fundamentals
05 Control Structures
07 Programming Guidelines
9 MySQL
10 Function in MySQL
11 IT Applications
Computer system includes software and hardware together to make it perform the required tasks. Software is a
collection of instructions and related data that tells a computer what to do and how to do.
Computer Hardware is a collection of electronic and other peripheral units, which enables software to perform
desired operations. And, there is important software, known as Operating system (OS) specially designed to
establish the communication between various hardware devices and software loaded on a computer system.
A computer system is broadly divided into three units – Input Unit, Central Processing Unit (CPU) and Output
Unit. Input unit helps the user to enter raw data and instructions into the computer system, central processing unit
performs the required operations as per given instructions and at the end output unit produces meaningful results in
the desired format for the user.
Every task given to a computer follows an Input- Process- Output Cycle (IPO cycle). Thus the basic structure of the
computer is:-
• Input Unit: The input unit consists of input devices that are attached to the computer system. These
devices take input and convert it into binary language that the computer understands. Some of the
common input devices are keyboard, mouse, joystick, scanner etc.
• Central Processing Unit (CPU) : The CPU is called the brain of the
computer because it is the control centre of the computer. As the CPU is
located on a small chip, it is also called the microprocessor. CPU executes
the required computation and then either stores the output or displays on the
output device. The CPU has three main components which are responsible
for different functions – Arithmetic Logic Unit (ALU) , Control Unit (CU) and
Memory registers. 1
• Arithmetic Logic Unit (ALU): This unit is responsible for performing various Arithmetic (+,-,/,*)
, relational (=,<=,>= ,>,<) and logical operation.
• Control Unit : This unit is responsible for the sequence of operations. It interprets the instructions of
a program in storage unit and produces signals to execute the instructions. It also controls the flow of
data and instructions in the computer system.
• Memory Unit: Memory attached to the CPU is used for storage of data and instructions and is called
internal memory. During processing, it is the internal memory that holds the data. The internal memory is
also called the Primary memory or Main memory. A computer memory can be thought of as ‘cell’. A
memory cell may be defined as a device which can store a symbol selected form a set of symbols.
Since main memory is volatile (temporary), secondary memory space is needed to store data and
information permanently for later use. Some of the common secondary storeage device are Hard Disk,
Magnetic Tape Drive, CR-RW, DVD, Flash Drive and Floppy Diskette etc.
• Output Unit: Output unit consists of output devices. These are used to display results on video display
or are used to print the result (hard copy). These can also be used to store the result for further use.
Common output devices are Monitor (VDU), Speaker, Printer and Plotter.
-----------------------------------------------------------------------------------------------------------------------------------------
INPUT DEVICES
Input devices are used to enter data and instructions into the computer. An input device converts our
information or data in to a form which can be understood by the computer. A good input device should
provide timely, accurate and useful data to the main memory of the computer for processing. Some of the
common input device are:
• Keyboard : Keyboard is a primary input device. This is the most common input device which uses an
arrangement of buttons or keys. In a keyboard each press of a key typically corresponds to a single
written symbol. In normal usage, the keyboard is used to type text and numbers while in a modern
computer, the interpretation of key press is generally left to the software.
A computer keyboard distinguishes each physical key from every other and reports the key-presses to
the controlling software. Keyboards are also used for computer gaming, either with regular keyboards
or by using keyboards with special gaming features. Keyboard consists following parts :
Nevagation and Cursor Movement keys : Arrow keys, and set of special keys as Insert, Home, Page
Up, Page Down, Delete, End and Home key.
2
Special Keys : There are several other non-printable keys for various different purposes. These
include caps lock, tab, ctrl, pause, delete, backspace, spacebar, shift, enter etc which are used for
special purposes.
• Mouse: A mouse is a pointing device that functions by detecting two-dimensional motion relative to
its supporting surface. The mouse's motion typically translates into the motion of a cursor on a
display, which allows for fine control of a Graphical User Interface.
a) Mechanical Mouse
b) Opto-Mechanical Mouse
c) Optical Mouse
d) Wireless Mouse
• Light Pen: A light pen, also called a selector pen, is a computer input
device in the form of a light- sensitive wand used in conjunction with a
computer's CRT display. It allows the user to point to displayed objects or
draw on the screen in a similar way to a touchscreen but with greater
positional accuracy
• Optical Character Recognition (OCR): - Optical character recognition, usually abbreviated to OCR,
is the mechanical or electronic conversion of scanned images of handwritten, typewritten or printed
text into machine-encoded text. It is widely used as a form of data entry from some sort of original
paper data source, whether documents, sales receipts, mail, or any number of printed records
• Smart Card Reader: A smart card, chip card, or integrated circuit card
(ICC) is any pocket-sized card with embedded integrated circuits. It is a
common method of digitizing printed texts so that they can be
electronically searched, stored more compactly, displayed on-line, and
used in machine processes such as machine translation
to the scanner's output port.There are five basic kinds of barcode readers --
pen wands, slot scanners, Charge-Couple Device ( CCD ) scanners, image
scanners, and laser scanners.
• Web Camera:- A webcam is a video camera that feeds its images in real time
to a computer or computer network, often via USB, ethernet, or Wi-Fi. Their
most popular use is the establishment of video links, permitting computers to
act as videophones or videoconference stations. The common use as a video
camera for the World Wide Web gave the webcam its name.
……………………………………………………………………………………………………………………..
OUTPUT DEVICES
• Terminals: It is a very popular interactive input-output unit. It can be divided into two types: hard copy
terminals and soft copy terminals. A hard copy terminal provides a printout on paper whereas soft
copy terminals provide visual copy on monitor. A terminal when connected to a CPU sends
instructions directly to the computer. Terminals are also classified as dumb terminals or intelligent
terminals depending upon the work situation.
• Printers: These are used to produce hard copy of output as text or graphics. Network printers have
built-in network interfaces can serve any user on the network. Individual printers are often designed
to support both local and network connected users at the same time. Some printers can print
documents stored on memory cards or from digital cameras and scanners. Multifunction printers
(MFPs) include a scanner and can copy paper documents or send a fax; these are also called multi-
function devices (MFD), or all-in-one (AIO) printers. Most MFPs include printing, scanning, and
copying among their many features.
Depending on their speed and approach of printing, printers are classified as impact and non-impact
printers.
Impact printers: Use the typewriter approach of hammering a typeface against the paper and inked
ribbon. Ex. Dot-matrix printers, Daisy Wheel Printer, Drum Printer.
Non-impact printers: Do not hit or impact a ribbon to print. They use electro -static chemicals and
ink-jet technologies. Laser printers and Ink-jet printers are of this type. This type of printers can
produce color printing and elaborate graphics.
Ink-jet (bubble-jets) printers: Ink-jets(bubble-jets) printers spray ionized tiny drops of ink onto a
page to create an image. This is achieved by using magnetized plates which direct the ink's path onto
the paper in the desired pattern. Almost all ink-jets offer a color option as standard, in varying degrees
of resolution.
4
Laser Printers: Laser printers operate by shining a laser beam to produce an image on a drum. The
drum is then rolled through a pool, or reservoir, or toner, and the electrically charged portions of the
drum pick up ink. Finally, using a combination of heat and pressure, the ink on the drum is transferred
onto the page. Laser printers print very fast, and the supply cartridges work a long time. Color laser
printers use the same toner-based printing process as black and white ( B/W) laser printers, except
that they combine four different toner colors.
…………………………………………………………………………………………………………………
SECONDARY STORAGE DEVICE
Alternatively referred as external memory and auxiliary storage, secondary storage is a storage
medium that holds information until it is deleted or overwritten regardless if the computer has power. For
example, a floppy disk drive and hard disk drive are both good examples of secondary storage devices.
Hard Disk: Hard disks are used to record computer data magnetically. A
hard disk drive consists of a stack of inflexible magnetic disks mounted on a
motor. As the disks spin at high speeds, read/write heads at the end of a
metal fork swing in and out to access sectors of the disks.
To read the data, an infrared laser is beamed through the CD's polycarbonate
substrate. The wavelength of light that bounces off the mirror-like reflective backing
is then measured. A pit scatters the light and the ridge reflects the light. Since pits
and ridges pass different amounts of light, and translated back into the original ones
and zeros.
DVD: It stands for Digital Versatile Disk or Digital Video Disk. DVDs consist of two
halfthickness (0.6-mm) back to back CDs. Delicate reflective coating protects it. A
DVD holds 4.7 GB to 17 GB of data. Like CDs DVDs also come in three varieties –
• DVD- ROM
• DVD- R
• DVD-RW
Blue Ray Disk: This is the latest optical storage media to store high definition audio
and video. It can store up to 27 GB of data on a single layer disk and up to 54 GB of
data on a dual layer disk. The blue ray disk uses a blue laser to read/write data on a
disk. wavelength of the blue ray is shorter, more data per unit area can be stored on
the disk.
6
Memory Concepts:
Memory is one of the most important components of a computer system as it stores
data and instructions. Every memory chip contains thousands of memory locations.
In the computer, the data is stored in the form of bits and bytes. A bit is the smallest
storage unit of memory. A nibble is a collection of 4 bits. Eight bits combined
together to form a single byte, which in turn represents a single character.
Primary Memory
Primary memory or main memory is a Metal Oxide Semiconductor (MOS) memory
used for storing program and data during the execution of the program. It is directly
accessible to CPU.
Information stored in RAM can be accessed in any order, and may be erased or written over.
Information stored in ROM may also be random-access, in that it may be accessed in any order, but the
information recorded on ROM is usually permanent and cannot be erased or written over.
7
What is a Communication Port?
A computer port is a physical docking point using which an extenal device can be connected to
the computer.
A computer port can also be programmatic docking point through which information flows from a
program to computer or over the network/internet.
1. Serial Port : Used for external modems and older computer mouse. It has two versions: 9 pin, 25
pin model. Data travels at 115 kilobits per second.
2. Parallel Port: Used for scanners and printers.Also called printer port (LPT). 25 pin model. Also
known as IEEE 1284-compliant Centronics port.
3. PS/2 Port: Used for old computer keyboard and mouse . Also called mouse port. Most of the old
computers provide two PS/2 port, each for mouse and keyboard. Also known as IEEE 1284-compliant
Centronics port.
4. Universal Serial Bus (or USB) Port : Can connect all kind of external USB devices such as
external hard disk, printer, scanner, mouse, keyboard etc. Introduced in 1997. Most of the computers
provide two USB port as minimum. Data travels at 12 megabits per seconds USB compliant devices
can get power from a USB port
5. VGA Port : Connects monitor to a computer's video card. Has 15 holes. Similar to serial port
connector but serial port connector has pins, it has holes.
6. Power Connector : Three-pronged plug Connects to the computer's power cable that plugs into a
power bar or wall socket.
7. Firewire Port : Transfer large amounts of data at very fast speed. Connects camcorders and video
equipments to the computer Data travels at 400 to 800 megabits per seconds Invented by Apple Three
variants: 4-Pin FireWire 400 connector, 6-Pin FireWire 400 connector and 9-Pin FireWire 800
connector
8
8. Modem: It is a modulation demodulation device that converts analog signals to
digital signals and vice versa. It is used to Connects a PC's modem to the telephone
network.
9. Ethernet Port: Connects to a network and high speed Internet. Connect network cable to a
computer. This port resides on an Eternet Card. Data travels at 10 megabits to 1000 megabits per
seconds depending upon the network bandwidth.
10. Game Port : Connect a PC to a joystick. Now replaced by USB.
11. Digital Video Interface , DVI port : Connect a Flat panel LCD monitors to the computer's high
end video graphic cards. Very popular among video card manufacturers.
--- X ---
9
QUESTIONS AND ANSWERS
1. What are Input devices for PDAs, Smart Phones and Tablet PCs ?
Ans. A Primary Input device for a PDA is a basic stylus. Some PDAs have a built in keyboard or support
voice input. You can attach a full sized portable keyboard to a PDA. Smart phones include PDA
capabilities; onput devices used with PDAs usually are available for smart phones. The Primary
input for a Tablet PC is a digital pen, with which you can write on the device screen.
Set of programs that performs some specifice task is called software. For example : Micorosoft
Word, PageMaker, Typing tutor, Computer Games etc.
A computer program that is permanently stored in a chip (ROM) while manufacturing is called
Firmware. Firmware are stored to define the basic functioning of a computer system. For example:
Program stored in bootstrap loader to initiate booting.
6. Give examples of each system software and application software. Explain the function of each type.
10
9. What are the major strength and weaknesses of a computer?
Ans. Strength : 1. Speed 2. Accuracy 3. Reliability 4. High storage
5. Versatility
Weaknesses : 1. Lack of decision making 2. Zero IQ
10. Why is binary language often termed as machine language ? Why is machine language needed? Ans. A
Computer works on Binary numbers which are in the form of 0’s and 1’s. Thus it needs a language
that uses unique symbols to represent these two states. Therefor a computer works on machine
language. The Binary language if often termed as machine language as it fulfills the condition of
using two unique symbols.
Ans. An OCR (Optical Character Reader) is used to read characters of special type font that are printed on
paper or it is a scanned document. On the other hand an OMR (Optical Mark Reader) is used to
transcribe marks that are marked with a drak pencil or ink on a special preprinted form (answer
sheet of multiple choice question paper where choice of the answer is reflected by shading the
correct box)
13. What are the two categories of printers ? Which type of printer is more speedy
Ans. The printers can be classified in two categories:
1. Impact Printers : In these type of printers, there is a physical connection between the paper and
the print head. They are (i) Line Printer (ii) Dot Matrix Printer (iii) Daisy Wheel Printer
2. Non Impact Printer : In these types, there is no physical connection between the paper and the
print head. The printing takes place with some electromagnetic, thermal, laser techniques. Non
Impact printers are more speedy than Impact printers
14. What is the difference between RAM and ROM?
Ans. RAM stand for Random Access Memory where both read and write operation can take place, but
this is volatile memory; its contents are lost when power is turned off.
ROM stands for Read Only Memory where only read operation can take place. This is a non
volatile memory. Both RAM and ROM are primary memory.
15. What does a Bus mean?
Ans. A Bus is a group of conducting lines that carries data, address and control signals between a CPU
and memory. It is of three types address bus, data bus and control bus.
17. Can you pick the one that offers maximum read speed along with maximum capacity?
Memory sticks ProDuo, SD Card, MMC Plus, and Smart Media Card.
Ans. Out of these Memory stick ProDuo offers maximum read speed along with maximum capacity
--- X ----
11
Chapter-2
SOFTWARE CONCEPTS AND PRODUCTIVITY TOOLS
Software is a general term used for computer programs that control the operations of the
computer. A program is a sequence of instructions that perform a particular task. A set of
programs form software. It is the software which gives hardware its capability. Hardware is of
no use without software and software cannot be used without hardware.
Types of Software
• SYSTEM SOFTWARE:
System Software is the software that controls internal computer operations and performs tasks associated
with controlling and utilizing computer hardware. It can be further classified as:
Operating System
Language Translators (Language Processor)
• OPERATING SYSTEM:
An Operating system is system software which acts as an interface between user and
hardware. . It manages all hardware and software, input, output and processing activities
within the computer system, the flow of information to and from the processor, sets priorities
for handling different tasks, and so on. Without operating system a computer cannot do
anything useful For example: Microsoft Winddows 7, Windows XP, Mac OS, UNIX, Linux,
Andriod Kit Kat etc.
• NEED OF AN OPERATING SYSTEM:
Operating System provides an environment to run applications thus programmer can
design the application without concerning the details of the computer's internal
structure. Operating system is required because of following reasons: -
1. Easy interaction between user and hardware.
2. Starting computer operation automatically when power in turned on.
3. Loading & scheduling users program.
4. Controlling input & output.
5. Controlling program execution.
6. Managing use of main memory.
7. Providing security to users program.
12
• FUNCTIONS OF AN OPERATING SYSTEM :
• APPLICATION SOFTWARE :
Set of programs to carry out specific task like word processing, spreadsheet, presentation
tools, library management, railway reservation etc is termed as Application software. Application
software can be classified as:
o General Purpose Application Software :
o Specific Purpose Application
Software o Utility Software
o Developer Tools
UTILITIES SOFTWARE:
Utility software are those application program that assist the computer
by performing housekeeping function like compression of files/folders
or taking backup, disk defragmentation and antivirus software.
13
• Disk Defragmenter: In a computer memory a file may store in scattered form i.e at different
memory locations. This fragments of the file takes extra access time when used and slow down the
computer processing. Disk de-fragmentation utility software speeds up the system by rearranging
such fragmented files stored on a disk in contiguous locations in order to optimize the system
performance.
----X _--
14
Chapter-4
INFORMATION SECURITY AND SOCIAL NETWORKING
COMPUTER SECURITY THREATS:
Computer systems are vulnerable to many threats that can inflict various types of damage
resulting in significant losses. This damage can range from errors harming database
integrity to fires destroying entire computer centers. The effects of various threats vary
considerably. Some affect the confidentiality or integrity of data while others affect the
availability of a system.
Malware:
Short for "malicious software," Malware refers to software programs designed to damage or
do other unwanted actions on a computer system. Common examples of Malware include
viruses, worms, Trojan horses, and Spyware.
Virus :
Computer viruses are small programs or scripts that are designed to do hamper the
performance of a computer system. These malicious programs have self replicating
capability and can duplicate themselves, attach themselves to programs, and travel across
networks/ in removable devices. Opening an infected e-mail attachment or affected file is
the most common way to get a virus.
There are many antivirus programs available that scan incoming files for viruses before
they can cause damage to your computer. Some of these programs include Norton
Antivirus, McAfee, Quick Heal etc.
Trojan Horse:
A Trojan horse is a type of malware that claim as a helpful program but when install or used
capture the computer rights and hack the system. It provides unauthorized access of
computer to hacker or perform malfunctioning.
Trojans do not attempt to inject themselves or duplicate themselves into other files like a
computer virus. Trojan horses may steal information, or harm their host computer systems.
Trojans hourse usually spread throuh downloading online games or internet-driven
applications in order to reach target computers.
Spyware:
Spyware is a type of malware (malicious software) installed on computers that collects
information about users without their knowledge. The presence of spyware is typically
hidden from the user and can be difficult to detect. Some spyware, such as keyloggers, may
be installed by the owner of a shared, corporate, or public computer intentionally in order
to monitor users.
Spyware can capture information like Web browsing habits, e-mail messages, usernames
and passwords, and credit card information. If left unchecked, the software can transmit
this data to another person's computer over the Internet.
15
Worm:
A computer worm is a standalone malware computer program that replicates itself in order
to spread to other computers. Often, it uses a computer network to spread itself. This is due
to security shortcomings on the target computer. Unlike a computer virus, it does not need
to attach itself to an existing program. Worms almost always cause at least some harm to
the network, even if only by consuming bandwidth, whereas viruses almost always corrupt
or modify files on a targeted computer.
Virus detection and its removal are made through an antivirus program which finds out
viruses in a computer and then possibly removes or repairs the virus problem. Some of
commonly used Virus detection and its removable tools are Norton Antivirus, McAfee, Virus
Scan, Kaspersky and Quick Heal etc.
Digital Certificate:
A digital certificate is a pair of files on your computer that you can use to create the digital
equivalent of handwritten signatures and sealed envelopes. Each pair of files is divided into
two parts: the public key and the private key.
The public key is the portion that is shared; the private key is the portion that you, and only
you, should have access to. Your computer and programs understand how to share only the
public portion of your keys so that others can see them, while still keeping your private
keys secure.
Digital Signature:
A digital signature authenticates electronic documents in a similar manner a handwritten
signature authenticates printed documents. This signature cannot be forged and it asserts
that a named person wrote or otherwise agreed to the document to which the signature is
attached.
The recipient of a digitally signed message can verify that the message originated from the
person whose signature is attached to the document.
A digital signature is issued by a Certification Authority (CA) and is signed with the CA’s
private key. A digital signature typically contains the: Owner’s public key, the Owner’s
name, Expiration date of the public key, the Name of the issuer (the CA that issued the
Digital ID), Serial number of the digital signature, and the digital signature of the issuer.
Digital signatures deploy the Public Key Infrastructure (PKI) technology.
Cookies:
A cookie is usually a small piece of data sent from a website and stored in a user's web
browser while a user is browsing a website. When the user browses the same website in the
future, the data stored in the cookie can be retrieved by the website to notify the website of
the user's previous activity. Coolies are also known as an HTTP cookie, web cookie, or
browser cookie,
Firewall:
A firewall can either be software-based or hardware-based and is used to help keep a
network secure. Its primary objective is to control the incoming and outgoing network traffic
by analyzing the data packets and determining whether it should be allowed through or not,
based on a predetermined rule.
Hardware Firewall: Hardware firewall providing protection to a Local
Network. Software Firewall: Computer running firewall software to
provide protection
16
Password:
A password is a secret word or string of characters that is used for authentication, to prove
identity or gain access to a resource (example: an access code is a type of password). A
typical computer user may require passwords for many purposes: logging in to computer
accounts, retrieving e-mail from servers, accessing programs, databases, networks, web
sites, and even reading the morning newspaper online.
Ans. Spam: Email spam, also known as junk email or unsolicited bulk email (UBE), is a
subset of electronic spam involving nearly identical messages sent to numerous
recipients by email. Clicking on links in spam email may send users to phishing web
sites or sites that are hosting Definitions of spam usually include the aspects that email
is unsolicited and sent in bulk.
17
Malware : Malware, short for malicious software, is software used or created to disrupt
computer operation, gather sensitive information, or gain access to private computer
systems. It can appear in the form of code, scripts, active content, and other software
Digital Certificate: A digital certificate is an electronic "credit card" that establishes your
credentials when doing business or other transactions on the Web. It is issued by a
certification authority (CA). It contains your name, a serial number, expiration dates, a copy
of the certificate holder's public key (used for encrypting messages and digital signatures),
and the digital signature of the certificate-issuing authority so that a recipient can verify
that the certificate is real
----X----
18
Chapter-4
PROGRAMMING FUNDAMENTALS
• RAD: Rapid Application Development is software programming technique that allows quick development of
software application.
• Integrated Development Environment (IDE): It is a software tool to help programmer to edit, compile,
interpret and debug the program in the same environment. i.e Eclipse,NetBeans, VB etc.
• Byte code: A byte code is machine instruction that the Java compiler generates and Java interpreter
executes. When the compiler compiles a .java file, it produces a series of byte codes and stores them in a
.class file. The Java interpreter (JVM) can execute the byte codes stored in the .class file.
• JVM: Java Virtual Machine (JVM) is a program which behaves as interpreter and translates the byte code into
machine language as they go called just in time compilation.
• Source Code: The core program or text which is written in a language like C,C++ or Java is called source
code.
• Object Code: The program which only is understood by the computer in the form of machine instructions or
binary instructions called object code. In Java JVM is used to generate object code in the form of byte code.
• GUI: A graphical user interface (GUI) presents a pictorial interface to a program. GUI allows the user to spend
less time trying to remember which keystroke sequences do what and spend more time using the program in a
productive manner.
Programming Fundamentals
Token
The smallest individual unit in a program is known as Token. Java has the following types of tokens:
keyword, Identifier, literal, punctuators and operators.
Keywords
Keywords are words that have a specific predefined meaning in Java. They cannot be used as variable names.
They are also known as reserve words. Eg. void, private, if, while etc.
Literals:
Items having fixed data values are referred to as Literals. They are also known as
Constants. Various types of literals available in Java are :
Integer literals
Floating literals
Boolean literals
Character literals
String literals
Null literals
Variable: Variable is a named storage location in computer memory whose contents can change during a
program run. The characteristics of a variable are:
(i) It has a valid name.
(ii) It is capable of storing values.
(iii) It provides temporary storage.
(iv)It is capable of changing its value during program execution.
(v) Each variable must declare before use along with its data type.
19
Operators: Operators are special symbols that perform specific operations on one, two, or three operands, and
then return a result.
Atithmetic operators:
Relational Operators :
Logical Operators:
20
Bitwise operators
Data type: Data type states the way the values of that type are stored in memory, and the range for that type. There
are two data types available in Java:
• Primitive Data Types
• Reference/Object Data Types
• Primitive Data Types: The Java programming language is statically typed, which means that all
variables must first be declared before they can be used. A primitive type is predefined by the
language and is named by a reserved keyword. The eight primitive data types supported by the
Java programming language are:
byte • Byte data type is a 8-bit signed two's complement integer.
• Minimum value is -128 (-2^7)
• Maximum value is 127 (inclusive)(2^7 -1)
• Default value is 0
• Byte data type is used to save space in large arrays, mainly in place of integers,
since a byte is four times smaller than an int.
Example : byte a = 100 , byte b = -50
21
t data type is a 16-bit signed two's complement integer.
shor • Minimum value is -32,768 (-2^15)
t: • Maximum value is 32,767(inclusive) (2^15 -1)
• Short data type can also be used to save memory as byte data type. A short is 2 times
smaller than an int
• Default value is 0.
• Example : short s= 10000 , short r = -20000
• Sho
r
Reference Data Types: Reference variables are created using defined constructors of the classes. They are used
to access objects. These variables are declared to be of a specific type that cannot be changed.
For example, Student, Employee etc.
• Class objects, and various type of array variables come under reference data type.
• Default value of any reference variable is null.
• A reference variable can be used to refer to any object of the declared type or any compatible type.
• Example : Animal animal = new Animal("Elephant");
22
Variable Declaration:
In Java, all variables must be declared before they can be used. The basic form of a variable declaration is:
DataType identifier [ = value][, identifier [= value] ...] ;
Here, The DateType is one of Java's data types. The identifier is the name of the variable. To declare more than one
variable of the specified type, use a comma-separated list.
Note: Java variable names are case sensitive, so MySum and mySum are not same variable.
Example:
int x, y, z; // declares three integers type (int) x, y, and z.
int d = 3, e, f = 5; // declares three more integer with
initialization byte z = 34; // initializes z.
double pi = 3.14; // declares an approximation of pi.
parse methods: parse() methods helps to parse string into different numeric types. These are :
Type Conversion:
The process of converting one predefined type into another is called Type Conversion. These are of two types:
a) Implicit type conversion
b) Explicit type conversion
23
Chapter 5
CONTROL STRUCTURES
Control Flow Statements: There are the situtations when a programmer requires taking decision or to iterate block
of statements for specific number of time, there we use control flow statements. Control flow statements, however,
breakup the flow of execution by decision making, looping, and branching, by execute condition expressions for
particular blocks of code.
Sequence Control Structure : Sequence construct means the statements are being executed sequentially. It is a
default flow of statement from top to bottom.
Selection Control Structure: When the execution of the statement(s) depends upon a condition test then it is called
selection flow of control. If a condition evaluates to true, one course of action is followed other wise another course of
action is followed. It is achieved by if……else conditional statement and switch …….. case conditional statement.
if statement:
Syntax:
if (conditional expression)
{
Statement Block;
}
Condition
if-else
?
Syntax:
if (conditional expression)
{
Block of Statement-1 Block of Statement-2
Statement Block;
}
else
{
Statement Block;
}
Nested if else
These control structures are used to test for multiple conditions as against the simple if statement which can
be used to test a single condition.:
Syntax:
if (conditional expression1)
{
statements1;
}
else if (conditional expression2)
{
statements2;
}
else if (conditional expression3)
{
statements3;
}
else
{
statements4;
}
24
(b) switch: This selection statement allows us to test the value of an expression with a series of character or integer
values. On finding a matching value the control jumps to the statement pertaining to that value and the
statement is executed, till the break statement is encountered or the end of switch is reached.
switch (Variable/Expression)
{
case Value1 :
statements Block 1 ;
break ;
case Value2 :
statements Block 2
break ;
default:
statements Block 3
}
LOOPING (ITERATION) : These statements are used to perform a set of instructions repeatedly while the
condition is true.
• for ……. Loop Statement :- It is basically used to repaeat block of statement { } for specific number of times.
Syntax
for( initialization; test expression; increment/decrement expression)
{
statements;
}
• while loop statement: The while loop is an entry-controlled loop. It means that the loop condition is tested
before executing the loop body. If the loop condition is initially false, for the first iteration, then loop may not
execute even once.
JUMP STATEMENTS:
(i) break : The break is used to break from an enclosing do, while ,for or switch statement.
(ii) continue: The continue statement stops the execution of the current iteration and causes control to begin with
next iteration.
(iii) return : Return is used to return value from the method
25
Chapter-6
JAVA IDE PROGRAMMING – I , II & III
In Java, the GUI programmin is done through Swing API ( Application Programming Interface). Swing is a set of classes
that provides more powerful and flexible components than are possible with AWT (Abstract Windows Toolkit). It supplies
buttons, chekboxes, labels, tabbed panes, scrool pans, trees, tables, dialog boxes etc.
o jTextField: JTextFeild allows placing editable text on the Frame/Pane. User can enter text in a text field
during runtime.
o jbutton: is used to initiate an action when it is clicked.
o jList: is a group of values or items from which one or more selections can be made.
o jComboBox: jComboBox is similar to jList but also allow to enter editable text during run time.
It is a combination of jTextFiled and jList.
o jRadioButton: Allow us to choose a single item from a group of jRadioButton options.
o jCheckBox: Allow us to choose one or more items from a group of jCheckBox options.
o jPasswordField: Allow us to enter a text during the run time but shows an encrypted text instead of the
original text
o jTextArea: JTextArea is a multi-line text component to enter or edit text.
o Focus: The control under execution is said to have the focus. The control having the focus obtains
input form the user.
o getText(): getText() method is used to obtain the text from a jTextFeild during the run time. o
setText(): setText() method is used to set or change the text of a jTextFeild during run time.
Swing Controls Methods and Properties: These are the Swing Controls available with NetBeans IDe and
their concern methods and properties are given below.
26
Swing Controls Methods Properties
2. Which window contains the Swing Controls components. Ans: Palette window
3.What is the most suitable component to accept multiline text. Ans : Text Area
27
5. What will be the output of the following command?
"Learning".concat("Java") Ans: LearningJava
8.Write code to add an element (“New Course”) to a list (SubList) at the beginning of the
list. Ans: SubList.add(0,”New Course”);
9. Describe the three common controls. Also give some of their properties.
Ans: Control Name Properties
(i) jButton text, icon
(ii) jLabel text, border
(iii) jTextField text, font
10. By default a combo box does not offer editing feature.How would you make a combo box
editable. Ans: By setting its editable property to false.
11. Write Name the component classes of Swing API for the following components- a) frame (b) button
Ans: (a) JFrame (b) JButton
12. What is the name of event listener interface for action events
? Ans: ActionPerformed
16.Which method of list is used to determine the value of selected item, if only one itm is
selected? Ans: getSelectedValue()
18. What will be the output of the following code segment: String firstName = "Manas ";
String lastName = "Pranav";
String fullName = firstName + lastName; jTextField1.setText("Full Name:
"); jTextField2.setText (fullName);
Ans: Full Name:
ManasPranav
28
22.Which events gets fired when a user click a JButton and
JRadioButton. Ans: ActionPerformed
24. What will be used if there are two or more possible options?
Ans: We can use if…..else conditional statement or switch……case statement.
28.Which process is used to translate a task into a series of commands that a computer will use to perform
that task.
Ans: Project design
29. Which of the following component is the best suited to accept the country of the user?
A. List B Combo box C Radio button D Check box
Ans: List and combo box
30. Which construct will be used to find the sum of the first 10 natural
numbers? Ans: for loop
b) Forms: Forms are used to accept data (input) and submit data to an external agent for processing.
3. Differentiate between:
a) Text field and Text area components :
The Text Field allows the user to enter a single line of text only. But Text Area component allows to accept
29
multiline input from the user or display multiple lines of information.
4. What is a Variable?
Ans: Variables are named temporary storage locations.
7. What is an identifier?
Ans:Identifiers are fundamental building block of a program and are used as the general terminology for the
names given to different parts of the program viz. variables, objects, classes,functions, arrays etc.
12. What is the main difference between a combo box and a list box?
Ans: The List Box does not have a text field the user can use to edit the selected item, wheras a Combo Box is
cross between a text field and a list.
13. Explain the use of for statement along with its syntax.
Ans: The for loop repeat a set of statements till a test condition is satisfied. The syntax of the for loop
is: Syntax:
for( initialization; test exp; increment/decrement exp)
{
statements;
}
16. What is the main difference between a while loop and a do while loop?
Ans: In while loop test expression is evaluated at the beginning of the loop whereas in do while loop the test
expression is evaluated at the bottom of the loop. This means that do-while loop is executed at least once.
30
17. How is the if…else if combination more general than a switch statement?
Ans:The switch statement must be by a single integer control variable, and each case section must correspond to a
single constant value for the variable. The if…else if combination allows any kind of condition after each if.
a) Exception Handling: Run time errors are also called exceptions, and handling such errors in the
application is called exception handling.
b)Syntax: Formal set of rules defined for writing any statement in a language is known as syntax.
c) Portability: The application should be portable. It should be able to run on different platforms.
d) Prettyprinting: Prettyprinting is the formatting of a program to make it more readable. These formatting
conventions usually consist of changes in positioning, spacing, color, contrast, size and similar modifications
intended to make the content easier to view, read and understand.
e) Syntax error: Syntax errors occur when syntax rules of any programming language are violated. These errors
occur during compilation of the application
23. Write the use of following methods used with check box control.
a) getText( ), b) setText(String s) c) isSelected( ) d) setSelected( )
---X---
OUTPUT FINDING QUESTIONS
1 Write the output following code when executed:
(i) System.out.printl(“Hello”.charAt(3));
(ii) System.out.printl(“Good morning”.substring(4));
31
Ans: (i) l (ii) morning
Ans: 0 times
4. What will be the value of j and k after execution of the following code:
int j=10,k=12; if(k>=j)
{
k=j; J=k;
}
Ans: 10 10
32
Ans : Code MightWork
Ans: 10
10. How many times will the following loop get executed? x = 5;
y = 36; while ( x <= y) { x+=6; }
Ans: 6
11. What will be the content of the jTextArea1 after executing the following code? Int Num = 1;
do
{
jTextArea1.setText(Integer.toString(++Num) + "\n"); Num = Num +
1; }while(Num<=10)
12. What will be the contents of jTextfield1 and jTextfield2 after executing the following code:
String s=”KENDRIYA VIDYALAYA GUNA”
jtextfield1.setText(s.length()+” “);
jtextfield2.setText(Math.round(2.34)+“”);
Ans : 23 2
13. What will be the value of s after executing the following code? double i,sum=2
for(i=3;i<8;++i) { if(i%4=
=0) {
break;
sum=Math.pow(sum,i);
}
else
sum+=i/2;
}
Ans: 150.0625
14. What will be the content of jTextField1 and jTextField2 after executing the following code:
String st=”New to Information Technology”;
jTextField1.setText(st.replace(“Technology”,”Practices”);
jTextField2.setText(st.substring(7));
Ans: New to Information Practices
Information Technology
18. Predict the output for tan & tan1 if sac equals 7? int tan = 0, tan1 = 4
; if ( sac == 2 )
{ tan = 4 ; tan1 = 0; } else if (sac == 8)
{ tan = 0 ; tan1 = 4; }
JOptionPane.showMessageDialog( null , “ tan = “ + tan +” , tan1 = “
+ tan1 ) ;
Ans: tan = 0 tan1=4
33
case 1: x=x+2; case 2: x=x+3; default: x =x+1;
}
System.out.println(“value of x:”+x);
Ans: 15
24. What will be the contents of jTextField1 and jTextField2 after executing the following code:
String s = “Sun Micro Systems”;
jTextField1.setText(s.length()+””);
jTextField2.setText(s.toLowerCase());
Ans: jTextField1 : 17
jTextField2 : abc micro systems
25 What values will be assigned to the variable ua ,ub, uc and fail after execution of the following program segment:
int i=0,ua=0,ub=0,uc=0,fail=0;
while(i<=5) {
switch ( i++ ) {
case 1 : ++ua;
case 2 : ++ub; uc++; break;
case 3 :
case 4 : ++uc; ua++;ub++; break;
default : ++fail;
} }
Ans: ua=1 ub=1 uc=0
3. Rewrite the code after removing the errors (if any) and underline the corrections.
int y=3;
switch(y);
{ case 1: System.out.print(“Yes its One”);
case>2: System.out.println(“Yes its more than Two”); break;
34
case else: System.out.print(“Invalid Number):
Ans:
int y=3;
switch(y)
{ case 1: System.out.print(“Yes its
One”); break;
case 2: System.out.println(“Yes its more than Two”);
break; default:System.out.print(“Invalid Number):
}
Ans:
int x = 0;
int n= Integer.parseInt(JLabel1.getText());
Ans:
m=1; n=0;
for(;m+n<19;++n) System.out.println(“hello”); m=m+10;
35
8. Rewrite the following code using while loop :
int i,j; for(i=1;i<=4;i+
+){
for(j=1;j<=i;++j){
System.out.print(j); }
System.out.println( );}
Ans:
int i=1,j;
while(i<=4){
j=1;
while(j<=i){
System.out.print(j);
++j;
}
i++;
System.out.println();
}
9. Rewrite the following code using while loop int
i,j; for(i=1,j=2;i<=6;i++,j+=2)
System.out.println(i++);
System.out.println(“Finished!!!”);
11. Write the equivalent switch case for the following code:
if (num1 = =1 )
jTextField1.setText(“Number is one”);
else If (num1 = =2 ) jTextField1.setText(“Number is two”);
else If (num1 = =3 ) jTextField1.setText(“Number is three”);
else
jTextField1.setText(“Number is more than three”);
Ans:
Switch(num1) {
case 1 : jTextField1.setText(“Number is one”); break; case 2
: jTextField1.setText(“Number is two”); break; case 3 :
jTextField1.setText(“Number is three”); break; default:
jTextField1.setText(“Number is more than three”); }
36
12. Rewrite the following code fragment using
switch : if(ch = = ‘E’)
east++;
if(ch = =
‘W’) west++;
if(ch = = ‘N’)
north++;
if(ch = = ‘S’)
south++;
else
jOptionPane.showMessageDialog(null, “unknown”);
Ans. switch(ch) {
case ‘E’: east++;
break;
case ‘W’: west++;
break;
case ‘N’: north++;
break;
case ‘S’: south++;
break;
default :
jOptionPane.showMessageDialog(null, “unknown”);
}
37
JAVA SWING APPLICATIONS
1 Even Odd Application
38
3 Greatest among three un-equal numbers:
switch(daynum)
{
case 1:
day=”Monday”;
break; case 2:
day=”Tuesday”;
break; case 3:
day=”Wednesday”; break;
case 4:
day=”Thursday”; break;
case 5:
day=”Friday”; break;
case 6:
day=”Saturday”; break;
case 7:
day=”Sunday”; break;
default:
day=”Invalid day number”;
}
lblRes.setText(day);
39
5 Grade calculation based on marks scored out of 100
90 to 100 - A
75 to <90 - B
60 to <75 - C
45 to <60 - D
33 to <60 - E
0 to <33 - F other
invalid score
40
7 The following interface is used to calculate the net salary of a person after deducting the tax from the
gross based upon the selection from the avaliable radiobutton options (10%, 20% and 30%). The
click event of the button will display the tax and the net salary.
8 The following interface calculate the fees of a student based upon the given criteria. For a boy the fees
is 1000. For a girl the fees is 500. For a single girl child as selected from the check box there is no fees.
Write code under the Action event of the button to display the name and fees in a jTextArea as shown.
private void btnResActionPerformed(java.awt.event.ActionEvent evt) {
String name = txtName.getText();
int fee;
if(rbtG.isSelected())
{
fee = 500;
if(chkSg.isSelected())
fees=0;
}
else
fees=1000;
txtRes.append("Name:"+name+"\n");
txtRes.append("Fees:"+fee);
}
41
9 The math editor interface is shown below. It performs the Add, Subtract and Multiply operations based on
the seclections from the jComboBox. Write code under the get Result button to achieve the desired
results.
Step 1: To make it possible to use the dynamic feature of jListBox we must import the
following: import javax.swing.DefaultListModel;
Step 2: Declare an object of DefaultListModel class as the first statement in jFrame class:
public class ListApp extends javax.swing.JFrame {
DefaultListModel listModel;
Step 3: Instantiate the listModel object inside the constructor of the jFrameC class:
public ListApp() { //this is the already available inside the jFrame code window
42
initComponents(); // this is already available
listModel = new DefaultListModel();
lstName.setModel(listModel);
}
Step 4: Adding elements in the jListBox:
private void btnAddActionPerformed(java.awt.event.ActionEvent evt)
{ // TODO add your handling code here:
listModel.addElement(txtName.getText());
}
Step 5: Deleting the selected element from the jListBox:
private void btnDelActionPerformed(java.awt.event.ActionEvent evt)
{ // TODO add your handling code here:
listModel.remove(lstName.getSelectedIndex());
}
Step 6: Displaying the selected el;ement in a jLabel:
private void btnShowActionPerformed(java.awt.event.ActionEvent evt)
{ // TODO add your handling code here:
lblRes.setText((String) lstName.getSelectedValue());
}
11 The following application retrieves the passwaord from a jPasswordField and displays it in a jLabel
43
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
javax.swing.JOptionPane.showMessageDialog(rootPane,"Hello World", "My Caption", 1);
}
44
14 The following interface computes the sum of n natural numbers and factorial of a number as entered by
user depending upon the selection of the jRadioButton:
GUI Programming adopts simplified approach to programming. In GUI Programming, most of the
components are predefined in a generic way to be adapted and incorporated according to the needs of
the application. Some guidelines for good GUI Programming are:
Phase 2: Designing : In this phase detailed design of the following components is to be made:
• Input Design
• Ouput Design
• Interface Designing (Forms)
• Modular Components
• Algorithms
Phase 3: Coding
Phase 4: Testing and Debugging:
Phase 5: Implementation
Phase 6: Documentation and M aintenance:
46
Types of Errors
Compile Time Error- Occurs during compile time. When a program compiles it sources code
is checked for rules of programming language. Its types are:-
Syntax error: it occurs when a grammatical rule of Java is violated
Semantic error: it occurs when statement are not meaningful.
Q1. Excessive comments add time to the execution of your program. (True/False). Justify your
answer.
Ans. No, Comments don’t add time to program execution. As comments are only for documentation
purpose. They are non executable statements.
Compile time errors are easy to correct as we get error message corresponding to that which
give an idea to correct it. Run time errors causes abnormal termination of program.
Example of compile time error: Missing semicolon(;). Example of run time error: Divide by
zero error, Logarithm of a negative number.
Q7. Prettyprinting
Ans. Prettyprinting is the formatting of a program to make it more readable. These formatting
conventions usually consist of changes in positioning, spacing, color, contrast, size and similar
modifications intended to make the content easier to view, read and understand.
47
Q8 The code given below will give an error on execution if the value entered in t2 is 0. Identify
the type of the error and modify the code to handle such an error.
int a,b,c;
a= Intger.parseInt(t1.getText());
b= Intger.parseInt(t2.getText());
c= a / b;
Ans: The error is logical error. int a,b,c;
a= Intger.parseInt(t1.getText());
b= Intger.parseInt(t2.getText()); if(b!
=0) c= a / b;
else {
JOptionPane.showMessageDialog(null,”Denominator cann’t be
zero”); t2. setText(“ “);
t2.requestFocus( ) ;
}
Ans Comments are non executable statements and are used for internal documentation purpose.
In Java comments are given either by // or /* ….*/ brackets.
Example-
Indentation makes a program readable and understandable. When you are writing a program you
must remember that the opening braces should properly match with a closing braces.
48
Chapter-8
DATABASE MANAGEMENT SYSTEM
Data: Basic/raw facts about something which is not organized, for example details of some students
which is not organized.
Data Item: Each piece of information about an entity, such as name of a person or address, age or name
of a product or the price is a Data Item.
Database: A well-organized collection of interrelated data that ensures safety, security and integrity of
data is called database.
Database Systems: Systems comprising of Databases and Database Management Systems are simply
referred as database systems.
Data Independence: The ability to modify a scheme definition in one level without affecting a scheme
definition in the next higher level. Two Level of Data Independence are:-
• Physical Data Independence: It refers to the ability to modify the scheme followed at
the physical level without affecting the scheme followed at the conceptual level.
• Logical data Independence: It refers to the ability to modify the scheme followed at
the conceptual level without affecting the scheme followed at the External level.
49
Data (Database) Model: A way by which data structures and their relationships are analyzed.
• Relational data model
• Network data model
• Hierarchical data model
• Domain : Domain of an attribute refers to the set of all the possible values for that attribute.
• Candidate Key: A set of one or more minimal attributes used to uniquely identify a tuple in
the relation and which can act as Primary Key. A relation can have multiple candidate keys
• Primary Key: A candidate key that is primarily chosen for unique identification of tuples in a
Relation. Any subset of Primary key should not be Primary key.
• Alternate Key: Candidate keys that not chosen as primary key are the alternate keys.
Example:In A LIBRARY Table
* Candidate keys can be Accession No, Book No
* Primary key: If we select Book No as primary key for
our purpose then Alternate Key will be Accession No.
• Views : A view is a virtual table whose contents are taking from other tables depending upon a
condition.
50
Table: Student
Roll No. Name Marks
101 Anu 85
102 Riya 70
103 Ankit 78
Here name of the view is toppers Base table is students toppers( A virtual table based on Student table)
FOREIGN KEY
A column or a combination of columns whose values are derived from primary key of some other
table is called the foreign key of the table in which it is contained.
REFERENTIAL INTEGRITY
The property of a relational database which ensures that no entry in a foreign key column of a table can
be made unless it matches a primary key value in the corresponding column of the related table. It is
enforced in the database with the help of foreign key constraint.
Do Yourself :
Identify Tuple, Attributes, Field Names, Primary Key in the table Custmer shown below.
51
Chapter-9
MYSQL
MySQL : It is an Open Source RDBMS Software that uses Structured Query Language . It is available free
of cost.
Key Features of MySQL :
Every column (or data item) should belong to a unique domain (known as data type). These data types help
to describe the kind of information a particular column holds. MySQL supports the ANSI SQL data types.
Some of the commonly used data types along with their characteristics are as follows:
SQL statements are used to retrieve and update data in a database. SQL works with database programs like
MySQL, MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc. Most of the SQL database programs
also have their own proprietary extensions in addition to the SQL standard.
52
SQL COMMANDS
SQL commands can be classified into the following:
Data Definition Language (DDL): A database scheme is defined by set of definitions, which are expressed, by
a special set of commands called Data Definition Language (DDL). They are used to create tables, databases,
identify data items, provide unique names to the data items and to define the length and provide the range of
values that each data item can assume. They are CREATE TABLE, ALTER TABLE and DROP TABLE
commands.
Data Manipulation Language (DML):
The data manipulation language (DML) handles operations such as entering rows into a table, changing data,
deleting rows, and extracting data from rows and tables. With DML, one does not change the table's structure,
but rather its contents. It contains commands like INSERT, UPDATE and DELETE.
Transaction Control Language (TCL): A transaction is a one complete unit of work. A transaction is
successfully completed in and only if all its constituent steps are successfully completed. To manage and
control the transactions, the transaction control commands are used. e.g. COMMIT,ROLLBACK,SAVEPOINT.
Now the database with the given name will be created. One must be connected to the database before using it
, as below:
• Creating Tables
Tables are defined with the CREATE TABLE command. When tables are created its columns are named,
data types and sizes supplied for each column. At least one column must be specified.
Syntax:
Example:
mysql> CREATE TABLE Students (
RollNo DECIMAL(3), Name VARCHAR(25) );
Once the table is created we can insert the record in it, edit or delete existing records, and also we can
search for desired record in a very comprehensive way using the SQL Select statement.
When a constraint is applied to a single column, it is called a column level constraint but if a constraint
is applied on a combination of columns it is called a table constraint.
53
• Following constraints can be defined on a table in SQL:
Constraints name Description
PRIMARY KEY to create a primary key
NIQUE to create a unique key
NOT NULL to define that column will not accept null values.
FOREIGN KEY/ REFERENCES to define referential integrity with another table.
DEFAULT to define the columns default value.
CHECK to define the custom rule.
NOT NULL and DEFAULT constraints can be applied only at column level rest all constraints can be applied on
both column level and table levels.
USE OF CONSTRAINTS
> CREATE TABLE student (Srollno integer NOT NULL, …);
> CREATE TABLE student (Srollno integer UNIQUE, …);
>>CREATE TABLE student (SRNo integer NOT NULL, Sclass integer, Sname varchar(30), Sclass DEFAULT 12);
> CREATE TABLE student (Srollno integer CHECK (Srollno>0), Sclass integer, Sname varchar(30));
> CREATE TABLE student (Srollno integer NOT NULL PRIMARY KEY, Sclass integer, Sname varchar(30));
> CREATE TABLE teacher (Tid integer NOT NULL, FOREIGN KEY (Studentid ) REFRENCES student (Sid));
Inserting Dates:
INSERT INTO Student (RollNo,Name, Class, DOB) VALUES (12333,’Anu’,11, ‘1998-02-24’)
NOTE: Column names can be omitted if the values are entered in the same order in which they appear in the
table. Insert into will give you an error if you omit to enter a mandatory value (non-null).
Will delete all records from Students table. This is not likely to be what you want.
54
MODIFYING THE CONTENTS OF RECORDS:
The UPDATE command changes one, many, or even all records in a table, depending on the conditions
that you specify
Syntax:
UPDATE tablename
SET column_name = expression [,column_name = expression..] [WHEREsearch_conditions];
An expression can be either a constant value (e.g., ‘Thomas’) or an operation done on another column
or columns (see the example below, assuming a loan table with column rate.).
Because there is no condition (i.e., no WHERE ) all records will be updated. All rates will be increased by 1.5.
Choosing all fields (columns): Use a asterisk (*) to indicate all fields with the select statement:
NOTE: The order in which you list the columns affects their order in the resulting output. Items within [ ] are
optional.
Temporarily renaming columns in query results
Example:
SELECT f_name as “Name” FROM customer;
55
Eliminating duplicate query results with distinct
If you use the keyword distinct after the keyword SELECT, you will only get unique rows.
Example:
Null values
Note: “%” (matches any string of zero or more characters) and “_” (matches any one character). In addition to those,
brackets can be used to include either ranges or sets of characters.
Combinations of previous options using logical operators and, or, and not etc.:
SELECT f_name, l_name FROM customer
WHERE l_name LIKE ‘San%’ AND City NOT IN (‘Baroda’,‘Delhi’)
56
Some more examples:
‘Am%’ matches any string starting with Am.
‘%Singh%’ matches any string containing ‘Singh’
‘%a’ matches any string ending with ‘a’
‘_ _ _’ matches any string that is exactly 3 characters long.
‘_ _ %’ matches any string that has at least 2 characters long.
‘_ _ _g’ matches any string that is 4 characters along with 3 characters in the beginning but ‘g’ as
the 4th character.
Describe/ Desc statement is used to see the structure of a table: Desc <tablename> ;
Describe <tablename>;
Sorting records
The output of a SELECT query can be sorted in ascending or descending order on one or more columns, the default is
ascending. This is important to note that the data in table is not sorted, only the results that appear on the screen are
sorted.
Syntax:
SELECT <column name> [,<column name>, ….] FROM <table
name> [WHERE <condition>]
[ORDER BY <column name> [, <column name>…]];
Adding a column:
The ALTER TABLE command is used to change definitions of existing tables . It can add columns, delete columns
or change their size.
Syntax:
ALTER TABLE <table name>
ADD (<column name> <data type with size> <constraints>);
Modify a column :
Syntax :
ALTER TABLE <table name>
MODIFY ( column name newdatatype (newsize));
Example:
ALTER TABLE Students MODIFY ( age NUMBER (1));
57
Changing a column name:
ALTER TABLE <table name>
CHANGE <old_column_name> <new_column_name> <column definition> ;
Example:
ALTER TABLE Students
CHANGE age s_age NUMBER (2)
OPERATOR PRECEDENCE :
All the operators have precedence. Precedence is the order in which different operators are evaluated.
Various operators in descending order of precedence ( top to bottom) are listed below:
1 !
2 ( unary minus)
3 ^
4 *,/,DIV,%, MOD
5 -,+
6 =, <=, >, >=, =, !=, IS, LIKE, IN
7 BETWEEN
8 NOT
9 &&, AND
10 ||, OR
58
Chapter-10
MYSQL FUNCTIONS
Functions
A function is a predefined command set that performs some operation and returns the single value.
Numeric Functions
POWER() : Returns the argument raised to the specified power. POW () works the same
2):Result:0.25 (iii)POW(-2,3):Result: -8
ROUND() : ROUND(X) Rounds the argument to the zero decimal place, Where as
Example : (i) SIGN (15) Result : 1 : (ii) SIGN (-15) Result : -1 : (iii) SIGN (0) Result : 0.
Character/String Functions
LENGTH() : Returns the length of a string in bytes/no.of characters in string.
CHAR() : Returns the corresponding ASCII character for each integer passed.
Result : INFORMATICS
LEFT() : Returns the given number of characters by extracting them from the left side of the
given string
59
RIGHT(): Returns the given number of characters by extracting them from the right side
of the given string
Result : CES
MID(): Returns a substring starting from the specified position in a given string.
Result : FORM
Date/Time Functions
What is SQL?
Ans . SQL is Non -procedural universal data access language used to access and manipulate data stored in nearly all
the data bases available currently. SQL standards are defined by ANSI (American National Standards Institute).
SQL statements are used to retrieve and update data in a database. SQL works with database programs like
MySQL, MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.
What is a constraint?
Ans : A constraints is a condition or check application on a field or set of fields.
Example: NOT NULL (ensure that column con not have null value), CHECK (make sure that all value satisfy
certain criteria), UNIQUE (ensure that all values in a column are different) etc.
The VARCHAR on the other hand supports variable length strings and therefore stores strings smaller than the
field size without modification.
What are the differences between DELETE and DROP commands of SQL?
Ans: DELETE is DML command while DROP is a DDL command. Delete is used to delete rows from a table while
DROP is used to remove the entire table from the database.
Explain with the help of an example that why should a transaction be executed as a whole or it should be not
executed at all.
Ans: Suppose Raunak's account number is 3246 and his aunt's account number is 5135. In order to process the
cheque presented by Raunak, the following two SQL commands need to be executed on the database maintained by
the bank:
61
Query Based question & answers
Ans: SELECT Pincode from Post where Pincode LIKE " %1" ;
i. SELECT Pincode from Post where Pincode LIKE " 0%" ;
(i) Write the command to delete all the rows of particular voter from the table voter where voter ID between
10 and 20.
Ans: Delete from VOTER where V_id between 10 and 20;
(ii) Delete the table physically. Ans: Drop table VOTER;
4. Write MySql command to create a furniture table including all constraint.
Table: Furniture
5 20 20 6 2
CREATE TABLE FURNITURE ( ITEMNO INT(5) PRIMARY KEY, ITEMNAME VARCHAR(20) NOT NULL,
TYPE VARCHAR(20),DATE_STOCK DATE DEFAULT '2012/03/19', PRICE INT(6), DISCOUNT INT(2) );
62
5. Consider a database LOANS with the following table:
Table: Loan_Accounts
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
8. Display the Int_Rate of all the loans started after 01-04-2009. Mysql>
Select Int_Rate from Loan_Acc where Start_date>'2009-04-01';
Using NULL
9. Display the details of all the loans whose rate of interest is NULL.
Mysql> Select * from Loan_Acc where Int_rate is NULL;
10.Display the details of all the loans whose rate of interest is not NULL.
63
Using DISTINCT Clause
11. Display the amounts of various loans from the table Loan_Accounts. A loan amount should appear only once.
Mysql> Select DISTINCT Loan_Amount from Loan_Acc;
12. Display the number of instalments of various loans from the table Loan_Accounts. An instalment should
appear only once..
Mysql> Select DISTINCT Instalment from Loan_Acc;
Using IN Operator
19. Display the Cust_Name and Loan_Amount for all the loans for which the number of instalments are 24, 36, or
48 (Using IN operator)
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Instalment IN(24,36,48);
21. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name ends with 'a'.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where Cust_Name like '%a';
22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name contains 'a'
Lab Activity 1: Create a table STUDENT with under mentioned structure by using SQL
Statement:
StdID Number Primary Key
Character
StdName (30) NOT NULL
Sex Character(6) Male or Female
Percentage Number
SClass Number
Sec Character
Character(10 Science or
Stream ) Commerce
DOB Date Date of Birth
Step 4: As you press enter key after typing above statement, 1 record will be stored
into STUDENT table.
Step5: Similarly like step 3, enter other records of the following table.
Percentag Se
StdID StdName Sex e Class c Stream DOB
FEMAL 10/11/199
1001 AKSHRA AGARWAL E 70 11 A Science 6
FEMAL Commerc 18/09/199
1002 ANJANI SHARMA E 75 11 A e 6
Commerc 19/11/199
1003 ANSHUL SAXENA MALE 78 11 A e 6
FEMAL Commerc
1004 AISHWARYA SINGH E 79 11 A e 1/11/1996
FEMAL Commerc 20/09/199
1005 AKRITI SAXENA E 76 11 A e 6
FEMAL Commerc 14/09/200
1006 KHUSHI AGARWAL E 77 11 A e 3
1007 MAAHI AGARWAL FEMAL 74 11 A Science 21/04/199
E 7
FEMAL 26/11/199
1008 MITALI GUPTA E 78 12 A Science 7
1009 NIKUNJ AGARWAL MALE 58 12 A Science 12/7/1997
FEMAL Commerc 20/12/199
1010 PARKHI E 59 12 A e 7
65
22/04/199
1011 PRAKHAR TIWARI MALE 43 12 A Science 7
Commerc 21/12/199
1012 RAGHAV GANGWAR MALE 58 12 A e 7
Commerc 13/08/199
1013 SAHIL SARASWAT MALE 57 12 A e 7
FEMAL 13/08/199
1014 SWATI MISHRA E 98 11 A Science 6
28/08/200
1015 HARSH AGARWAL MALE 58 11 B Science 3
22/05/200
1016 HARSHIT KUMAR MALE 98 11 B Science 3
1017 JAHANVI KAPOOR MALE 65 11 B Science 10/1/1997
Commerc
1018 STUTI MISHRA MALE 66 11 C e 10/1/1996
SURYANSH KUMAR
Commerc 22/08/200
1019 AGARWAL MALE 85 11 C e 7
FEMAL Commerc 15/01/199
1020 TANI RASTOGI E 75 12 C e 8
1021 TANISHK GUPTA MALE 55 12 C Science 11/4/1998
Commerc 28/06/199
1022 TANMAY AGARWAL MALE 57 11 C e 8
1023 YASH SAXENA MALE 79 11 C Science 13/3/1998
Commerc
1024 YESH DUBEY MALE 85 12 C e 3/4/1998
Lab Activity 2: Open school database, then select student table and use following SQL statements.
TYPE THE STATEMENT, PRESS ENTER AND NOTE THE OUTPUT
1 To display all the records form STUDENT table.
SELECT * FROM student ;
2. To display ony name and date of birth from the table STUDENT.
SELECT StdName, DOB FROM student ;
3. To display all students record where percentage is greater of equal to 80 FROM student table.
SELECT * FROM student WHERE percentage >= 80;
4. To display student name, stream and percentage where percentage of student is more than 80
SELECT StdName, Stream, Percentage WHERE percentage > 80;
5. To display all records of science students whose percentage is more than 75 form student table.
SELECT * FORM student WHERE stream = ‘Science’ AND percentage > 75;
Lab Activity 3: Open school database, then select student table and use following SQL statements.
TYPE THE STATEMENT, PRESS ENTER AND NOTE THE OUTPUT
1. To display the STUDENT table structure.
DESCRIBE Student;
4. Type the statement and press enter key, note the new field that you have added as
TeacherID
SELECT * FROM student;
Lab Activity 4
1. To Drop (Delete) a field form a table. For e.g you want to delete TeacherID field.
2. To subtract 5 form all students percentage and display name and percentage.
3. Using column alise for example we want to display StdName as Student Name and
DOB as Date of Birth then the statement will be.
SELECT StdName AS "Student Name",
DOB As “Date of Birth” FROM Student;
Lab Activity 5:
1. To change a student name from SWATI MISHRA to SWATI VERMA whose StdID is
1014 and also change percentage 86.
UPDATE Student SET StdName = ‘SWATI VERMA’,
percentage = 86 WHERE StdId = 1014;
2. To delete the records form student table where StdId is 1016.
DELETE FROM Student WHERE StdID = 1016;
3. Type the following SQL statement and note the output.
SELECT * FROM Student WHERE StdName LIKE 'G_' ;
SELECT * FROM Student WHERE StdName='G';
SELECT * FROM Student WHERE StdName LIKE 'G%' ;
SELECT * WHERE Student WHERE StdName='%G%' ;
4. Display all the streams in student table.
SELECT DISTINCT Stream FROM Student;
5. Note the output of the following statement.
SELECT StdName, Sex, Stream FROM Student WHERE percentage BETWEEN 70
AND 80;
67
Do yourself:
Create a Table Empl to store employee details as shown below and write statements for following
queries based on the table.
1. Consider the Empl table and write SQL command to get the following.
a. Write a query to display EName and Sal of employees whose salary are greater than or equal
to 2200?
b. Write a query to display details of employs who are not getting commission?
c. Write a query to display employee name and salary of those employees who don’t have their salary
in range of 2500 to 4000?
d. Write a query to display the name, job title and salary of employees who don’t have manager?
e. Write a query to display the name of employee whose name contains “A” as third alphabet?
f. Write a query to display the name of employee whose name contains “T” as last alphabet?
g. Write a query to display the name of employee whose name contains ”M” as First and “L” as third
alphabet?
h. Write a query to display details of employs with the text “Not given”, if commission is null?
_______________________________________________________________________________
68
Chapter-11
IT APPLICATIONS
¾ E-GOVERNANCE:
It refers to application of electronic means in governance with an aim of fulfilling
the requirements of common man at affordable costs and in fastest possible time.
¾ E-BUSINESS:
69
¾ Some E-Business websites are:
¾ E-LEARNING:
It is a flexible term used to describe a means of teaching through technology such as
a network, browser, CDROM or DVD multimedia platform.
70
QUESTION & ANSWERS
Q.1. What is e-Governance?
c. Cost reduction.
e. Increased efficiency.
b. Self pacing for slow and quick learners reduces stress and increased satisfaction.
c. Interactivity engage users, pushing them rather than pulling them through training
Ans: E-learning is preferred because it provides faster learning at reduced cost, increased
accessed to learning and clear accountability for all participants in the learning process.
71
KENDRIYA VIDYALAYA SANGATHAN,
BANGALORE REGION
SESSION ENDING EXAMINATION – 2014
INFORMATICS PRACTICES – (065)
Max Marks : 70 CLASS : XI TIME : 3 Hours
General Instructions :
d) You are regularly visiting your School’s Computer Lab. Enlist two
items that 2 you consider as e‐waste. Also justify your answer.
72
Q.2 a) What is Rapid Application Development? 1
d) 4
jTextField –
txtName
jTextFiled – txtPhy
jTextField –
txtChe
jTextField –
txtMat
jTextArea –
txtRes jButton
– btnRes
jButton ‐
btnExit
jTextBox –
tb1 jLabel –
lb1
75
i. Write SQL query to display the details of
STUDENT table in the descending order of the
FEES.
ii. Write SQL query to display the SNAME, GENDER and
FEES for all the students whose HOUSEID is either 10
or 11 or 13.
iii. Write SQL query to display the SNAME, FEES and
HOBBY for all the students who do not have a hobby.
iv. Write SQL query to display the SNAME and GENDER for
all the students who are paying fees in the range of 600
to 800.
v. Write SQL query to display the ROLLNO and SNAME for
all the students whose SNAME is ending with ‘A’.
vi. Write SQL query to display the STUDENT details whose
year of birth is 2002.
b) Study the given HOSPITAL table and write the DML queries
that follow. 4
PID PNAME DOA DOD WARD FEES
2008‐01‐ 2008‐01‐20
1001 RAVI 10 SURGERY 2000
2008‐02‐ 2008‐03‐20
1002 AMAR 21 MEDICINE 1500
2009‐10‐ 2009‐11‐25
1003 SUJA 02 SURGERY 2500
2007‐12‐ 2007‐12‐31
1004 RUMA 12 OPTHALMO 1800
2008‐08‐ 2008‐09‐11
1005 SIJU 10 MEDICINE 2800
2007‐10‐ 2007‐12‐
1006 ARUNA 10 20 NEURO 3500
2008‐09‐ 2008‐09‐ OPTHALM
1007 HYDER 15 18 O 3250
2009‐06‐ 2009‐08‐
1008 RAINA 12 21 SURGERY 3000
i. Write a query Increase the FEES by 200 for all patients whose
WARD is
SURGERY.
ii. Write a query to delete all the rows from the HOSPITAL table
whose
WARD is NEURO.
Q.7 a) How e‐Governance has benefited the Common man? 2
76
KENDRIYA VIDYALAYA SANGATHAN,
BANGALORE REGION
SESSION ENDING EXAMINATION – 2014
INFORMATICS PRACTICES – (065) Marking
Scheme
Max Marks : 70 CLASS : XI TIME : 3 Hours
7
7
Each correct solution carry 3 mark. Deduction of marks is based on
d) syntax error and 6
logical errors.
e) The answer is 31 for Java compiler and 1 mark for correct answer 1
Correct definition 1 mark. For each type out of possible 3 types of
b) java comments ½ 2
marks.
SECTION-A
1. Answer the following questions :
a. Define each of the following:
(a)
Nibble (b) Byte (c) Kilo Byte (d) Giga Byte 2
State the basic units of the computer. Name the subunits that make up the CPU, and give the
b. function of each of the 2
units.
c. Differentiate between the compiler and interpreter. 2
d. What is a computer virus? How can it affect your computer? 2
e. Expand the following terms : 2
a) PDAs b) MICR c) DVD d) TFT
Which Graphical controls of JAVA can used to display multiple choices out of which more than one
2. a. can be selected? 1
Suppose you want to scan your storage devices attached with your computer for virus infection .
b. Suggest the type and 1
name of the
software.
c. What is Write Once Run Anywhere characteristics of Java? 2
d. How can you declare the variable in JAVA for the following:- 2
(i) If you want to store the employee no. of an employee.
(ii) If you want to store the name of an employee.
e. What is meant by E-learning. Suggest any two websites which can be used for E-learning. 2
f. What benefits (mention at least 2) does an e-business offer to an organization? 2
3. a. Define the following terms in respect of Relational database management System: 2
(i) Primary Key.
(ii) Foreign Key.
Find the errors from the following code segment and rewrite the corrected code underlining the
b. correction made. 2
int a ,b;
c = a + b;
for(;i<=5;i++)
{
Display c;
c=c+1
]
Rewrite the following code using do-while
c. loop. 2
For(int x=0;x<10;x++)
{
System.out.Println(x);
}
Design an application that obtains three values in three text fields from user: Principal, Rate of
5. a. Interest, Time. It should 4
then compute and display Simple Interest when Calculate button is clicked. Controls names and
Interface are given below
-
Control Purpose Name
Text Box To accept Principal jTextField1
To accept Rate of
Interest jTextField2
To accept Time jTextField3
To display Simple
Interest jTextField4
80
b.
Write a java code to calculate and print the factorial of an integer stored in variable num. 4
c.
Rajni Raghav works for a Computer Institute. He wishes to create controls on application form
2
for the following functions. Choose appropriate controls from Text Box, Label, Option Button,
Check Box, List Box, Combo Box, command Button and write in the third column :
(i) Write the SQL command to create the above table with constraints. 2
(ii) Insert 2 records with relevant information, in the table student 1
(iii) Display all the records of the table Student. 1
(iv) Delete the Student Whose Roll no is 100. 1
(v) Change the Stream of Student to ‘Computer’ Whose Roll no. is 536. 1
Add one column email of data type VARCHAR and size 30 to the table
(vi) Student. 1
(vii) View structure of the table created by you. 1
(viii) Drop the table Student. 1
(ix) Make the all changes permanently. 1
81
7. Answer the question based on the table given below:
TABLE : HOSPITAL
(c) To list names of all patients with their date of admission in ascending order. 1
(d) To display Patient’s Name, Charges, Age for only female patients.
1
Find Out the Output of Following SQL Command:-
(i) Select COUNT(DISTINCT charges) from HOSPITAL;
82
SESSION ENDING EXAMINATION
INFORMATICS PRACTICES
CLASS XI
MARKING SCHEME
(ALL the answers are suggestive, similar and correct answers may also be considered)
SECTION-A
1. Answer the following questions :
a. Define each of the following:
(a) Nibble (b) Byte (c) Kilo Byte (d) Giga Byte 2
Ans:- Nibble- Collection of 4 bits
Byte- Collection of 8 bits
Kilobyte- Collection of 1024 bytes
Gigabyte- Collection of 1024 Mega Bytes
(1/2 marks each for each correct ans)
b. State the basic units of the computer. Name the subunits that make up the CPU, and give the function of each of the units. 2
Basic Units: 1. Input unit 2. Central Processing unit(CPU) 3. Output Unit 4. Memory.
Ans. The CPU has two subunits : The control Unit(CU) and Arithmetic logic unit(ALU).
The control unit controls the entire operation being carried out.
The ALU performs the arithmetic and logical operations.
2 marks for the correct answer.
c. Differentiate between the compiler and interpreter. 2
Ans. An interpreter converts and executes HLL program code into Machine language code line by line where as Compiler
converts an HLL program into object program(Machine Lang.) in one go and once the program is error free, it can be
executed later.
2 Marks for the correct answer.
d. What is a computer virus? How can it affect your computer? 2
Ans. Computer viruses are malicious codes/programs that cause damage to data and files on a system. Viruses can attack any
part of a computer. It can effects as (a) Worms : A worm is a self-replicating program which eats up the entire disk space or
memory. (b) Trojan Horses: A Trojan horse is a program that appears harmless but actually performs malicious functions
such as deleting files.
2 Marks for the correct answer.
e. Expand the following terms : 2
a) PDAs b) MICRc) DVD d) TFT
Ans. PDA :Personal Digital Assistants .
MICR : Magnetic Ink Character Reader / Recognition
DVD : Digital Video Disk
8
3
TFT : Thin Film Transistor
½ Mark each for each correct expansion
2. a. Which Graphical controls of JAVA can used to display multiple choices out of which more than one can be selected? 1
jCheckbox .
Ans. 1 Mark for correct answer
b. Suppose you want to scan your storage devices attached with your computer for virus infection. Suggest the type and name 1
of the software.
Ans. Antivirus – MCaffe , Avast, AVG etc.
1 Mark for correct answer
c. What is Write Once Run Anywhere characteristics of Java? 2
Ans. The Java programs need to be written just once, which can be run on different platforms without making changes in the
Java program. Only the Java interpreter is changed depending upon the platform.
This characteristic is known as Write Once Run Anywhere.
(2 marks for complete answer )
d. How can you declare the variable in JAVA for the following:- 2
(iii) If you want to store the Employee no. of an employee.
(iv) If you want to store the name of an employee.
Ans. (i) Int employeeno;
(ii) String name;
1 mark each for each correct declaration.
e. What is meant by E-learning. Suggest any two websites which can be used for E-learning. 2
Ans. E-learning is a flexible term used to describe a means of teaching and learning through technology such as a network,
browser, CDROM or DVD multimedia platforms.
Two websites : www.moodle.org, www.w3schools.com
1 Mark for defining e-learning
½ Mark each for each correct website.
f. What benefits (mention at least 2) does an e-business offer to an organization?. 2
Ans. The benefits an e-business offer to an organization are:
1. Provides convenience and comfort for customers.
2. Offers opportunity to access new markets across the globe.
1 Mark each for each correct benefit.
3. a. Define the following terms in respect of Relational database management System: 2
(iii) Primary Key.
(iv) Foreign Key.
Ans. (i) A Primary Key is a set of one or more attributes that can uniquely identify tuples within the relation.
(ii) A column in the current table that is a primary key in another table (Master Table) is known as foreign key.
1 Mark each for defining each of the key correctly
b. Differentiate between DEFAULT and CHECK constraint of table with example. 2
Ans. DEFAULT Constraint CHECK Constraint
Default constraint is used to set a default value for a Check constraint is used to check the valid values for a
column that may be used when no value is inserted by the column.
user for that column.
Ex – Ex –
Create table student ( Create table student (
Gender char(1) Default ‘M’); Sal decimal(6,2) check (sal>=2000 and sal<=5000));
1 mark for correct difference
½ mark each for correct example of each.
8
4
c. What will be the output of following code? 2
(iii) SELECT LOWER(CONCAT(‘Informatics’, ’Practices’));
(iv) SELECT INSTR(‘INFORMATICS PRACTICES’,’OR’);
Ans. (i) informaticspractices
(ii) 4
1 Mark each for each correct output.
d. Difference between DDL and DML commands of SQL with example. 2
Ans. Data Definition(Description) Language Subset of SQL commands that are used to describe various objects of
database.(Example: CREATE/ALTER)
Data Manipulation Language Subset of SQL commands that are used to manipulate data in tables.(Example:
SELECT/INSERT/DELETE/UPDATE)
1 mark for correct difference
½ mark each for correct example of each.
e. Rahul wants to create a table STUDENT which can store Roll number, name, address and percentage in SQL. Write the 2
command to create the table STUDENT (Decide the type and size of column on your own).
Create table STUDENT(Rollnumber integer, name varchar(15), address varchar(30), percentage decimal(3,2));
Ans. 2 Marks for correct answer.
SECTION-B
4.A Give the value of x after executing following Java code. 2
int a=10;
int b=12;
int x=5;
int y=6;
while (a<=b)
{ if (a%2= =0)
x=x + y;
else
x=x-y;
a=a+1;
}
Ans. 11
(2 marks for correct output.)
b. Find the errors from the following code segment and rewrite the corrected code underlining the correction made. 2
int a ,b;
c = a + b;
for(;i<=5;i++)
{
Display c;
c=c+1
]
Corrected Code:
Ans. int a , b, c;
c = a + b;
for(;i<=5;i++)
{
System.out.println(“”+C);
c=c+1;
} ½ mark each for finding any 4 errors.
85
c. Rewrite the following code using do-while loop. 2
For(int x=0;x<10;x++)
{
System.out.Println(x);
}
c. Rajni Raghav works for a Computer Institute. He wishes to create controls on application form for the 2
following functions. Choose appropriate controls from Text Box, Label, Option Button, Check Box, List Box,
Combo Box, Command Button and write in the third column:
8
7
S.No. Function / Purpose of Control Control
1 Enter Applicant Name
2 Enter Gender
3 Enter Course from a List of choices
4 Submit Form
SECTION-C
6. Answer the question based on the table given below:
TABLE : Student
(x) Write the SQL command to create the above table with constraints. 2
(xi) Insert 2 records with relevant information, in the table student 1
(xii) Display all the records of the table Student. 1
(xiii) Delete the Student Whose Roll no is 100. 1
(xiv) Change the Stream of Student to ‘Computer’ Whose Roll no. is 536. 1
(xv) Add one column email of data type VARCHAR and size 30 to the table Student. 1
(xvi) View structure of the table created by you. 1
(xvii) Drop the column Grade from the table Student. 1
(xviii) Make the all changes permanently. 1
Ans. (i) create table student(Roll_No integer(4) primary key, Name varchar(20) NOT NULL,
Stipend integer(7) Check Stipend>0, Stream varchar(15) NOT NULL,Grade varchar(1));
2 marks for correct answer.
(ii) (a) insert into Student values(100,’Vishal Mishra’,1000, ‘Science’,’A’);
(b) insert into Student values(101,’Arvind Verma’,2000, ‘Science’,’A’);
(iii) select * from student;
(iv) delete from Student where Roll_No=100;
(v) update Student set Stream=’Computer’ where Roll_No=536;
(vi) alter table Student add(email varchar(30));
(vii) desc[ribe] Student;
(viii) Drop table Student;
(ix) commit;
1 mark each for each correct answer from part (ii) to (ix)
88
7. Answer the question based on the table given below:
TABLE : HOSPITAL
(e) To list the names all the patients admitted after 15/01/98. 2
(f) To list the names of female patients who are in ENT department.
2
(g) To list names of all patients with their date of admission in ascending order. 2
2
(h) To display Patient’s Name, Charges, Age for only female patients.
Ans.
(a) SELECT name FROM hospital WHERE DatoFadm > ‘15-jan-1998’;
II. 16
89
SESSION ENDING EXAMINATION
CLASS – XI
SUBJECT : INFORMATICS
PRACTICES (065)
Note :
Section – A
Q1- Answer the following questions :
2
a) Explain the various function of ALU? M
b 2
) Differentiate between Compiler and Interpreter? M
What do you understand by Application Software? Write
c) the name of any one
2
application software? M
d Write the function of 2
) following : M
(i) Address Bus (ii) Control Bus
What is computer virus? What are its preventive 2
e) measures? M
1
a) What is DBMS? M
b 1
) What do understand by Candidate Keys? M
What do you understand by Degree and Cardinality 2
c) of a table? M
9
0
d 2
) What are the advantages of using a DBMS? M
Define ROUND() and TRUNCATE() function with 2
e) example? M
2
f) Define the function CONCAT()? M
g 1
) What is database? M
Section – B
Property
Controls Name Property Value
JRadioButton1 Text Fahrenheit to Celcius
buttonGroup buttonGroup1
9
1
buttonGroup buttonGroup1
JTextField1 Text txtTemp
Variable Name
JTextField2 Text txtCon
Variable Name
JButton1 Text Convert
Variable Name btnDisc
JButton2 Text Clear the text
Variable Name btnClear
JButton3 Text Exit
Variable Name btnExit
On the Action event of the Clear button the text fields and 2
(i) radio buttons get clear. M
(ii On the Action event of the Exit button the application gets 2
) closed. M
(iii) On the Action event of the button “Convert” the temperature is
converted as per user
3
choice. M
2
c) Rewrite the following code using while loop : M
int sum=0;
for(int i=1; i<=5;i++)
{
sum=sum+i;
}
d) Rewrite the correct code after removing the syntax errors if any in
th
e
fo
llo
wi
ng
co
de
:
2
M
if(sex==1)
JLabel1.setText("Women");
else;
jLabel1.setText("Man");
e) Consider the following program code and tell how many time the
loop will execute : 2M
int x=5,
y=50;
while(x<
=y)
92
{
y=y/x;
x=x+5;
}
Section-C
Siz
Column Name Data Type e Constraint Description
Address of the
Address Varchar 40 Person
(e) Write SQL Commands for the questions form (a) to (h) on the
basis of table
Teacher. [7 X 1M]
Table : Teacher
No Dateojjoi Salar
. Name Age Department n y Sex
2007-02- 1200
1 Jugal 34 Computer 10 0 M
2008-03- 2000
2 Shanti 31 History 24 0 F
2009-02- 1400
3 Sandeep 32 Maths 25 0 M
2007-04- 2000
4 Sangeeta 45 History 15 0 F
2007-05- 2100
5 Rakesh 35 Computer 17 0 M
(i) To show all information about the teacher of
History department in descending order of their
name .
(ii) To list the male teacher who are in Maths department.
(iii) To display Name, Salary, Age of all male teacher.
(iv) Update the Salary by increasing Rs. 1000 for female
teacher.
(v) To Insert a new record in table Teacher with the following
data :
9, ‘Raja’, 23, ‘Hindi’, ‘2005-08-19’,12675, ‘M’
(vi) Display the name of those teacher whose name started with
alphabet ‘S’;
(vii) To Delete those records where Department is History.
(viii) Write SQL Command to drop the table Teacher.
93
(f) Find the Output of following : [5 X
1M]
Marking Scheme
Question-1
This unit of computer system performs arithmetical and logical
a) operations. In the ALU
addition, subtraction, multiplication, division, and logical
operations or comparisons are
performed.
(2 Marks for correct definition )
b) 1Marks for each correction definition of Compiler and interpreter.
Application Software is a set of program designed for specific users
c) or applications such as
word processing, graphics etc. for ex. MS-Word, MS-Excel etc.
1Marks for correct definition and 1 marks for correct example.
d) 1Marks for each correction definition.
Marks for correction definition of Virus and 1 marks for
e) 1 preventive measures.
Question-2
Marks for correction definition and 1/2 marks for each points (at
a) 1 least 2 points)
Marks for correction definition of e-Learning and 1 marks for
b) 1 correct example :
www.moodle.org, www.w3schools.com
c) 1Marks for correction definition of e-business.
Question-3
a) The database is managed by a software package know as DBMS
1Marks for correction definition of DBMS
If a table has more than such attributes which identify a tuple
b) uniquely, then all such
attributes are known as Candidates keys.
1Marks for correction definition Candidate Key .
Marks for Degree : total number of attributes and 1 marks for
c) 1 Cardinality : total number
of rows.
d) 1/2 Marks for each point (at least four points)
e) 1Marks for Round() function and 1 marks for Truncate().
f) 1Marks for CONCAT() function.
g) 1Marks for correction definition of database.
Question-4
1/2 Marks for correct definition of Syntax error and 1/2 marks for
a) correct example.
1/2 Marks for correct definition of Logical error and 1/2 marks for
correct example.
JFrame is a superclass which provides the basic attributes and
b) behaviors of a window .
1Marks for correction definition
Casting is a form of conversion which uses the cast operator to
c) specify by a type name in
parentheses and is placed in front of the value to be converted. For
example :
Res=(float) total/count.
They are helpful in situations where we temporarily need to treat a
value as another type.
1Marks for correction definition and 1 marks for its use.
d) 2Marks for correction definition of container class.
(i
e) ) int sum, a ;
(ii
) a=1;
(iii) sum=sum+a; or sum+=a;
(1 Marks for each correct statements)
Question-5
a) (i) It is a.
It is b.
95
It is c.
(ii) It is c.
(iii) It is d.
(iv) Not a, b, c, d .
(1/2 for each correct output)
b) Event on Clear button :
jTextField1.setText("");
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);
jTextField2.setText(""); (1/2 marks for each
correct coding)
Event on Exit
Button :
System.exit(0);
(2 Marks for
statement). Event
on Convert Button :
int t = Integer.parseInt(txtTemp.getText());
if(JRadioButton1.isSelected()==true)
{
if(JRadioButton2.isSelected()==true)
{
float
F=1.8*(t+32)
txtCon.setText(“”+
F);
}
1 1/2 marks for each correct output.
c int sum=0, i=0;
while(i<=5)
{
sum=sum+i;
i=i+1;
}