0% found this document useful (0 votes)
468 views

Class 10 Computer Notes

This document contains definitions and explanations of key Java concepts: 1. It defines keywords like import, void, this, static, new, extends, throw, throws, break, continue, return, read(), readLine(), ISR, BR, StringBuffer, and try/catch blocks. 2. It provides descriptions of core OOP concepts like objects, classes, data abstraction, encapsulation, inheritance, polymorphism, and dynamic binding. 3. It also covers Java features like applets vs standalone applications, bytecode, the JVM, comments, packages, character sets, and the history and components of classes. 4. Programming fundamentals like tokens, literals, delimiters, data

Uploaded by

Dwijesh Donthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
468 views

Class 10 Computer Notes

This document contains definitions and explanations of key Java concepts: 1. It defines keywords like import, void, this, static, new, extends, throw, throws, break, continue, return, read(), readLine(), ISR, BR, StringBuffer, and try/catch blocks. 2. It provides descriptions of core OOP concepts like objects, classes, data abstraction, encapsulation, inheritance, polymorphism, and dynamic binding. 3. It also covers Java features like applets vs standalone applications, bytecode, the JVM, comments, packages, character sets, and the history and components of classes. 4. Programming fundamentals like tokens, literals, delimiters, data

Uploaded by

Dwijesh Donthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Class 10 Theory Notes

List of keywords
Import: brings library packages from java library to current working class.

Void : used in impure function. Void means no return value .

this:- invokes current working object. Helps in resolving variable.

Static: helps user to access class without creating objects. Existing objects will
resume the value of current working objects. Ensure uniformity among
objects.

new: class is known as object factory as it can produce number of objects


using new keyword. Dynamic allocation of memory. It helps in inheritance.

Extends: new classes can be created using existing classes. Helps in inheritance.

throw : cannot handle multiple exception and throw is used within the
method.

throws : can handle multiple exception and it is given with function


signature.

break: terminates inner most loop conditionally and unconditionally.

Continue: skips multiple iterations conditionally and unconditionally.

return: indicates pure function. Return is the only jump loop which can give
back value to the main method.

read() : will accept a character input. ( Syntax : char ch= (char)br.read( );


)

readLine ( ) : will accept a string input. ( Syntax : String x= br.readLine


( ); )
ISR: It is the byte oriented stream. Makes compiler ready for a stream of
input.

BR: buffer is a temporary memory. It creates temporary memory for ISR


object.

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

OOP – Object oriented Programming:

1. Object-oriented programming language. It concentrates on attributes of


an object.
E.g.: car – attributes height, weight / behavior - accelerate (), brake
()
Features: Polymorphism, inheritance, data abstraction, data hiding,
message passing, encapsulation.
2. Object: - A unique entity with certain characteristics and behavior. Set
of related objects creates a class. E.g.: flower
3. Class-is a collection of similar objects form a class. A java program is a
class.
Syntax for creating object: class name object name =new class name
();
Car ob. =new Car ();
4. Data abstraction: Enjoying features of an object without getting into
its complexity. It promotes data hiding. Abstraction displays only the
outer features of an object. E.g.: Enjoying food without knowing
receive.
5. Encapsulation: Wrapping data and code into a single unit. Encapsulation
hides the inner details of an object. It promotes data hiding. E.g.:
hiding electrical wires of a fan.
6. Data hiding provides insulation to data members using access specifies.
Eg: public, private, protected.
7. Inheritance: New objects and classes acquiring properties of existing
objects and classes. New and extends keyword helps inheritance.eg:
parental gene.
8. Polymorphism: Poly means many and morph means one form. This
enables one object to exist in multiple forms. E.g.: Water in 3 states.
9. Dynamic binding: The interconnect between called method and calling
method through parameters. This promotes message passing.
10. The interaction between multiple objects through parameters is called
message passing. It is done through actual and formal parameters.
11. Refer 2
12. Object factory :Class can create multiple objects using new keyword.
Class is a set of related objects.
13. Class is neither primitive nor reference data type. It is created by user
for user. Class is the base type of any object. Class is created by
multiple data types thus class known as composite data type.
14. Instance is a copy. As object acquires properties from parent class,
Object is known as instance.
15. Base class is a parent class or super class. Derived class is a sub class or
child class. New classes acquire the property through extends keyword.
Syntax: class C extends B

When class C extends B, we say that C is a subclass of B, and B is


the super class of C. This is called inheritance, because C inherited
from B.

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)

