Computers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 127

Class 9

COMPUTER
APPLICATION
CONCEPTS RECAPTULATION

▪ Types of memory
▪ Process of booting -BIOS
▪ Operating System role
▪ Programming language
▪ Types of Languages –Binary, Assembly and HLL
And their characterictics /Disadvantages
▪ Translators/Language Processors –Compilers and
Interpreters(differences )
▪ Source code : definition
▪ Object code/Machine code/Binary code
:Definition
Chapter 3
Values and Data types
CHARACTER SET IN JAVA

•Letters
•English alphabet (A-Z,a-z)
•Digits
•0-9
•Delimiters
•Special characters
•Operators
•Arithmetical , logical and relational
▪ public class JavaProgram
▪ {
▪ public static void main(String args[ ])
▪ {
▪ int len, bre, peri, area;//declaring the TOKEN
variables
▪ len=6;
▪ bre=10;
▪ peri=0;
▪ area=0;

▪ area = len*bre;//calculating area
▪ peri = (2*len) + (2*bre);//calculatig perimeter

▪ System.out.print("Area = " +area);//displayig area

▪ System.out.print("\nPerimeter = " +peri);//
▪ }}

TOKEN

▪ Token can be defined as each individual


component of java program in such a way that
it carries some meaning and takes part in
effective execution of the program.
Various types of Token

•Literals
•Identifiers
•Assignment
•Punctuators
•Seperators
•Operators
•Keywords
CHARACTER SET IN JAVA

•Letters
•English alphabet (A-Z,a-z)
•Digits
•0-9
•Delimiters
•Special characters
•Operators
•Arithmetical , logical and relational
Literals(Constants)

▪ Literals are constants in java program.


▪ They do not change through out the program.
▪ Types :
� Integer
� Real
� Character
� String
� Boolean
� Null
•9, 90, 8343974
•Real
•With decimal

•9.089823
•Character
•All alphanumeric

•Enclosed in single quotes


•‘A’
•‘d’
•‘8’
•‘&’

•String
•Set of characters

•Enclosed in double quotes

•“sdhfjdh”
•Hello8989”
•“10% of amount “
•Boolean
•true or false
•Null
Punctuators

Punctuation signs used as special characters


in java.
▪ . Dot :
▪ ; Semicolon:
▪ ? Question mark:
Seperators

▪ Used to separate the variables or the


characters.
▪ Comma: ,
▪ Brackets: ( )
▪ Curly braces: { }
▪ Square brackets: [ ]
Operators

▪ Symbols used to perform arithmetical or


logical operations to yield meaningful results.
✔ Arithmetical operators:
✔ Relationaloperators:
✔ Logical operators:
Keywords

▪ Reserved words
▪ Special meaning in the system compiler
▪ Keywords cannot be used as variable names
▪ Eg:
public
Class
for
System etc
Assignment

=
Various types of Token

•Literals
•Identifiers/Variables
•Assignments
•Punctuators
•Seperators
•Operators
•Keywords
VARIABLE ????
Identifiers(variables)

▪ Also called variables


▪ What is a variable? Named memory location
which contains a value
▪ Value of a variable can change depending
upon the circumstances and problem in the
program.
Declaration

▪ Syntax;
<data type> <space> <var name>;
Eg:
Int a,b,c;
Need to declare the
variable

?
Rules for naming a variable

▪ May have any number of characters


▪ May contain alphabets,digits, and underscore
▪ Underscore can be applied in between the characters
to increase the length of the variable name.
▪ Var name should be meaningful related to the logic
▪ No keyword should be used as variable name
▪ Should not start with digit or special character
▪ Should not include a space in between charaters
Variable initialisation

Static: The variable has been initialized at the


time of declaration
Eg: int c=8;

Dynamic: When the variable is initialized at run


