IX - Computer Applications - Promotional Exam Notes

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

IX – CTA - Summary of Promotional Exam Syllabus

Note: refer Textbook for examples wherever required.

1. Types of Java Programs: Applications and Applets.


2. Stand alone application : this type of programs are written to carry out specific tasks on a
stand-alone local Computer.
3. Applet programs :are used in internet applications. The java applet will be placed on the
web by embedding into a HTML file.
4. Source code is the set of instructions and statements written by a programmer using a
computer programming language
5. Object code is produced when an interpreter translates byte code into executable
machine code.
6. Byte code is program code that has been compiled from source code into low-level code
designed for a software interpreter. It may be executed by a virtual machine (such as a
JVM) or further compiled into machine code.
7. Features of Java: Simple language, compiled and interpreted, robust and secure, platform
independent, Architecture neutral, Distributed, Multithreaded, Object Oriented, Garbage
collection etc.,
8. Java solves the problem of platform independence by using byte code.
9. Procedural Oriented Program organizes the program around its code.
10. Object Oriented Program organizes the Program around its data.
11. A software object maintains its state in one or more variables.
12. A software object implements its behavior with methods.
13. An object is called an Instance of a class.
14. During program execution one object passes and receives information from another
object using member functions. Such process is called Data messaging.
15. The two primary benefits of encapsulation are Modularity and information hiding.
16. One of the main advantage of inheritance is any data member can be reused without
defining.
17. An object factory is a producer of objects.
18. A class is a set of objects that have common structure and common behavior.
19. An object is identified by its attributes.
20. An object is a software bundle of variables and related functions.
21. A class is a blueprint or prototype of objects. Group of objects form a class. A class
defines variables and methods common to all the objects.
22. Abstraction is to represent essential features of a system without getting involved with
the complexity of the entire system.
23. Encapsulation is the mechanism that binds code and data together it manipulates. Two
primary benefits of encapsulation are modularity and information hiding.
24. Polymorphism allows two or more classes to respond to the same message in different
ways.
25. Inheritance is the process by which one object acquires the properties of another object.
The class whose property is acquired is called BASE class. The class in which the
property of BASE class is acquired is called DERIVED class.
26. Software objects interact and communicate with each other using messages, messages
are passed as parameters using the function.
27. System.out.print () - displays the result and the cursor remains in the same line.
28. System.out.println () - displays the result and the cursor moves to the next line.
29. Every individual unit in a program is called a Token.
30. White space is a space between two tokens. It is also called as a tab, space or newline.
31. Keywords are reserved words that convey special meaning to the compiler.
32. Identifiers are the names given to various data items in a program such as variables,
class names, function/method names, object names.
An identifier can start with an alphabet (uppercase or lowercase).
An identifier can have only $ and _ as special characters.
An identifier can numbers between or at the end of identifier.
No blank space allowed while naming the identifier.
33. Java keywords must not be used for naming the identifiers.
34. A comment is a remark from the programmer to explain some aspect of the code to
someone who is reading the source code.
Types of comments: Single line, multi-line and documentation comments.
35. Separators are used as punctuation marks in a program such as ;(semicolon) to end the
java statement, comma(,) to separate variables etc.,
36. Constants or literals are the data items which does not change their values during the
execution of the program. The different types of constants are Integer, Floating point,
Character, String, and Boolean literals.
37. A data type is a set of possible values that a variable can hold. It is classified into
Primitive and composite. Primitive datatypes are already inbuilt in java and the size is
fixed. Composite datatypes are created by the user using primitive datatypes and the size
is unfixed. Eg: class, arrays, String, wrapper classes.
The various size and ranges of different primitive data types are shown below:-
Data type Size in bits Size in bytes Range
byte 8 bits 1 byte -128 to +127 or -27 to 27-1
short 16 bits 2 bytes -32768 to +32767 or -215 to 215-1
int 32 bits 4 bytes -231 to 231-1
long 64 bits 8 bytes -263 to 263-1
float 32 bits 4 bytes -3.4 x 10-38 to3.4 x 1038
double 64 bits 8 bytes -1.7 x 10-308 to 1.7 x 10308
char 16 bits 2 bytes 0 to 65536
8 bits, but
boolean 1 byte true or false
uses 1 bit
38. A variable is a named memory location to store values.
39. Declaration of a variable is the data type followed by the name of a variable.
40. Initialization of a variable is nothing but storing values using assignment operator =.
41. Dynamic initialization of a variable means assigning values during the execution of
the program.
42. Java character set is a 2-byte character code set. It can represent 65536 characters,
which means almost all human alphabets and writing symbols around the world can be
represented which is called as Unicode character set.
43. ASCII character set is a 1 byte character code set, it can represent only 128 characters.
The various ASCII values range are ‘A’-‘Z’(65-90), ‘a’-‘z’(97-122), ‘0’-‘9’(48-57).
44. An operator is a symbol used to perform specific operation on operands.
45. Operators are classified into Unary, Binary and Ternary Operators.
46. Operators that holds two operands are called Binary Operators.
47. Operators that hold only one operand are called Unary Operator.
48. Operator that holds three operands is called Ternary operator.
49. Arithmetic operators (Binary operators) are used to perform arithmetic operations on
two or more variables (operands) or values. The symbols used are + (Addition),
- (Subtraction), * (multiplication), / (division, returns quotient as output), % (Modulo),
returns remainder as output). The result of these operators will be either integer, or
float, or double data type.
50. Relational operators are used to check the relationship between two operands.
Symbols used are < (less than), > (greater than), <= (less than or equal to), >= (greater
than or equal to), = = (equal to),!= (Not equal to). The result of these operators is a
boolean value either true or false.
51. Logical operators are used to check the relation between two or more relational
expressions and give the result in boolean data type. The symbols used are && (AND), ||
(OR) ! (NOT),
52. Unary operators are the operators that hold only one operand. The symbols are +
(Unary plus which indicates it is a positive value. It is also used to promote the value
to int if it is in byte or short or char), -(Unary minus indicates the number is negative),
++(Increment), --(Decrement).
53. Logical NOT ! operator is also called as unary operator as it works on single operand.
54. Assignment operators are used to assign values to variables during compilation or
execution of the program. The different types of assignment operators are simple
assignment (=), compound assignment (a=b=c=d=value;) where all the operands
should be of same data type), complex or short hand assignment (+=, -=, *=, /=, %=).
55. Ternary operator (conditional operator) is used to replace if else statements. It contains
three expressions. The symbols used are ? and :
56. An operator between two operands is called infix notation.
57. An operator present before the operand is called prefix notation.
58. An operator present after the operand is called postfix notation.
59. Expression is the combination of operators and operands. It can be pure expression,
mixed expression, complex expression or logical expression.
60. In pure expression all the operands in an expression belongs to the same data type.
61. In Impure expression all the operands or any one operand belongs to different data type.
62. In complex expression there is more than one operator.
63. Logical expression results to true or false.
64. Operator precedence/hierarchy determines the order in which operands are executed in
an expression based on the priority given to the operator associated with it. [Note: learn
the priority order table given in the text book]
65. Operator associativity determines the order of evaluation either from left to right or right
to left, when more than one operator has the same priority.
66. The process of converting one primitive type to another is called type conversion. The
two types of conversion are Implicit or widening or Automatic or COERCION and
Explicit conversion or Narrowing or type casting.
67. Implicit conversion is the conversion of one primitive type to another compatible
primitive type done by the java compiler without programmer’s intervention.
68. Explicit conversion is the conversion from one primitive type to another type using type
cast operator ( ) done by using programmer’s intervention.
69. Conditions of Implicit conversion are: (1) Source and destination data types are
compatible. (2) The destination type is larger than the source type.
70. Conditions of Explicit conversion are: (1) Source and destination datatypes are
incompatible. (2) The destination type is less than the source type.
71. Escape sequence or Non-graphic characters are used in java to format the output.
\n→new line, \t→ tab space, \” prints double quotes, \’ prints single quote, \\ prints a
slash(\).
72. final keyword is used to define the value of a variable always constant throughout the
program. Example: final int a=10;
73. There are two types of flow of control: (1) Normal flow of control-which executes
74. Statements in a sequential order. (2) Conditional flow of control-which executes
statements based on the condition given by the user in the program.
75. Selection construct is also known as Decision –making statements. In this construct a
statement or set of statements is either executed or skipped depending upon the test
condition. Execution of selected set of statements is maximum once.
76. An if statement tests a particular condition; if the condition evaluates to true, a course-of-
action is followed i.e. a statement or set-of-statements is executed. Otherwise (if the
condition evaluates to false), then course-of-action is ignored.
77. Multiple statements placed within curly braces form a compound statement.
78. A nested if is an if that has another if in its if’s body or in its else’s body. The nested if
else statement introduces a source of potential ambiguity referred to as dangling-else
problem. This problem arises when in a nested if statement, number of if’s is more than
the number of else clauses. The question arises, which if does the additional else clause
property matchup.
For instance
if (ch>=’A’)
if (ch<=’Z’)
System.out.println (“Upper Case”);
else
System.out.println(“others”);
The indentation in the above code fragment indicates that programmer wants the else to
be executed with the outer if. However, java matches else with the preceding unmatched
if. In this case, the actual evaluation of the if-else statement is if the inner condition is
false then prints “others” which is the logical error. This problem can be solved by
placing the statements within a pair of curly { } braces.
if (ch>=’A’)
{
if (ch<=’Z’)
System.out.println (“Upper Case”);
}
else
System.out.println (“others”);
79. Java provides a multiple-branch selection statement known as switch. This selection
Statement successively tests the value of an expression against a list of integer or
character constants. When a match is found, the statement associated with that constant
are executed until the break statement or the end of switch statement is reached. The
default statement gets executed when no match is found. If the control flows to the next
case below the matching case, in the absence of break, this is called fall through. The
default statement is optional and if it is missing, no action takes place if all matches fail.
Features of switch statement:
1.It can only work for equality expressions.
2. No two case constants can have identical values.
3. It works only with byte, short, int, long, char, String and boolean data types.
4. It executes faster than if else if statements and it is more efficient.
5. We can have nested switch statement. i.e. a switch statement within another switch
statement.
80. The number of times the statements gets executed till the termination condition is met is
called a loop. It is classified into (1) definite loop and (2) Indefinite loop.
81. Definite loop executes for the fixed number of times. Example: for loop.
82. Indefinite loop executes as long as the user wants. Example while and do while loop.
83. In Iteration or looping construct a statement or a set of statements are executed
repeatedly until the test condition becomes false. Execution of selected set of statements
can be more than once.
84. while loop is an entry controlled loop, which checks the condition in the beginning. The
variations in while loop are empty loop and infinite loop.
85. do while loop is an exit-controlled loop, which checks the condition after executing the
loop body. Do while executes the loop body atleast once without checking the condition.
The variations in do while loop are empty loop and infinite loop.
86. for loop is also an entry controlled loop. In for loop the initialization, condition and
updation are grouped together in one place. Execution is faster in for loop than while and
do while loops. The variations in for loop are multiple initialization of variables of same
data type, multiple conditions separated by using logical operators, multiple updation of
counter variables or looping variables, optional expressions (i.e., you can skip either
initialization, or condition or updation or all the three), Empty loop and Infinite loop.
87. Comma separator is used in for loop to separate multiple variables and multiple
updations.
88. Empty loop is loop which has no statements to execute till the given condition is
satisfied. It is also called as time delay loop.
89. Infinite loop is the loop which never stops its execution.
90. Accumulators are the variables which keeps accumulating the values during the
execution of a loop. Eg: sum=sum+i; // sum is called as accumulator.
91. Counters are used in the loop, to count the number of times the loop runs.
92. The Jump statements in java are used to transfer the control from one part of the program
to the other part. There are three jump statements such as break, continue and return.
93. break statement is used to exit from the switch block. It is also used to exit from the loop,
without going to the next iteration.
94. continue statement is used to force early iteration in a loop, by not executing the
remainder part of the loop.
95. The java.lang.System.exit() method exits current program by terminating running Java
virtual machine. Eg: System.exit(0);
Syntax of all the concepts covered in the syllabus

