Class 10 Computer Notes
Class 10 Computer Notes
List of keywords
Import: brings library packages from java library to current working class.
Static: helps user to access class without creating objects. Existing objects will
resume the value of current working objects. Ensure uniformity among
objects.
Extends: new classes can be created using existing classes. Helps in inheritance.
throw : cannot handle multiple exception and throw is used within the
method.
return: indicates pure function. Return is the only jump loop which can give
back value to the main method.
String Buffer: they protect string in the form of object. Strings are non-
mutable and string buffer is mutable. Advanced functions like append ( ),
reverse ( ) can be used with stringbuffers.
Eg: String x=”Presidency”;
String Buffer ob.=new String Buffer(x);
try and catch block: this helps in exception handling. Here try block will
throw an error and catch block will hold and display the error. Catch block
will handle one exception at a time.
Chapter 1
Chapter 2
1. Applet: - programs with browsers.
Stand-alone application: individual programs without any network.
2. Features of java:
1. Highly case sensitive – Upper case is differentiated by lower case
ASCII codes.
2. Follows WORA: - Write Once Read Anywhere
3. Has interpreter and compiler
4. Strongly typed language – data type declaration is a must.
Features of bluej
5. Follows GUI
6. Windows based platform
7. IDE(it is a combination of interpreter, compiler and debugger)
8. Open source.
3. During the process of HLL to LLL / LLL to HLL compilation, Compiler
executes the whole program at once. Interpreter does line by line
compilation.
4. Byte code: Platform independent intermediate language generated by
JVM. JVM is a processor chip.
5. JVM: Java virtual machine.
WORA: Write once runs anywhere. Platform independent
JDK- Java development kit. Makes java a language cum platform.
6. Single line comment: - (// comment) - widely used.
Multi line comment: (/* comment */) – should be closed.
Documentation comment(/** comment */) – should be closed. Used in
jar files.
7. Source code: It is the HLL / program written by programmer.
Machine code/Object code: LLL/ Binary language – understood by
machine.
8. Reserved words- convey special meaning to compiler. Cannot be used as
variables.
9. Package- set of related classes’ forms java package.
Java.lang.* is the default package. Also, the largest package
10. Character set: it is Unicode. It is advanced version of ASCII. It
supports foreign languages too.
ASCII range: A to Z (65 to 90)
a to z(97 t0 122)
System.out.println(‘ ‘); output = 32
3 0 to 9 (48 to 57)
Space – 32
11. Refer 10
12. History of java: Earlier it was named as OAK. Developed by James
Gosling at Sun Microsystems laboratory.
13. Class components: Member methods() , member variables, class
keyword, blocks
14. Class syntax:
class <class name>
{Member variable;
Member methods () { }
}
Chapter III
1. Token: The smallest individual subunit of a class.
Types of tokens:
o Variable , constants, operators, data type, keywords,
punctuators.
2. Literal also known as constant. It gives values to the variable and
remains unchanged.
Identifier : named memory location also known as variable.
LHS=variable
RHS =constant
int a=7;
3. Delimiters: Creates set of java statements and blocks as per
syntax. Deviation results in syntax. error. Eg: ; , . ( ) [ ]
4. Data type allocates memory size as per bits for variables. Types
primitive and reference.
Keyword is a reserved word.
Operator Hirachy : Operators performs operations on variables and
constants. Follows ARL (arithmetic, relational, logical) rule.
5. Escape sequence: Nongraphic characters which creates impact on
terminal window. Should be given inside single or double quotes.
\n – next line
\t – tab space
Bitwise operator: Performs binary arithmetic results in integer
output. Eg: & | ^
6. Primitive – Intrinsic or built in data type. (BSIL , BCFD)
7. Types of initialization:
Static : Assigning null literal or default assignment. (a=7, a=0)
Dynamic: Assigning during run time(c=a+b)
8. Java expression is a valid combination of variable , constant and
operators.
Math expression to java expression syntax: datatype variable =
expression;
9. Type conversion: Conversion of one data type into another is
done by two ways.
Implicit /Type promotion/coercion – done by compiler e.g.: ( 5.0/2
=2.5)
Explicit/Type casting- done by user forcibly. Eg: ( (int)‘A’ )
10. Prefix follows change and use rule e.g.: ++a , --a (unary)
Postfix follows use and change rule e.g.: a++ , a—
11. Single operand receives operation in Unary operator . Eg: ++a, -
-a
Two operands receives operation in binary . Eg: all arithmetic
operators.
12. Ternary /alternative if –else /conditional assignment operators –
acts on 3 operands.
<Data type> <variable> = condition ? true statement: false
statement;
13. Operator is a java token . Expression is a valid combination of
variable constant operator. Types of expression: simple, mixed expression.
14. Refer 10
15. / - quotient % gives remainder . Both are arithmetic operator.
16. = - assignment operator . == relational operator .
17. Refer Math class functions.
Function Input Output Purpose
Math.abs(n) Integer, double Integer, double Returns +ve
value
Math.pow(x,y) Integer, double Double Returns xy
Math.sqrt(n) Integer, double Double Returns ˨n
Math.ceil(n) Integer, double Double Returns round
up value
Math.floor(n) Integer, double Double Returns round
down value
Math.round(n) Integer, double Integer Returns round
off value
Math.rint(n) Integer, double Double Returns round
4.5 = 4.0 off value.
3.5=4.0 Odd
4.6 =5.0 numbers from
3.4=3.0 .5 , even
numbers from
.6
Math.log(n) Integer, double Double Returns
logarithm value
Math.exp(n) Integer, double Double Returns
exponential value
Math.sin(n) Integer, double Double Returns
/cos/tan sin/cos/tan value
Math.asin(n) Integer, double Double Returns angle of
/acos/atan the sin/cos/tan
value
Math.random() Empty parameter Double Returns random
Int numbers
a=(int)Math.random(); between 0.1 to
(0)Double 0.9. lower and
a=Math.random(); upper limits can
(0.1 to 0.9) be set.
() Parentheses
Left to
15 [] Array subscript
Right
· Member selection
Unary post-
++ Right to
14 increment
-- left
Unary post-decrement
Unary pre-
++ increment
-- Unary pre-decrement
+ Unary plus
Right to
13 - Unary minus
left
! Unary logical negation
~ Unary bitwise
( type ) complement
Unary type cast
* Multiplication
Left to
12 / Division
right
% Modulus
+ Addition Left to
11
- Subtraction right
Relational less
than
<
Relational less than or
<=
equal
> Left to
9 Relational greater than
>= right
Relational greater than
instance
or equal
of
Type comparison
(objects only)
Relational is equal
== Left to
8 to
!= right
Relational is not equal
to
Left to
7 & Bitwise AND
right
Left to
4 && Logical AND
right
Left to
3 || Logical OR
right
Right to
2 ? : Ternary conditional
left
Assignment
=
Addition assignment
+=
Subtraction assignment
-= Right to
1 Multiplication
*= left
assignment
/=
Division assignment
%=
Modulus assignment
3. Fall through
The execution of consecutive statements in switch case construct.
This can be avoided by break keyword.
4. Scope of variables
The area within which the user can access member variables. The
variable scope can be modified by access specifiers (public, protected,
private)
5. Testing and debugging
Testing Debugging
Adding more positive Removal of error.
features to the code.
Ensures logical testing Ensures syntax of the
code.
7. Import keyword
Helps user to bring library packages to current working class.
import java.lang is default package.
8. Dangling else condition
Multiple if supported by a smaller number of else results in dangling
error.
Here dangling else by default matches with inner most if. We can
correct dangling if –else error by appropriate use of blocks{}
9. Converting if to switch /ternary to if/if to ternary statements
Refer syntax sheet.
9. What is Operator Associativity?
Ans. Operator associativity of an operator is a property that determines how
operators of the same precedence are grouped in the absence of parentheses;
i.e. in what order each operator is evaluated when two operators of same
precedence appear in an expression.
5. Null loop
Bodyless loop or empty loop.
for(; ;);
6. Infinite loop
Condition always remains true thus the loop never ends. Can be
rectified by update expression /test expression. for(i=1; i<=5; i- -
)
7. Jump statements/loops
Transfers the control structure from one part of the code another part
conditionally or unconditionally. E.g.: break , continue, return
10. Multiple initialization: Helps user to control the loop with multiple
variables. Here multiple variables are separated by comma operator.
Always counters can be replaced by multiple initialization.
E.g.: for(int i=1, j=5; i<6; i++, j+=2)
9. local variable,: The variable scope is limited within the declared method
or construct.
global variable: Variable scope is wide and all member methods can use
global variables. It is declared outside the methods.
10. Recursive functions: function calling itself inside the body is known as
recursive function. Recursive function is generally used with Pure
functions. Here calling and called method will be same.
Factorial using recursion.
public int fact(int n)
{
if(n<
=1)
retur
n 1;
else
return ( n * fact (n-1) ); // here fact( ) function
is called by fact ( ) }
class variable: These are also known as static member variables and there
is only one copy of that variable that is shared with all instances of that
class. If changes are made to that variable, all other instances will see the
effect of the changes.
global : they are also known as class variables. All the member methods
can access.
Maximum variable scope.
local variable: belongs to a particular method or block. Limited variable
scope.
2. Wrapper class
It acts as an outer layer for Primitive data type. Protects the
primitive data type in the form of object.
String functions
String boundary = 0 to length ()-1
Function Format Input Output Description
length() a.length() Empty Int Returns number of
parameter characters in the given
string (counts from position
one)
Trim() a.trim() Empty String Removes the leading and
parameter trailing spaces in the given
string.
charAt() a.charAt(n) Int Char Returns the character at the
nth position
Indexof() a.indexOf(‘m’) Char Int Returns the position of the
(returns -1 if first occurrence of character
search not ‘m’ in the string
found)
Indexof(‘m’,n) a.indexof(‘m’,4) Char, int Int Returns the position of ‘m’
from the nth position
Lastindexof() a.lastIndexOf(‘m’) Char Int Returns the position of last
occurrence of the character
‘m’
Substring() a.substring(n) Int String Returns group of characters
from the nth position
Substring() a.substring(m,n) Int,int String Returns group of characters
from the m to (n-1)
position
Tolowercase() a.toLowerCase() Empty String/char Converts all the characters in
parameter the string ‘a’ to lowercase
Touppercase() a.toUpperCase() Empty String/char Converts all the characters in
parameter the string ‘a’ to uppercase
Equals() a.equals(n) String boolean Checks whether the string
‘a’ and ‘n’ are equal
Equalsignorec a.equalsIgnoreCas String Boolean Checks whether the string
ase() e(n) ‘a’ and ‘n’ are equal
irrespective of the case
compareTo() a.compareTo(b) String Int Compares whether the two
strings are equal or not.
This function can decide on
greater or smaller string.
a>b = positive
a<b = negative, a=b = zero
Example Character.isBoolean(e),Character.isupper(e).(Exception to
3. Out of bound error: When user exceeds a limit of 0 to n-1 range out
of bound error occurs.(n – length of the array). This can be rectified
by lower /upper limits.
Scanner token
nextInt() It receives the next token from scanner object which can be expressed
as an integer
nextFloat() It receives the next token from scanner object which can be expressed
as a floating type of value.
nextLong() It receives the next token from scanner object which can be expressed
as a long type of value
nextDouble() It receives the next token from scanner object which can be expressed
as double type value
next() This method accepts the next token from the scanner object as a
string
nextLine() This method accepts the entire line of text.
boolean Returns true if the next token in the scanner object can
hasNextInt() be interpreted as an int value
boolean Returns true if the next token in the scanner object can
hasNextLong() be interpreted as an long type of value
boolean Returns true if the next token in the scanner object can
hasNextFloat() be interpreted as an float type value
boolean Returns true if the next token in the scanner object can
hasNextDouble() be interpreted as an double type of value
boolean hasNext() Returns true if the scanner object has another token in
its input; false otherwise.
boolean Returns true if the scanner object has another line in its
hasNextLine() input, false otherwise.
Syntax
3. Object creation
Classname objectname =new classname();
7. InputStreamReader Syntax
InputStreamReader object1 = new InputStreamReader(System.in);
BufferedReader object=new BufferedReader(object1);
9. Scanner Class
Scanner objectname=new Scanner (System.in);
10. Try and catch method.
Try
{
Statements;
}
catch(Exception e)
{
Statements; }
If (condition)
True
statement;
Else
if(condition)
true
statement;
else
false
statement;
if(condition)
true
statement;
else
false statement;
}
Else
{
if(condition)
true
statement;
else
false
statement;
}
Iterative construct
Functions
Array
21. Initialization
Datatype variable ={
values}; int
a[]={1,2,3};
Note:
- Refer string and character class functions syntax
If(var==1)
A=1;
Else if(var==2)
A=2;
Else if(var==3)
A=3
Else
A=4;
switch(var) {
case 1:A=1;
break; case 2
: A=2; break;
case 3: A=3;
break;
default: A=4;
}
Class A
{
Public void main() throws IOException, ArithmeticException ,
ArrayOutOfBoundException
{
t
r
y
{
Scanner
}
Catch(Exception ex)
{
}