time (during execution) , it is termed as
dynamic initialization
int a=4;
int b=4;
int c=a+b; // dynamic initialization
Questions :
Q1:A constant which gives the exact representation of data is
called
▪ Variable
▪ Literal
▪ Identifier
▪ Character
Question 2:A word used in a high level language which has a
special meaning attached to it is called
▪ Class
▪ Identifier
▪ Keyword
▪ Literal
▪ A character literal is enclosed in___
▪ Each individual component of a Java
statement is known as ____
▪ In Java, the constants are also called____
▪ _____ operator is used to store a value in the
variable.
▪ The comma, exclamation, question mark etc.,
are termed as ________ in Java language.
Answer the following
questions
▪ Define variable with an example.
▪ What do you mean by constant? Explain with an
example.
▪ What do you understand by Token? Name different types
of tokens.
▪ What are the rules to assign a variable in a Java
programming?
▪ Distinguish between:
(a) Integer and floating constant
(b) Token and Identifier
(c) Character and String constant
(d) Character and Boolean literal
DATA TYPE

Data type is a type of value


stored in a variable which is used
throughout a program as a
constant to give meaningful
result
Independent of any other type
dependent of primitive data type

User Defined data types/Composite data types


INTEGER •byte
•Short
--whole number •int
---Without decimal •long
---Both positive and negative

•float
FLOATING POINT •double
---with decimal numbers
Character data type

Letter or digit or ‘c’


special character ‘E’
enclosed in single ‘8’
quotes ‘&’
Declaration:
data type varname=‘value’;
char ch =‘M’;
Char p=‘8’;
Hierarchy of data types

▪ byte
▪ char
▪ short
▪ int
▪ long
▪ float
▪ double
▪ What do you mean by data type?
▪ State two kinds of data types.
▪ What do you understand by primitive data
type? Give two examples.
▪ What do you mean by non-primitive data
type? Give examples.
▪ Why is it necessary to define data type in Java
programming?
▪ What is the hierarchy of data types?
(Y+Z/8)*78
Arithmetic expression????????
x+y
Arithmetic statement?????????
Z=x+y
▪ int a,b,c,d;
d= a+b+c;

int a; float b; double c;


a+b+c;
Arithmetic expression
▪ Which contains variables,constants and
arithmetic operators.
▪ Eg: a= b+c;

Pure Impure/mixed

same datatypes different type of


variables
TYPE CONVERSION

▪ In mixed expression the result should be


obtained in any one form of its data types.
▪ Hence it is needed to convert various data
types into a single type.
▪ Such conversion is termed as TYPE
CONVERSION

▪ Implicit Explicit
IMPLICIT/coersion

In a mixed expression , the data type of the result


is converted automatically into highest data
type available in the expression .
int a; float b; double c;
double d=a+b+c
EXPLICIT/type casting

int a, b;
float c=(float)(a+b);
Resultant datatypes? After
type conversions
int i;
float f; double d;char c; byte b;
a) i+c/d;
b) f/d+c*f;
c) i+f-b*c;
d) (f/i)*c+s;
e) i+f-c+b/d;
f) i/c+f/b;
Escape sequences

▪ They are non-graphic characters


▪ Used as commands to direct the cursor while
printing.
▪ An escape sequence character begins with a
backslash( \ ) and followed by one or more
characters.
▪ Also called back slash characters
System.out.println()

▪ \n - Insert a newline in the text at this point.


▪ \t - Insert a tab in the text at this point.
▪ \' - Insert a single quote character in the text at
this point.
▪ \" - Insert a double quote character in the text
at this point.
▪ \\ - Insert a backslash character in the text at
this point.
▪ System.out.print(“ USA \n “+”Uk \n”);
/* string USA is printed enclosed in the double
quotes and By \n, cursor will go onto the next
line */