Type Default Size Example Literals

8 bits( only 1bit


Boolean false true, false
is occupied)

Byte 0 8 bits (none)


\u0000
Char 16 bits 'a', '\u0041', '\101', '\\', '\'', '\n', 'ß'
(0-65535

short 0 16 bits (none)

Int 0 32 bits -2, -1, 0, 1, 2

Float 0.0f 32 bits 1.23e100f, -1.23e-100f, .3f, 3.14F

Long 0l 64 bits -2L, -1L, 0L, 1L, 2L

double 0.0 64 bits 1.23456e300d, -1.23456e-300d, 1e1d

Reference datatype: created by user for user e.g., classes, objects ,


array

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.

18. Operator hierarchy

ARL- It evaluates expression using arithmetic , relational , logical


hierarchy.
Under arithmetic
- Unary is given first preference ,
- binary follows (BEDMAS)rule equal precedence will follow L to R
rule
- ternary

Java Operator Precedence Table

Precedence Operator Type Associativity

() 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

Bitwise left shift


<< Bitwise right shift with
Left to
10 >> sign extension
right
>>> Bitwise right shift with
zero extension

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

Bitwise exclusive Left to


6 ^
OR right

Bitwise inclusive Left to


5 |
OR 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

Larger number means higher precedence.

Chapter IV –Decision Making Statement

1. Types of decision making statements


If –else , switch case
2. Difference between if and switch
If –else switch
Can perform relational , Only equality if tested.
logical , equality test
Can evaluate complex Can evaluate simple
expression with varies expression.
operators

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.

6. Syntax error, logical errors, runtime errors


Syntax- violation of java grammar/cases results in syntax error.
Logical- Inappropriate use of looping or operators results in logical
error. Logical error results in display of wrong outputs.
Runtime – when there is no mathematical solution for an expression
it results in run time error. Square root of negative number = NAN ,
number divided by zero- Infinity.

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.

13. What is a bug? What is debugging?


Ans. An error in a program is called a bug and the process of removing it is
called debugging.

Chapter V- Iterative construct 1. Loop control elements


Initialization expression/initial value
Test expression /final value
Update expression /increment/decrement
Body of the loop

2. For ,while and do while similarity and difference.


For Entry controlled Known iteration
While Entry controlled Unknown iteration
Do while Exit controlled Unknown iteration

3. Exit control and entry control loop.


Entry controlled- Here the test expression is evaluated , then
body of the loop is executed. E.g.: for and while.
Exit controlled- Here the body of the loop is executed then the
condition is tested. Also known as at least once loop. E.g.: do while.
4. Snippet to generate random numbers.
System.out.println(Math.random()) ;

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

8. Time delay loop


It is an empty loop created to keep the
compiler engaged. for( ; ; )

9. Optional expression : Allows user to create loop with or without any


of the loop control elements. for( ; ; )

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)

11. Converting for statement to while statement/while to for Refer


syntax sheet.

Chapter VI –Functions /constructor

1. Need for function: Behavior of an object is represented as function. It


helps in reducing the code length and reuse and recycle existing
methods.
Types of functions: library/Inbuilt functions
(Math/String/Character/Scanner)
User defined function/Defined by user(
Pure/Impure)
2. Function signature : Argument list of function prototype.
Function prototype: Valid combination of access specifier, return type,
function name and argument list. Header line of a function. ( public
void main( int a,int b) )
Public void presidency (int a, String name )
Function Overload: A class can have multiple functions with the same
name but with different argument list. Here compiler resolves the
function not by name but by signature.
Function overload promotes polymorphism.
Constructor overload: A class with multiple constructors with different
signatures is known as constructor overload. User should create multiple
objects to execute constructor overload.
3. Pass by value: Primitive data type is passed by parameters. State of
the object is not disturbed. E.g.: public void add (int a)
4. pass by reference: Reference data type is passed by parameters. State
of the object is disturbed. E.g.: public void add (car ob)
Here an object is passed through parameter.
5. Actual : Present in the main( ) method. Gives value to formal
parameter.
E.g.: public void main( )
{ area(7);}

Formal parameter: Present in the prototype of called method. It is


also known as dummy arguments.eg: public void area( int r)

6. Pure /Accessor/Getter method: - Uses return keyword. State of the


object is not disturbed.
7. Impure function/Mutator/Setter method. Uses void keyword. State of
the object is disturbed.