Concept Syntax [or] General Form

Single line comment //……………………………..

Multiple line comment /*…………………..

…………………….. */

Documentation comment /**………………………….

…………………………………

…………………………*/

Variable declaration Datatype variablename;

Multiple variable declaration Datatype variable1, variable2,……………variable

Variable initialization Datatype variable;


variable=value;

[or]

Datatype variable=value;

Multiple variable initialization Datatype variable1, variabl2,……………..;

Variable1=value;

Variable2=value;

……..

Variable=value;

Prefix or preincrement and --var;


predecrement
++var;

Postfix or postincrement and Var--;


postdecrement
Var++;

if statement if(condition)
{
statements;
}

if else statement if(condition)


{
statements;
}

else

Statement;

Nested if statement if(condition)


{

if(Condition)
statements;
}

if…else if statement if(condition)


{
statements;
}

else if(condition)
{
statements;
}

……….

else
{
statements;

switch statement switch(expression)


{
case label1:

statements;
break;
.

case labeln:

statements;

break;
default:

statement;
}

Ternary Operator Var=expression1?expression2:expression3;

while statement while(expression)


{
statements;
}

do while statement do
{
statements;
}while(expression);

for statement for(initialization; condition; updation)


{
statements;
}

Explicit Type conversion or Var=(datatype)(var or expression);


Typecasting

Common Syntax Errors with their description

Sl.No Example Error Name

1 int a=10 Statement missing ;

2 int a=1, a=1; Multiple declarations for a

3 int x=12.3; Possible loss of precision. Required int


found double

4 int x; System.out.println(x); Variable x might not have been


initialized.

5 if(a>b); else without if because if condition is


System.out.println(a); terminated by semicolon.
else

System.out.println(b);

6 System.out.println(a); Cannot find symbol a

7 system.out.println(10); Package system does not exist.

8 String s="Hello; Unclosed String literal.


9 class Sample Expected {
void display(){ } }

Common Runtime error or exceptions

Sl.No Example Error Name

1 int x=10, y=0; ArithmeticException-Divide By Zero. A


int z=x/y; Number cannot be divided by zero.
System.out.println(z);

2 In Scanner Class: During the execution, if the user enter


System.out.println("Enter an any other value other than integer, then
integer"); it raises the error as
int a=sc.nextInt(); InputMismatchException

3 System.out.println(Math.sqrt(-4)); NaN(Not a Number) Runtime error,


cannot find square root of –ve numbers

Note: Logical errors occurs due to wrong logic in the program which needs to be
corrected by the user to get the exact output required by the user.

Example:

if(age>=17)

System.out.println(“Minor”);

else

System.out.println(“Major”);

In the above logic, the messages are printed wrong

Like this many errors can be made by the user depending upon the logic.

Description of all the Java keywords

Keyword Description

byte Represents smallest integer in the range -128 to 127. Its size in bits is 8

short Represents integer value in the range -32767 to 32768. Its size in bits is
16 or 2 bytes.

int Represents integer value in the range -231 to 231-1. It is the default data
type in java among integers. Its size in bits is 32 or 4 bytes.

long Represents integer value in the range -263 to 263-1. Its size in bits is 64 or
8 bytes.

float Represents real numbers with fractional precision in the range


-3.4 x 10-38 to 3.4 x 1038. Its size in bits is 32 or 4 bytes. It is used to
represent single precision numbers.
double Represents real numbers with fractional precision in the range
-1.7 x 10-308 to 1.7 x 10308. Its size in bits is 64 or 8 bytes. It is used to
represent double precision numbers.

char Represents characters found in all the human languages which is called
Unicode in the range 0 to 65, 535. It also represents standard set of
characters known as ASCII in the range 0 to 127. Its size in bits is 16 or 2
bytes.

boolean Represents logical values true and false. Java reserves 8 bits, but uses
only 1 bit. 1 represents true value and 0 represents false value.

final Used with variables to represent their value as constant. It cannot be


changed during the runtime/ compile time of the program.

void Indicates the method/function doesn’t return any value.

if Used to make decisions in java.

else Used as alternative to if when the condition is false.

switch Used to test the value of the given variable or expression against a list of
case values.

case To represent labels/constants in a switch block.

default Gets executed when none of the case labels/constants matches with the
input.

break Used to exit from switch block or loop.

continue Used to force early iteration in for loop. When used in while and do while
block, the control gets transferred to while expression.

import To access/call the classes present in the package.

while It repeats the block of statements while the expression that controls is
true.

do It executes the block of statements, then checks the while expression.

for It is also a looping statement, used mainly for pre-determined number of


iterations.

class It is the fundamental building block of the Object Oriented Programming.


It encapsulates code(methods/functions) and data.
Chapter 6 (Java Scanner Class)

Scanner class: The Scanner class is a class in java.util, which allows the user to read
values of various types. The Scanner looks for tokens in the input. A token is a series of
characters that ends with what Java calls whitespace. A whitespace character can be a
blank, a tab character, or the end of the line. Thus, if we read a line that has a series of
numbers separated by blanks, the scanner will take each number as a separate token.
Numeric and String Methods

Method Description

byte nextByte() Returns the next token as a byte value (8 bits).

short nextShort() Returns the next token as a short value (16 bits).

int nextInt() Returns the next token as an int value (32 bits).

long nextLong() Returns the next token as a long value (64 bits).

float nextFloat() Returns the next token as a float value (32 bits).

double nextDouble() Returns the next token as a double value (64 bits).

Returns the next token as a boolean value (reserves 8 bits


boolean nextBoolean()
but uses 1 bit, 0 for false and 1 for true)

Finds and returns the next complete token as a string; a


String next()
token is usually ended by whitespace.

Returns the next complete token as a string including


String nextLine() whitespaces; a token is usually ended when the user press
enter key.

Example:

import java.util.*;
class sccanner1
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter an integer");
int a=sc.nextInt();
System.out.println("Enter a float value");
float b=sc.nextFloat();
System.out.println("Enter a double value");
double c=sc.nextDouble();
System.out.println("Enter a long value");
long d=sc.nextLong();
System.out.println("Integer value "+a);
System.out.println("Float value "+b);
System.out.println("double value "+c);
System.out.println("long value "+d);
}
}