Output:
USA
Uk
UNICODE and ASCII code
▪ Fundamentally, computers just deal with numbers.
▪ They store letters and other characters by assigning a number for each
one.
▪ Before Unicode was invented, there were hundreds of different systems,
called character encodings, for assigning these numbers. These early
character encodings were limited and could not contain enough characters
to cover all the world's languages.
▪ Even for a single language like English no single encoding was adequate
for all the letters, punctuation, and technical symbols in common use.
▪ Early character encodings also conflicted with one another. That is, two
encodings could use the same number for two different characters, or use
different numbers for the same character.
▪ Any given computer (especially servers) would need to support many
different encodings. However, when data is passed through different
computers or between different encodings, that data runs the risk of
corruption.
▪ System. out. print(" Want \t to\t learn \t
computers");

/* the string Want to learn computers will be


printed and Each word is separated by a tab */
Output:
Wantto learn computers
▪ The Unicode Standard provides a unique
number for every character, no matter what
platform, device, application or language.
▪ It has been adopted by all modern software
providers and now allows data to be
transported through many different platforms,
devices and applications without corruption.
▪ ASCII is a code for representing
English characters as numbers, each letter of
english alphabets is assigned a number ranging
from 0 to 127
ASCII CODES

•128 characters(0-127)
•0-9 48-57
•A-Z 65-90
•a-z 97-122
Operators and
Expressions in
Java
X=Y+Z+8
operands
variables Constant

X=Y+Z+8
Operators
Arithmetic expression????????
x+y
Arithmetic statement?????????
Z=x+y
ARITHMETIC
EXPRESSION
v/s
JAVA EXPRESSION

Area=2(l+b)
Area=2*(l+b)
▪ Abc
▪ ab-bc+ac
▪ (p*r*t)/100
OPERATORS

Arithmetical logical relational


Arithmetical operators

▪ The operators which are applied to perform


arithmetical calculations in a program are
known as arithmetical operators.
▪ =, - ,* ,/, %
Arithmetic operators

Unary Binary Ternary


UNARY OPERATOR

▪ Operator----applied with single operand.


▪ +, -, ++, --
Unary(+) +a, +9
Unary(-) -a,-7
Unary increment(++) ++a,a++
Unary decrement(--) --a,a--
•Change before action
•Change after action
▪ ++p +5 p=5
▪ a++ + a++ a=48
▪ n=m++*5 + --m m=12
Short hand operations
▪ An expression can be written in short form
▪ a=a+b
a+=b

x=x*2
x*=2
A short hand expression is formed only when a
variable is used as an accumulator to the
expression(same variable before and after
assignment operator.
Arithmetic operators

Unary Binary Ternary


BINARY OPERATORS

▪ An operator deals with deals with two


operands
▪ +
▪ -
▪ /
▪ %
▪ *
TERNARY OPERATORS (
Conditional Assignment
Statement)
▪ Operators dealing with three operands
▪ Syntax:
Variable= (test expression)? Expression 1:
Expression 2;
Ex:
if( a>b)
Ternary operator
{
d=(a-b); d=(a>b)?(a-b): (b-a);
}
else
{
d=(b-a);
Var=test exp?exp1:exp2
}
▪ p=5, q=19
int n =(q-p)>(p-q)?(q-p): (p-q);

If( (a+b)>c)
{
K=15;
S.O.P(k);
}
else {
K=30;
S.O.P(k);
}
NESTING

▪ a,b,c
Relational Operator

▪ Compare two operands and determine relation


between them
▪ Out put : Boolean type : True or false
▪ ==
▪ !=
▪ >
▪ <
▪ >=
▪ <=
LOGICAL OPERATORS

▪ These operators give the relation between two


relational expressions
▪ Output : boolean : true or false
▪ Java supports three logical operators
logical AND &&
logical OR ||
logical NOT !
Logical AND

▪ To compare two or more conditional


expressions

▪ (3>5)&&(7>9)------
Logical OR

▪ To compare two or more conditional


expressions

▪ (3>5)||(7>9)------
LOGICAL NOT !

▪ When you want to reverse the result of an


expression

▪ !(8>9)----
ENCAPSULATION
The concept of hiding
internal details and exposing
external details is called
ABSTRACTION
OBJECT AND CLASSES
STEPS TO CREATE OBJECT

CLASSNAME OBJECT
DECLARATION
NAME

INSTANTIATION

NEW KEYWORD (ALLLOCATING


MEMORY )
INITIALISATION

INITIALISING
VARIABLES
CLASS/OBJECT TERMS

CLASS AS A OBJECT FACTORY


CLASS AS A USER DEFINED DATATYPE
OBJECT AS AN INSTANCE OF A CLASS
DIFFERENCES BETWEEN CLASS AND
OBJECT

You might also like