8. Constructor : A special member function with the same name of the


class. It has no return type not even void. Always associated with
objects.
Function: Has a different name from the class. Will have a return type.
May or may not be associated with objects.

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 ( ) }

11. Types of constructor


Parameterized
Default/non-parameterized.
12. Static data member – ensures uniformity among objects. All the
objects will take the value of the current working object. It refers to
the same memory location shared by multiple objects. Static keyword
enables user to access class without creating objects.

non static: each object will retain individual references. It creates


different memory allocation for multiple objects.
Chapter VII- Encapsulation

1. Types of access specifiers


Public: minimum data hiding , all members can access public members.
Private: maximum data hiding, only class members can access.
Protected: only class members and inherited members can access.\

2. Instance variable: These variables belong to the instance of a class,


thus an object. And every instance of that class (object) has its own
copy of that variable. Changes made to the variable do not reflect in
other instances of that class.

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.

3. Similarity and difference between Private , public , protected.


Class Sub-class package Outside the
class
Public √ √ √ √
Protected √ (only (only x
inherited inherited
subclass can subclass can
access) access)
Private √ x x x
4. Resolving variable
When a class has local and global variable with the same name within
the scope local hides the global variable. This is known as resolving
variable.
To activate global variable ‘this’ keyword is used.(n – local variable ,
this.n- global)

Chapter VIII-Library functions 1. Exception handling in java


Handling unavoidable errors through throw and throws keyword.
throw cannot handle multiple exception and throw is used within
the method. throws can handle multiple exception and it is given
with function signature.

2. Wrapper class
It acts as an outer layer for Primitive data type. Protects the
primitive data type in the form of object.

3. class is known as composite datatype or user defined datatype : It is


defined by user for user . A class is created by multiple data type
elements. Class acts as a base data type for any object.

4. Read All string functions , character function with their syntax ,


input , output, and purpose.(Refer the string functions/math functions
printed list.)

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

Replace() a.replace(‘b’,’c’) Char,char String Replace the occurrences of


the first character with the
second character.
Character class: Most of the character class functions return Boolean output.

Example Character.isBoolean(e),Character.isupper(e).(Exception to

Uppercase() and to Lowercase().) to Uppercase() and to Lowercase() is used

in String and Character Class.

Syntax for string functions = Variable name. Function (argument)( e.g.: x


.to Uppercase(); )

Syntax for character class function: Character. Function ( char variable


)(Character.toUpperCase( e ); )

Chapter IX-Arrays 1. Need for array and types of array.


Combines multiple elements of a single data type. It is a reference
data type. Two types of array are single dimension, double dimension
array.
2. Advantage : simple structure to combine multiple elements of similar
data type. Random or sequential access is allowed.

disadvantage of array: only same data type elements can be grouped.


Careful designing is required otherwise results in out of bound error.

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.

4. Sorting: Traversing through array elements and arranging them in a


required sequential order is sorting.
Searching: Traversing through array elements and finding out position of
a particular element is searching.

merging : combining multiple array into single unit. Append merge ,


alternate merge.
5.
Bubble sort selection sort
The heaviest element is positioned The smallest element is positioned
first in ascending order first in ascending order.
Proves to be time consuming due Consumes less processing time.
to number
of comparisons.

linear search binary search


Can be used for sorted or unsorted Used only for sorted array
array
Proves to be time consuming for Consumes less processing time.
longer arrays.
6.
Subscript subscript variable
Position of an element /index Variable that can hold multiple
similar data type elements.
A[7] Here 7 refers to the position A[ ] is the subscripted variable. ( A
of the element (Only integer in the can be of any primitive data type)
range of 0 to n-1, where n is length
of the array)

Ordinary variable array variable


Can hold one value at a time. Can hold multiple values referred by
various indices.
int p; int p [ ] also known as subscripted
variable.
6.
length Length()
Counts number ofin a Counts number of characters in
elements given the given
array. string.
Array is a group of elements String is a group of
multiple of characters.
same data
type.
Array is reference data String is a derived data
type. type.

7. Byte size of the array : no. of elements * byte size of


base data type Ex: int a[5]
Byte size of the array = 5 x 4 bytes
= 20 bytes
8. Initialization : declaring an array with assigning values for respective
elements.
int a[ ]={ 1,2,3}( array variable ), int a=7; (
ordinary variable) ; instantiation : declaration of
an array. int a[ ] =new int [5]; ( array variable)
, int a; (ordinary variable)