import java.util.*;
class sccanner2
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String a=sc.next();//reads characters until first whitespace
System.out.println("Your name is "+a);
}
}

import java.util.*;
class sccanner3
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your name");
String a=sc.nextLine();//reads characters including whitespaces till the user press
//enter key.
System.out.println("Your name is "+a);
}
}

Chapter 7 Mathematical Library Methods(Methods of Math class)


It is used to perform various mathematical operations such as finding square root,
power, logarithm etc.,

Methods:

➢ int/long/float/double abs(int/long/float/double) - Returns the absolute value of


the argument. [It converts the negative to positive]
Example:
System.out.println (Math.abs(-5)); //Output: 5
System.out.println (Math.abs(-5.5f)); //Output: 5.5
System.out.println (Math.abs(-123.456)); //Output: 123.456
➢ int/long/float/double max(argument1, argument2) - Returns the maximum value
among the arguments.
Example:
System.out.println (Math.max(1,4)); //Output: 4
System.out.println (Math.max(1.2f,8.6f)); //Output: 8.6
System.out.println (Math.max(45.6, 89.90)); //Output: 89.90
System.out.println (Math.max('a','A')); //Output: 97

➢ int/long/float/double min(argument1, argument2) - Returns the minimum value


among the arguments.
Example:
System.out.println (Math.min(1,4)); //Output: 1
System.out.println (Math.min(1.2f,8.6f)); //Output: 1.2
System.out.println (Math.min(45.6, 89.90)); //Output: 45.6
System.out.println (Math.min('a','A')); //Output: 65
➢ double sqrt(int/float/double) - Returns the square root value of the argument.
Example:
System.out.println (Math.sqrt(4)); //Output: 2.0
System.out.println (Math.sqrt(25.0f)); //Output: 5.0
System.out.println (Math.sqrt(625.0)); //Output: 25.0