Chapter X-Scanner class

Need for scanner token.

It is a new advancement in java input output streams. User can input


different datatypes without type conversion. Set of library functions are used
to achieve the same.

Scanner token

• The scanner class works on the principle of “Tokens”.


• A scanner token is a series of characters separated by whitespace.
• Some of the delimiters that can be used as token separators are
comma, full stop, semicolon, white space etc.,

• Scanner class use whitespace as a default token separator.


• Java.util package to be imported to use scanner classes.
• An object to the class needs to be created i.e., Scanner sc=new
Scanner(System.in);

Use delimiter : It helps user to change default delimiter to required delimiter.

• To change the default delimiter : Scanner ob=new Scanner(delimiter);


ob.useDelimiter(“*”);

All the tokens in scanner class


Note : There is no scanner token to accept a single character.

Methods to read tokens from scanner class.

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.

Methods of checking(returns boolean output)

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.

Print Writer Class


Alternate method for System.out.print
Syntax: import java.io.*;
PrintWriter object =new PrintWriter(outputstream output, Boolean
flushIfNewline)
Eg: PrintWriter ob=new PrintWriter(System.out.true);

Difference between next() and nextLine(), nextInt() and hasnextInt(), etc.,

next( ): - will accept a single scanner token (a


word) nextLine( ):- will accept a group of
scanner tokens(a sentence)

nextInt ( ) : will accept an integer token . hasNextInt( ): - will


check the validity of input for integer and returns boolean output.

Syntax

Class as basis of all computations.

1. Data type declaration data type variable = expression ;


2. Ternary operator
Data type variable = (condition) ? true statement : false statement;

3. Object creation
Classname objectname =new classname();

4. Extends keywords (out of portion)


New class name extends old class name;
Derivedclass extends baseclass;

5. To refer member variable through objects.


Objectname. Variable;

6. To refer member method through objects


Objectname.method();

7. InputStreamReader Syntax
InputStreamReader object1 = new InputStreamReader(System.in);
BufferedReader object=new BufferedReader(object1);

8. Syntax for read() and readLine() String x = object.readLine(); char x


= (char) object.read();

9. Scanner Class
Scanner objectname=new Scanner (System.in);
10. Try and catch method.

Try
{
Statements;
}
catch(Exception e)
{
Statements; }

Note: Kindly use blocks if we have more than one statement.


Selective construct

11. If else construct If (condition)


True statement;
Else
False statement;

12. Multiple If else construct

If (condition)
True
statement;
Else
if(condition)
true
statement;
else
false
statement;

13. Nested If else construct


If (condition)
{

if(condition)
true
statement;
else
false statement;
}
Else
{

if(condition)
true
statement;
else
false
statement;
}

14. Dangling if If (condition)


if(condition)
true statement;
else // else is matched
with inner most if by default
false statement;

15. Switch construct Switch (


control variable)
{
Case value1:
Statements;
Break; // avoid break in switch case construct will create fall
through error Case value2:
Statements; Break; default: // this
makes the program user friendly by displaying invalid
message.
Statement;
}

Iterative construct

16. For construct for(control variable = initial


value ; test expression ; increment
/decrement value)
{
statements;
}
17. While construct
Control variable =initial value;
While(test expression)
{
Statements;
Increment /decrement value;
}
18. Do - While construct Control variable
=initial value;
do
{
Statements;
Increment /decrement value;
} While(test expression);

19. Labeled loops(Out of portion) A:


System.out.println(“Presidency”); for(i=1
; i<=5;i++)
{ if(i==3) break A;
// A is the user defined label
}

Functions

20. Constructor /Pure /Impure


functions class A
{
public A() //default constructor
{
}
public A(int m) //parametrized constructor
{
} formal parameter

public int ab(int x) // parametrized pure functions


{
Statements;
call by value return(int);
}

public void b() // impure functions


{
Statements;
}

public void main()


{
A ob1=new A();
A ob2=new A(7); //actual parameter System.out.println(ab(8));
//pure function called b(); // impure function is called directly.
Ob1.b();//impure function is called through objects.
}

Array

21. Initialization

Datatype variable ={
values}; int
a[]={1,2,3};

22. Declaration or Instantiation Datatype variable


=new datatype[size]; int a[]=new int[5];

23. Array byte size = byte size of base data type *


length of the array.

Note:
- Refer string and character class functions syntax

ALL THE BEST

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)
{
}

You might also like