Note: square root of a negative number results to NaN (Not a Number)

➢ double cbrt(int/float/double) - Returns the cube root value of the argument.


Example:
System.out.println (Math.cbrt(27)); //Output: 3.0
System.out.println (Math.cbrt(-512)); //Output: -8.0
➢ double pow(argument1, argument2) - Returns the result of argument1 raised to
argument2.
Example:
System.out.println (Math.pow(1,2)); //Output: 1.0
System.out.println (Math.pow(1.2f,3.4f)); //Output: 1.858729975419798
System.out.println (Math.pow(2.3,4.5)); //Output: 42.43998894277659
System.out.println (Math.pow('a', 2)); //Output: 9409.0
➢ double ceil(int/float/double) - Returns the value greater than or equal to the
argument.
Example:
System.out.println (Math.ceil(4)); //Output: 4.0
System.out.println (Math.ceil(4.2f)); // Output: 5.0
System.out.println (Math.ceil(5.0)); // Output: 5.0
System.out.println (Math.ceil(5.3)); // Output: 6.0
System.out.println (Math.ceil(-1.2)); // Output: -1.0
➢ double floor(int/float/double) - Returns the value lesser than or equal to the
argument.
Example:
System.out.println (Math.floor(4)); //Output: 4.0
System.out.println (Math. floor (4.2f)); // Output: 4.0
System.out.println (Math. floor (5.0)); // Output: 5.0
System.out.println (Math. floor (5.3)); // Output: 5.0
System.out.println (Math. floor (-1.2)); // Output: -2.0
➢ int/long round(float/double) - Returns the rounded value of a number from .5 and
above.

Example:
System.out.println (Math.round(5.6f)); //Output: 6
System.out.println (Math.round(4.5)); //Output: 5

➢ double random() - Returns a random number between 0(inclusive) and 1(exclusive)


Example: System.out.println (Math.random()); //Output: 0.3
System.out.println ((int)Math.random()*10); // Output: 4
// returns
To generate any number
random in in
numbers thea range 0 to
specific 9
range. Use the given formula:
Random_number = min + (int) (Math.random ( )* (max-min +1));
Example: To generate random numbers from 5 to 10
int min=5, max=10, rn;
rn= min + (int) (Math.random ( )* (max-min +1));
System.out.println (rn);

You might also like