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

ICSE Class 10 Computer Application Notes

credit to frozen notes site, github and reddit community very helpful check it out https://frozennotes.github.io/ICSE_Resources/computer.html

Uploaded by

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

ICSE Class 10 Computer Application Notes

credit to frozen notes site, github and reddit community very helpful check it out https://frozennotes.github.io/ICSE_Resources/computer.html

Uploaded by

anikashyrebel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
Chapter 1 Object Oriented Programming Concepts e the followin ae ie es Ysa Object:- An object is an identifiable entity with some specific identity , specific is ‘ characteristics and some specific behaviour. Class:- A class is a blueprint that represent a set of objects that share common 2 characteristics and behaviour. Abstraction:- Abstraction refers to the act of representing essential features without including the background details and explanations. Encapsulation:- The wrapping up of data(i.e. characteristics) and functions (i.e. behaviour) into a single unit called class is known as encapsulation. State of an Object:- The state of an object is the value of its characteristics at a - given point of time. Member Variables:- The real world objects are implemented in software form by representing their state through variables or data items called member variables. The value of member variables defines the state of an object. Member Functions:- The behaviour of the object is depicted through functions called methods or member functions. Message Passing:- When the objects need to interact with one another, they pass/ known as message passing. ¥ request information to one another. The interactior Inheritance:- Inheritance is the process in which objects of one class can link and share some common properties of the objects with another class. Base class:- The class whose features are shared is known as base class or supper class. Derived class:- The class that acquire the features of another class is said tobe the Ea derived class or sub class. |. Reusability:- When a class inherits from another class then it may happen that some of the components used in the base class are applied to the derived class for some operations. This feature is said to be the reusability feature which can be implemented through inheritance. _ a 42% Polymorphism:- Polymorphism is the process of using a function for more than one Purpose. It allows the use of different internal structure of the object by keeping the same external structure. 2) How are objects represented in software terms? The object is implemented in software terms as follows: iy ae e f ough membs ‘i ir J = S igh m ; er variables or datal a Bees): 3) 4) pais 6) 7 8) %) Lesson 4 Values and Dato Types aatgn ameter \7 jit or any other SIEM. dig oa ata langue C2 COB aaeet that has characters representing almost all characters in gy Character: A character can be any letter Character Set: character set isa set of Unicode:- Unicode is a two-byte character co human languages around the world Token:- The smatest individual unlt of Types of Token:- Keyword, Identifier, Ler Keywerds: Keyerords are the words that convey & SPS be used for identifier nares Identifiers:- Mentifiers are the fundament parts of the program lke variables, classes Rules for naming identifiers scan have alphabets, digits, underscore and dollar sign, Must not bea keyword or Boolean literal or nul itera. &_ Must not begin witha dat @. Can be of any length Treats uppercase and lower case differentiy(case sensitive) own as token. tis orators is, Punctuators, OP* ror nganing to the language compiler and so they mus, mt programs and are the names given to differ, ent al building blocks of the functions, arrays ete. Which ofthe following are valid or invalid identifiers and why? a astormerPorne, hrmaed b. SMaMath_ mud —= Borie a 2S 4. _Grade, 1d aay ‘ fe. INTEREST_woac f. CheckPalindrome pmb & Myfile_ymbach h. Break i. While_ oli J. _ques, Sees arnt a a m, $10 to_20_smb A 2M Vale ined; Mae mek Ahan ul OGM \ ‘Space_nind A Net amount “ © ay a a x Filed gab - Sy Mia Reeenli ees yg inom a —- . sum+prod. bb. dateofbirth_ pe reuant ‘neh Te THAD ce. 3students_jwwada dd. Total, ee. ft, Lesson 2 Introduction to Java 1) Source Code:- code written by programmer 2) Machine Code:-code that computer can understand 3) Assembler:- transtates code written in assembly language into machine code 4) Interpreter:- converting high level program to machine code instruction by instruction 5) Compilation:-converting source code to machine code 6) Native Executable Code:- machine code that is different for each platform 7) Ordinary Compilation VS Java Compilation:- in ordinary compilation the source code is converted to machine code, which is dependent on the machine or platform. This resultant machine code is called native executable code. The java compiler does not produce a native executable code for a particular machine. Instead it produces a byte code which is exactly same on every platform. Java Byte Code:- machine instruction for java processor chip called java virtual machine (L977 Java Virtual Machine:- abstract machine that hides underlying operating system from java application and executes the java byte code 10) Java as both programming language and a platform: Like any other programming language, we can use java to write or create various types of computer applications. Platform generally is used to refer to some combination of hardware and system software. The java platform is a new software platform designed to deliver and run highly interactive, dynamic and secure applications on networked computer system. 11) Java as platform independent language:- means that Java applications can run on any platform. 12) Java API:- java application programming interface are libraries of compiled codes that can be used in java programs 13) Just-In-Time(JIT) Compiler:- JVM also includes as JIT compiler as it compiles selected portions of Byte Code into executable code. 14) Characteristics of Java:- a. Write Once Run Anywhere(WORA):- java programs need to be written once and can run on different platforms without making changes in the java program. Light Weight Code:- with java big and useful applications can be created with no huge coding Security:- java offers many security features to make its program safe and secure Buil Graphics:- built-in graphic features and routines makes java application more visual Object Oriented Language Supports Multimedia:- java is ideally suited for integration of video, audio, animation and graphics in internet environment Platform Independent . Open Product: freely available to all 15) Types of Java Program:- There are two types of Java programs:- ‘a: Internet Applets:- small program embedded in a web page which runs on viewer's machine in a secured manner Standalone Applications:- program that can run independently without requiring external support seme aoe 2 ue i specific characteristics and some specifg ‘An object is an identifiable entity with some specific identity, spec! behaviour. ae common characteristics and behaviour, ‘Aclassis a blueprint that represent a set of objects that share 5) obj state and behaviour? " : ) see Bet ca ent with some characteristics attributes and beha ee ite a aM objet iapards upon the valve ofits attributes at any glven point of time. Since state and Dehaviour of objec, upon ie ibutes interwoven, they said to encapsulate state and behaviour. ject factory? Ai versace cy coal a te cr ically the class is a Soc wine object its attributes, as well as the statements to describe the operations that the obj perform. : objects are said to be instances of a class : aS Neca a clase defied we can erate as many objects as needed. All these objects materialise the abstract, sy by the class. These objects ae said to be instances of the class. All the instances created with th given class will have the same structure and behaviour. They will only differ regarding their state, 8) State the Java Concepts that is implemented through the followit ‘8. Assuper Class and a sub class 'b, The act of representing essential features without including background details. Answer:- a Inheritance , Data Abstraction be able to 9) Write a Java statement to create an object mp4 of class Digital. Digital mpa=new Digital) 10) What does a class encapsulate? Aclass encapsulate characteristics and behaviour (Data and Functions) 11) Why isa class known as. composite data, type? Classis atool to create user defined. The class name becomes data type for the instances used in the | ee ue that includes various predefined data type within it. Hence, the class is said to 12) In what way data hiding concept is implemented in OOP? A ee and objects encapsulated together. The member. methods of a class can ‘only be able to access members ofthe class, The data members cannot be used outside the class premises even in the same program. in this: ‘way data hiding concept is img plemented, 13) Write a Java statement to create an objet book of class Libra Library book=new Library( ); a - 14) What is the significance of the word ‘new’ while i Creating an object; _ The word ‘new Is uted for dynamic allocation ofthe object ne ny storage of an object. = itallots space in the dynamic memory for b. short {6 bhy a 4. tong:_Gk bike a e fort bi ee f. chars, bile acacia Ne i 8. boolean:_® bat (waaenbg, tat. ») G+ bite 1 of a particular data type. i hat hokdse-dats val 42) Variable:- A variable is 0 named memory location that I Baritone vare 43) Dynamic initialization: tis the secuaseanenverbna by meaner rey #7erererCx ©? nother variable or by returned valve of a called function moty location __ 44) rvalue:-data value stored at mer 45) lwalue:- memory address at which data value is stored 46) final:- keyword that makes a variable 2 constant 47) Scope:- progre in which a variable is accessible 448) Comments:- Comments are non- executable statements that understand the program ‘49) Types of Comments: = '2. Single line Comments:- Represented by double slashi//) c b. Multiline Comment:- Multiline Comment (/*....».*/) exten logic of a program Documentation Comment:- Documentation Comment(/**... documentation about the source code. '50) Arrange the following in ascending order of their size in bytes. a. char, long, float, byte__hyk b. short, boolean, double, int? by 7 51) Arrange the following in descending order of tl oa ‘a int, char, long, byte__Qemg b. boolean, float short, double. n region withit increase the readability of the program and help to -ontinues to the end of the line. ids over multiple lines required to explain the _*/)is used to generate external epee FeOmpanee i lo 7 — 53) Classify the it the following primitive and non-primitve data types: arrays, — bina ! aegee double. lasses atl f. boolean, Ser _ 57) Name the data type of the following to store i them: Ree ce the me 4315791445, i Beret iRake in pre 6 < dauble- Ei yi tno | PS Bina Obinstoy [1 wy SS ee ee 43) Non-graphic Characters:- Non-graphic characters are those characters that cannot be typed directly from keyboard, 14) Escape Sequence:- Escape Sequence is represented by backlash(\) and is used to include non-graphic characters in ‘our program. 45) Give the escape sequence for representing the following non-graphic characters:- a. Newline__\yw b. HorzontalTab VE c. Vertical Tab_\V d. Backslash__\\ S A * fe. Single quote Set N BY z f, Double quote aay = g. Backspace_\\ h. Form feed \ A i. Null Character, j. Carriage Return, 16) Operators:-Operators are special symbols that perform certain operation on the operand 17) Operand:- Operands are the data items on which the operation is performed. 18) Punctuators:- Punctuators are used for grouping and separating data values in a program. 19) ;Semicolon :- Used to separate statements 20) ,Comma:- Used to separate consecutive identifiers in a variable declaration. 21) {Curly Brackets:- Used to define a block of code and initialize values of array. 22) ( JParenthesis:- Used to define methods, precedence of operators in an expression and conditions in a control statement. 23) [] Square Brackets:- Used to declareé arrays and refer to values in a particular index. 24) (type) operator :- converts a value to a specified type 25) new operator:- create new arrays and new objects 26) Operator Precedence:- determine the order in which expressions are evaluated 27) Operator Associativity:- determine the grouping of operands and operators in an expression with more than one operator of the same precedence 28) Unary Operator:- acts on one operand 28) Binary Operators:- acts on two operand 30) Relational Operators:- determine relation among different operands(>,<,>=,<=, 31) Logical Operators:- combine relational expression forming complex decision making construct(®&&| |!) -ombine an arithmetic of eliminating the repeated operand thereby facilitating a condensed approach 6) Conditional Operator/Ternary Operator ( ?:|-it requires three operands. If fist operand evaluates true then _Second operand gets evaluated otherwise third operand. perator and assignment operator operations of handling hey are fundamental data types that come as a part of java ‘anguage . Eg:- byte, short, int, long, float, double, char and boolean fe constructed from primitive data type. Eg:- Arrays, Classes, Interfaces the size in bytes of the following data types: . W : mm. javapackage. voli ; ‘ nn. extends, f: rial a ea el Pp. a iE 11) Types of Literals: Integer Literals- Whole numbers without arly fractional part or decimal point. ». Floating Literals/Real Literals- Numbers having fractional part or decimal point Boolean Literals- can be either true or false |. Character Literals- single character enclosed in single quotes. >. String Literals- Zero or more characters enclosed in double quotes. Null Literals-it has value which does not contain anything, not even a blank or zero 22) Identify the type of Literals in the folowing, 1355, $345, 1a 246 “Computer” true -698543 0.0072 ae “Year 2019" “10% per annum” 6392 7.4985, a An’ 18 1.£-03 5.34f 2 87562 8 . “Vidyalaya” ve Conditional Constructs in Java 1) _Block:- A set of statements enclosed within a pair of braces is called a block 2) ‘™main() function:- main() function is a special function which is user defined but get automatically invoked when @ command for running a program is issued. 3 Sequence Constructs: - The sequence constructs means statements are executed sequentially. 4) Selection Constructs/Conditional Constructs: - The conditional constructs means execution of statements depending upon a condition-test. if a condition evaluates to be true a certain set of statements are executed otherwise another set of statements are executed. it's also known as decision construct. Java provides two types of selection statements- if and switch. 5) Iteration Constructs: - The iteration constructs means repetition of set of statements depending upon condition test. 6) The if statement of Java:- An if statement test a condition. Ifthe condition is true then a set of statements are executed otherwise they are ignored. syntax:- if(condition) statements; 7) The if-else statement of Java:- An if-else statement test a condition and provides either-or condition. if the condition is true then a set of statements are executed otherwise another set of statements gets executed. Synta if{condition) statements; else statements; 8] The if-else-if Ladder:- The if-else-if ladder is often called as an if-else-if staircase due to its appearance. It takes the following form: if{condition) statements; else if(condition) statements; else if{condition) statements; else statements; ‘The conditions are evaluated from top to bottom. As soon as the condition evaluates to be true, the statements associated with it is executed and rest of the ladder is bypassed. if none of the expressions are true, the final else gets executed. Ifthe final else is missing, no action takes place. 9) Nested if:- A nested if is an if that has another if in its if's body or in its else body. 10) Compound Statement:- A compound statement is a statement which encloses a number of statements within a pair of opening and closing curly braces. Eg: if{condition) di Statement’; Statement2; 12) Math ceil) :- This function is used to round up the given integer to the nearest higher integer. The result is always of double data type. Eg double n=Math.ceil(6.25); for nas 7.0 double n=Math. ceil (6.82); It returns a number for nas 7.0 double n=Math. ceil (-6.25); It returns a number for nas -6.0 double n=Math. ceil (-6.85); It returns a number fornas-6.0 13)Math-rint( ) = It returns the truncated value(i.e the integer part of the fractional number) when the fractional part is less or equal to 0.5 and it returns the next higher value for more than 0.5 in double type. Ege double d=Math.rint(6.45); value to das 6.0 double d=Math.rint(8.92); value to das 9.0 double d=Math.rint(7.5); value to das 7.0 double d=Math.rint(-5.95); Itreturns a double value to d as -6.0 double d=Math.rint{-5.35); It returns a double value tod as-5.0 14) Math.cbrt():- This function returns the cube root of the argument passed. It returns a double type value. Eg: double x=Math.cbrt(38); double value to x as 2.0 double x=Math.cbrt(512); value to x.as 8.0 15)Math.sin(), Math.cos(), Math.tan() :- These are the trigonometrical functions. They are used to find the sin, cos, tan values respectively of the given angle in radian as an argument. It returns Itreturns a number Itreturns a double Itreturns a double Itreturns a double Itreturns a Itreturns a double double type of value. es double d=Math.sin(x); double d=Math.cos(x); double d=Math.tan(x); where x is an angle provided in radian. 16)Math.exp() :- This function provides exponential value i.e. e% It returns a double type value. Eg- double d=Math.exp(6.25); d results in 518.0128 17)Math.random() :- This function returns number between 0 and 1. It returns a double type value. Eg- double d=Math.random(); twill return any double value to d between 0 and 1. 18) What will the following functions return? Math. sqrt(9) Math.sart(6.25) Math sqrt(225) Math.sqrt(64) Math.sqrt(400) Math.min(3,7) Math.min(6.4,8.2) Math.min(-5.3,-5.9) Math.min(-85.3,-15.29) Math.min(-80.4,98.2) Math.max(14,81) Math.max(612.7,83.4) Math.max{-87.54,-97.45) Math.pow(3,2) Math.pow(15,2) Math.pow(4,3) Math.pow(12,2) Math.pow(2,6) Math.abs(23) Math.abs(-64) Math.abs(-8.76) Math.abs(3.66) Math.abs(-9.99) Math.round(51.25) Math.round(-8.92) Math.round(-25.62) aa, Math.round(6.85) bb. Math.round(-4.75) cc. Math floor(6.25) dd, Math.floor(6.82) ee. Math floor(-6.25) ff. Math floor(-9.85) gg. Math.ceil(6.25) hh. Math.ceil(6.82) i. Math.ceil(-6.25) jj. Math.ceil(-6.85) kk. Math.rint(6.45) I. Math.rint(8.92) mm. Math.rint(-99.4) nn. Math.rint(7.5) 00. Math.rint(-5.95) pp. Math.rint(-5.32) qq. Math.cbrt(64) rr. Math.cbrt(125) ss. Math.cbrt(1000) tt. Math.sqrt(144) uu. Math.sqrt(361) w. Math.sqrt(400) NER EKER A OPER AU KTH sem aH Te Lesson 7 Mathematical Library Methods 1) User Defined Methods:- A method defined by the user is user defined method. 2) Library Methods or Built-in Methods:- The methods created by the developers of Java are called Library methods or built-in methods. 3) Math class:- The Math class of the java.lang Package contains a lot of generic mathematical functions, including geometric and trigonometric functions. These methods are defined by the Java developers and are available to all Java programs. 4) Math.sqrt() :- This function is used to find the square root of a positive number. It returns a double type of value. fe double n=Math.sqrt(4.0); Itreturns a double value for n as 2.0 double n=Math.sqrt(6.25); 'treturns a double value for n as 2.5 5) Math.min() >- This function returns minimum of two numbers. The return value depends on the values used as the arguments of the function. te- int n=Math.min(4,6); It returns an integer value as 4, which is minimum of n as 4 and 6. double n=Math.min(4. 8); It returns a double type minimum value of n as 28 double x=Math.min(-3.5,-9.5); It returns the double type of value for x as -9.5 6) Math.max() :- This function is used to find the maximum of two arguments. It returns a value depending upon the arguments of the function. Eg: int n=Math.max(4,8); It will return an integer type maximum value of n as8 double n=Math.max(12.7,8.4); It will return a double type maximum value for n as127 double x=Math.max(-67.66,-97.45); This function returns a double type maximum value for n as -67.66 7) Math.pow() :- This function is used to find the power raised to a specified base(number). It always returns a double type value. Eg double d=Math.pow(2.0,3.0); This function returns a double type value to das 2.0 as 8.0 double d=Math.pow(5.0,-2.0); The value of d will be returned as a double value as 0.04 8) Math.log() :- This function returns natural logarithm value of a given argument. It always returns a double type value. Eg double x=Math.log(6.25); It will return a double type value to x as 1,8325814637483102 9) Math.abs() :- This function is used to return absolute value i.e. only magnitude of the number. It returns int/long/double value depending upon the arguments supplied. Eg: int n=Math.abs(3); Itreturns an integer value to n as 3 int n=Math.abs(-8); It returns an integer value to the variable n as 8 double d=Math.abs(3.66); Itreturns a double type value to d as 3.66 double d=Math.abs(-9.99); It returns a double type value to d as 9.99 10) Math.round() :- This function returns a value in rounded form. It always returns in double type. If fractional part of the number is below 0.5. it returns the same integer value, otherwise, it returns the next integer value in double data type. E double n=Math.round(6.25); Itreturns an integer value to n in double data type as n=6.0 double n=Math.round(6.85); Itreturns an integer value to n in double data type i.e. n=7.0 double n=Math.round(-8.92); Itreturns an integer value to n in double data type i.e. n=-9.0 11) Math floor() :- This function is used to round down the given integer to the nearest integer. The result is always of double data type. E double n=Math floor(6.25); It returns a number for nas 6.0 double n=Math.floor(6.82); It returns a number for nas 6.0 double n=Math.floor(-6.25);It returns a number for nas -7.0 double n=Math floor(-6.85);{t returns a number for n as -7.0 Soca tf re —ht une ~ ae mo LolLolot Ol amie) Oot) 8 aGl 0-0 2 Chapter iterative Constructs in Java ae ole Sre iteration statements? Name the iteration statements provided by Java. on be true tee statements are statements that allows a set of instructions to be executed repeatedly till some condition evaluates ‘rue. The iteration statements provided by Java are for, while and do-while. 2) Which elements are needed to control a loop? 2) The elements that control a loop are: (i) initialization expression (ii) test expression (ii) update expression (iv) body of loop. 3) What is meant by entry controlled loop? Which java loops is entry controlled? A3) An entry controlled loop is one for which the test expression is evaluated before each iteration. The for loop and the while loop are entry controlled loop. Q4) What is meant by exit controlled loop? Which java loop are exit controlled loops? ‘AA) An exit controlled loop is the one for which the test expression is evaluated after each iteration. Such loop always execute at least once. The do-while loop is an exit controlled loop. Q5)What jalization expression? AS) Initialization expression initializes the loop vz Q6) What is test expression? A6) Test expressions truth value decide whether the loop will be executed (if test expression is true) or not (if test expression is false) Q7) What is update expression? ‘A7) The update expression updates the value of loop variables after every iteration of the loop. Q8) What is loop body? A8) The loop body contains statements to be executed repeatedly. Q3) What is an empty loop? 9) If the loop body of a loop contain an empty statement i.e. null statement, the loop is called an empty loop. Q10) Which expression are optional in a for loop? A10) All the expressions, namely initialization expression, test expression, update expression and the body of a loop are optional. Q11) When are empty loop useful? A111) Empty loops can be used for pointer manipulation, introducing time delays etc. Q12) What is the difference between a while loop and a do-while loop? 12) The while loop is pre tested i.e.an entry controlled loop whereas the do-while loop is post-tested i.e. an exit controlled loop. Q13) How many times is the loop body gets executed in a do-while loop? ‘A13) A body of a do-while is executed at least once. The exact number of iterations is controlled by the test variables, condition and the update statement. Q14) What is 2 while loop? A14) The while loop is an entry controlled loop. The loop evaluates a test expression before allowing entry into the loop. A while Joop can also be an empty loop, if it contains just a null statement in its body. A while loop can also be an infinite loop, control variable is not updated within its body. Q15) What is do-while loop? 15) do-while is an exit controlled loop. The do-while loop is executed at least once always, as it evaluates the test expression at the end of the loop. 16)Whatis nested loop? A16) If a loop contained in another loop inside its body, then it is a nested loop. In nested loops, before outer loop terminates. 17) What are jump statements? A17) The statements that facilitates the unconditional transfer of program control are call jump statements: return, break and continue. 18) What is return statement? AB) The return statement is used to return from a function, Q19) What is the significance of break ? 418) A break statement can appear in any of the loops and a switch statement. Whichever statement it appears in, it causes the termination of the statement there and then and the control, asses over to the statement following the statement containing break. In nested structure, a break terminates the very statement it appears in. Q20) Differentiate between null loop and infinite loop. A20) A null loop does not contain any statement to repeat whereas as infinite loo} iterations. Q21) Differentiate between break and continue. ‘A21) break statements terminates the statement in which it appears while continue moves the neat iteration, se in the beginning of the loop. if its loop the inner loop must terminate led jump statements, Java provides three P repeats execution of the statement for endless et eee ‘Twwns)) Namo — Naw ink on. ae = now tat (10 | Noms ¢f =10 ‘ User Defined Methods 4) Whats a program? A program is a set of instructions given to computer. 2) What are executable instructions? Instructions which initiate some action are called executable instructions. 3) Define Method/ Function. function is a sequence of some declaration statements and executable statements. 4) How is the behavior of an object implemented? The behavior of the object is implemented through function. 5) What is the need of Functions? Functions are helpful in coping with the complexity hiding low level details and providing reusability 6) When a Function should be defined? Function need to be defined before itis being used anywhere in the program. 7) Write the syntax of Function definition. [access specifier]Imodifier] return-type function-name(parameter lst) { Body of the function ‘ 8) Whats access specifier? ‘Access Specifiers are the keywords which are used to determine the type of access to the function. 9) Name the acess specifier. Eg: public, private, protected, 10) Which is the default access specifier? Friendly is the default access specifier. 11) Name few modifiers Final native ynchronized,transient volatile 12) What isthe significance of a method made final? {final method means that the functionality defined inside the method can never be changed 13) What is return type? Return type is a valid java data type which specifies the type of value returned by the function. 14) Which datatypes can be the return types of a function? Al the valid java data types can be the return types of the function. 415) Whatis the return type when a function does not return any value? When 2 function does not return any value then it should be void. 16) Define Parameter lst. The parameter lst is @ comma separated lst of variables ofa function referred to as its arguments or parameters 47) Where a method does exists? ‘A method exists within the classes. 18) Define Function Prototype. Function Prototype is the first line of the function definition which tells the compiler about access specifier, modifier, type of value returned by the function, name of the function and the number and type of arguments passed 19) Define Function Signature. Function signature basically refers to the number and type of arguments passed. 20) What happens when a function is made static? The keyword static makes a method as the class method which means that the method needs not to be called through the instance of the class rather through the class itself. 21) What happens when a funct made public? When a function is made public then it can be accessed by all the methods of all the classes. 22) What is the significance of void? The keyword void specifies that the function does not return any value, 73) How is function invoked? ‘A function is invoked by providing the function name, followed by parameters being sent enclosed in parentheses. —— UCC Byrne’ —_ String Manipulations Character Class Functions A)istetter() Argument type:- char 1 Return type:- boolean Function:- It returns true if the character passed is an , alphabet otherwise return false. * Example: « System.out.printin(Character.isLetter(‘c’)); fuat- _ System.out.printin(Character.isLetter(’4’)); ~ faloe System.out.printin(Character.isLetter('%’)); “aloe, System.out printin(Character.isLetter(‘F’)); bu System.out.printin(Character.isLetter("’)); folet- 2) isDigit() Argument type:- char Return type:- boolean Function: It returns true if the character passed is a digit otherwise return false. Example: System.out.printin(Character.isDi System.out printin(Character.isDigit ('4’)); “Dw System.out printin(Character.isDigit ('%’)); 42% ‘System.out.printin(Character.isDigit (‘7’) System out printin(Character.isDigit(’”); {alee 3) isLetterOrDigit() ‘Argument type:- char Return type:- boolean Fi Function:- It returns true if the character passed is either 2 digit or an alphabet otherwise return false. Example:- System.out.printin(Character.isLetterOrDigit (‘c’)); System.out printin(Character.isLetterOrDigit ‘4’)); taut ‘System.out printin(Character.isLetterOrDigit ('%')); es System.out printin(Character.isLetterOrDigit ('7')); System out printin(Character.isLetterOrDigit (')); alee 4) isWhitespace() Argument type:- char Return type:- boolean Function: It returns true if the character passed is a space otherwise return false. Example: ‘System.out.printin(Character isWhitespace('c’)); fol. System.out.printin(Character.isWhitespace ('’)); -pust System.out.printin(Character.isWhitespace(’%)); ‘System.out.printin(Character.isWhitespace ('7')); jie ‘System.out.println(Character.isWhitespace ('’)); teen 5) isUpperCase() Argument type:- char Return type:- boolean : Funetion:- It returns true if the character passed is a capital alphabet otherwise return false. sxample:- Sa out.printin(Character.isUpperCase('a')); toler System.out.printin (Character. isUpperCase (‘G ‘)); true System.out. println(Character. isUpperCase (‘T')); Dus» System.out.printin(Character. isUpperCase (‘t’)); System.out.printIn(Character. isUpperCase ('D’ ); ow 6) isLowerCase() ‘Argument type:- char Return type:- boolean Funetion:- It returns true if the character passed is a small alphabet otherwise return false. Example:- system, out printin(Character.isLowerCase(‘a')}; pus System.out.printin(Character. isLowerCase (‘8 ’)); System.out.println(Character. isLowerCase (‘N’)); i ‘system. out.printIn Character. isLowerCase (‘q’)); System.out.println(Character. isLowerCase (‘Y')); 42» 7) toUpperCase() Argument type:- char Return type:- char Function:- It returns the character passed in capital alphabet if a small alphabet is passed otherwise return the same character. Example: oe ‘System.out.printin(Character.toUpperCase(‘a’)); A System out printin(Character.toUpperCase (‘G’));*G” System.out.printIn(Character.toUpperCase (‘T’)); *T ” System.out.printin(Character.toUpperCase (‘t’)); ‘T * System out printin(Character-toUpperCase ('%’)); #/* 8) toLowerCase() Argument type:- char Return type:- char Function:- It returns the character passed in small alphabet if a Capital alphabet is passed otherwise return the same character. Example: char x=! System.out.printin(Character.toLowerCase(x)); ‘Te ‘System.out.printin(Character. -toLowerCase (‘G y x System.out.printin(Character.toLowerCase (‘T’)) +" System.out printin(Character.toLowerCase (‘t)); E" System.out.printin(Character.toLowerCase ('% a’; Constructor 1) What is a constructor? Constructor is a member function with the same name as its class an: value. 2) Whats the primary job of constructor? ciate Primary ipbol Conatructor is ona the member variables ofthe class with some legal int jal val 3) Whatis the return type of a constructor? Constructors have no return type, not even void 4) Whats the ned of constructors? Constructors are needed to create objets 5) What shouldbe the access specifier ofthe constructor? Constructor should aways be defined as public. 1) Whatwill happen ia constructor is made private or protected? 0 objects of 8 can't be created in Hoa aaeer, made private or protected then It wll at be avaiable fo the non-member function and so objects of that clas a non-member function ofthe class 7) Why constructor should be defined under the pubic section ofthe class? je . Boe eee anos unde th puna othe clase tal jets canbe eres nen uc 8) _Diferentate between Constrictor and Method. ‘ed to itialize the objects ofthat class type with some legal initial {Constructor | Method os S| a te sane name a aoe Sass Has any a cope cla nai =a Has ne return ype not even void [asa vale return type oF ve mae 7 Crates instancas ofa lass =| Groups java statement zg | Gels invoked atthe time of object creation | Needs to be called explicitly _ 8) "Name the type of constructor. Parameterized constructor Non-Parameterized constructor 410) Define parameterized constructor. Constructor with paramoters is called parameterized constructor. 41) Define non-parameterized constructor. Constructor with no parameters is called non-parameterized constructor 12) Whats default constructor? When in class no constructor is defined explicitly then compiler creates a non-parameterized constructor called intiatzes data members with some dummy val happens wien 2 use defined ciass does not have an explicit constructor? When auser defined class does not have an explicit con: data members with some dummy value. the default constructor which vetor then the compiler automatically supplies a default constructor which initializes 44) What happens when in a user defined class a constructor id defined explicitly? Winen inthe user defined ciass the constructor is defined explicitly then the default constructor created by the compiler gets hidden. 45) When a constructor gets invoked? ‘constructor gots invoked automatically atthe time of object creation 16) What isthe significance of Parameterized constructor? ‘The parameterized constructor allows us to intaize the various data elements of different objects with diferent values when The achoved bypassing teen values a argurents fo the consucior uncon when ne abject crewed en eh ae ete 47) What is the significance of this keyword? Keyword this is used to refer tothe current calling object. 18) What do you mean by temporary instances ofthe class? ‘The expt call to a constructor allows to create a temporary instance or temy 28 Jong as Its being used or referenced in an expression and after thai name. 18) Whats constructor overloading? 1 rte of oni coat icaled consirictor overloading. A constructor is sald to be overioaded when in the same scope Ee ee at ofthe class but ae efferentiated by the number and type of arguments passed. ttisa member function hase eane rane a the cas name joes not have any return type, not even void, ‘tis used to intialize member variable with some te adi alae member abe wth Some aint val ‘needs not to be called explicitly as it gots i \ iret Raeesc late oor ean wis kind at the time of object creation. fin the class no constructor is defined exp member variables with some dummy valu, porary object. A temporary object is the one that lives in the memory les. The temporary instances are anonymous, Le. they do not bear a i ‘ty then at thal time compiler creates a non-parameterzed constructor which initializes Min the class constructors sendy defined expt then the deta constructor get hid en, Functions *)_ What happens when a function call statement is encountered? tosses alls ‘Whenever a function call statement is encountered, the program control is transferred to the function, body are executed, and then the control retums to the statement following the function cal. 2) What happens when a return statement is encountered in a function? turns to the statement immediately following ‘Whenever a return statement is encountered in the function the program control returns t function call statement. 3) How is function with no arguments invoked? A function with no arguments is invoked by specifying empty parenthesis. 4) Differentiate between Actual arguments and Formal arguments. Actual arguments Formal arguments i definition Actual arguments appeorin funn cllstatement | Formal argument appear in function deinion [Actual arguments donot need their data type to be | Formal arguments need the datatype tobe spe | specified Wasa aa 5) What are the two ways in whi A function can be invoked in two manners: Call by Value and Call by Reference. 6) Define Call by Value. In call by value, a separate copy is created by the formal arguments and any changes made in the formal arguments are not reflected backin the actual arguments, 7) Define Call by Reference. In call by reference the formal arguments become the references of the actual arguments and any changes made in the formal ‘arguments are reflected back in the actual arguments. 8) In Java, how all primitive types are passed? A\l primitive types are passed by value 8) InJava, how all reference types passed? Alreference data types are passed by reference. 10) What are the two ways in which return statement is useful? 1} Return statement causes an immediate exit from the function as soon as it is encountered : 2) Return statement is used to return a value to the calling code. 11) Isit necessary to have a return statement in a function? No it's not necessary to have a return statement in a function 12) Why do most of the functions have return statement? Return statement is required because most ofthe functions rely on the return statement to stop execution either because a value must be returned or to make a function’s code simpler and more efficient. 13) Can a function have several return statements? Yes a function can have many retum statements but twill execute the first return statement which is encountered 414) How many values a function can return ata time? ‘Afunetion can return only a single value ata time. 15) What are the three types of functions? Explain them too. There are three types of functions: 1) Computational functions: The functions that calculate or compute some val lue and return the computed value are called 2). Monasterio Tefancton that nan Pulate information and return a success or failure code are called manipulative 3) Procedural functions: The functions that perform ar nn action and have no explicit return value are rocedural functions. 16) Differentiate between Pure function and impure Function. mes tommy ; Pure function: A function which receives objects and do not modify them. Impure Function: A function which receives objects and modifies them. 17) What is Function Overloading? by number and type of a 118) What is the need of overloading a function? ee Function ovrloatng implements polymorphism and ao reduces the comparisons a3 program thereby ae Program rum "J System.out.printin(str.startsWith(“mal”)); System.out.printin(x. startsWith (“appli’)); System.out.printin(y. startsWith (“Java”); System.out.printin("‘science”. startsWith (str)); System.out.printIn(“ions’. startsWith (x.substring(8)}); System.out.printin("World-Unity”. startsWith ("World”)); 12)endswith() Argument type:-String Return type:-boolean Function: It returns true if the current string ends with the specified string otherwise returns false. Example: String str="malyalam”; String x=" Applications”; String y="Java"; System.out.printin(str.endsWith("lam”)}; System.out printin(x. endsWith (“appli”)); System.out.printin(y. endsWith (“Java”)); System.out.printin(“science”. endsWith (str)); System.out.printin(“ions”. endsWith (xsubstring(8));, System.out.printin("World-Unity”. endsWith ("World”)}; 13)replace() ‘Argument type:-char,char Return type:- String Function:- It replaces all the occurrences of the first character passed with the next character passed and returns the string. Example: String str="malyalam”; ‘String x="Applications”; String y="Java”; System. out println(str-replace(‘a’,/@')); System. out printin(x. replace(‘p’’r’)); System.out.printin(y.replace(‘a’/')); System.out printin(science”.replace(‘e’,'&’)); System.out.printin(“Conservation”.replace(‘e’,’K)}; ‘System.out.println(“World-Unity” replace('-/’ ‘); 14)concat() Argument type:-String Return type:- String Function: it concats the specified string at the end of the current string. Example:- String str="Computer”; String x=" Applications”; String y="Java”; System.out printin(str.concat("Program”)); /stem.out.printin(str.concat(x)); ee out Pe concat(x.concat( “in” concat(y)))) System.out printin( “science”. concat(” Project”); system.out.printin("Economics”.concat(x)}; System.out printin(“World-Unity”. concat(“brings Peace”)); 15)trim() Argument type:-none Return type: String Function:- it removes all the blank spaces from the beginning and from the end of the string. Example:- String str=” Computer String x=" Applications String Java"; System.out.printin(str.trim().concat(“Program”)); System .out.printin(str.concat(x.trim())); System.out.printin(str.concat(x.trim().coneat(“in”.concat( y.trim())))}5 System.out printin(“science ”. trim().concat(” Project”); System.out.println(“Economics” concat(x.trim())); System.out printin(“World Unity’.trim().concat(“brings Peace”)); Conversion from Pri ive to String & Vice Versa 1) Integer.parseint() Argument Type :- String Return Type:-int Function: -onverts the string into integer form m-out-printin(x. toUpperCase()); stem. out printin(y.toUpperCase()); System. out.printin(“4athPosition”.toUpperCase()); System.out printin(“Password: “*Hello#”.toUpperCase()); Sea uut.printin(“World-Unity’. toUpperCase()); FALYALAM APPLICATION 5 Tae -TH Posi 11 ov AESWORD!* HELLO? WORLO- UNITY TitoLowerCase() Argument type:-none Return type: String Function: It returns the string after converting all the alphabets which are in upper case to lower case. Example: -"malyalam’ ‘String x="Applications”; String’ ‘System.out.printin(str.toLowerCase()); ra ‘System.out.printin(x. toLowerCase()); ‘System.out.; tIn(y.toLowerCase());, System.out.printin(“4th Position” toLowerCase()); System.out.printin(“Password: ‘*Hello#’”.toLowerCase()); ‘ystem.out.printin(“World-Unity”. toLowerCase()); udped> applications B)equals() Argument type:-String Return type:-boolean Function:- It compares the specified string with the current string and returns true if both the strings are same otherwise returns false. It treats upper case and lower case as different. Example: String str="malyalam”; String x="Applications”; String System. out printin(str.equals(“malyalam")); system. out printin(x. equals(“application”)); system.out.printin(y.equals("Java”)); ‘system.out printin("Science” equals(str)); System.out.printin{“ions”.equals(x.substring(8); system.out printin(“World-Unity”. equals("World Unity”); S)equalsignoreCase() Argument type:-String Return type:-boolean Function:- It compares the specified string with the current string and returns true if both the strings are same otherwise returns false. It treats upper case and lower case as same. Example:- String str="malyalam”; String x=" Applications”; String y="Java”; % System.out printin(str.equalsignoreCase (“Malyalam”); System. out.printin(x. equalsignoreCase{ "application”)); System out.println (y.equalsignoreCase("java”)); System.out.printin(“Science” equalslgnoreCase(str)); system. out.printin(“ions”.equalsignoreCase(x.substring(8) System.out.printin(“World-Unity”. ‘equalsignoreCase(“World Unity”)); 10)compareTo() ‘Argument type:-String Return type:-int Function:- it compares the specified string with the current string and returns 0 if both the strings are same. It returns some positive value if the current string is greater than the specified string and returns some negative value if the current string is smaller than the specified string. It checks the strings lexicographically. Example: String str="malyalam”; String x="Applications”; String System.out.printin(str.compareTo(“malyalam”)); System.out printin(x. compareTo(“application”)); System.out.printin(y.compareTo(“Java")); System.out printin(“science”.compareTo(str)); System.out.printin("ions”.compareTo|x.substring(8))); System out.printin(“World-Unity’. compareTo(“World Unity”); System. out printin(“Unit”.compareTo(“Unity’); System. out printin(“CADET”.compareTo("CABLE”); System out.printin(“Conserve”.compareTo(“Conserved”); 11)startswith() Argument type:-String Return type:-boolean Function:- It returns true if the current string starts with the specified string otherwise returns false. Example:- String Manipulations String Class Functions 1) length() Argument type:- none Return type:-int Function:- It returns the number of characters present in the string. Example: String str="Computer”; String String System.out.printin(str.length());® System.out-printin(x.length()); | 2 System.out.printin(y.length()); 4 System.out-printin(“Position” length());® System.out.printin(“Hello”.length()); System. out.printin(“World Unity” length()); (1 2)charat() Argument type:-int Return type:- char it returns the character at the specified index String x=" Applications”; String y="Java”; System.out-printin(str.charAt (2); M* ‘System.out-printin(x.charAt(0)); A System.out.printin(y.charAt(1)); O- 5 System.out.printin(“Position” charAt(5)); + System.out.printin(“Hello” charAt(“less” length())); 8° ree eran eeeicene 3)indexOf() Argument type:-char Return type--int Function:-It returns the index number of the first ‘occurrence of the character passed as an argument . Example: String str="Computer”; String x="Applications”; 4/4} ©) © i String y="Java"; [ale] System.out.printin(str.indexOf (‘m’)); 2. System.out-printin(x.indexOf(‘p’)); | system.out.printin(y.indexOf('v’)); 2 ‘system.out.printin(“Position”.indexOf(‘’)); & ‘System.out.printIn( “Hello” indexOf{“less”.charAt(0))); 2. system.out.printin(“World Unity”.indexOf(x.charAt(10)));3 4664 4)lastindexOf() Argument typ Return type:-int Function:- It returns the index number of the last ‘occurrence of the character passed as an argument Example:- String str="malyalam”; ‘Applications”; String y="Java”; system.out.printin(str.lastindexOf (‘m’)); 7 system.out.printin(x.lastindexOf('p’)); 2 System.out. printin(y.lastindexOf(‘a’));> system.out.printin(“Position” lastindexOf(‘i’)); s System.out.printin(“Hello” lastindexOf("less” char At(0)));3 ‘ystem.out.printin(“World Unity’ lastindexOf(x.charAt(10))); 7 har 5)substring() Argument type:-int int Return type:- String Function:- It extracts a small string from a bigger string. starting from the first index number to one less than the next index number. Example: String str=”malyalam”; String x=”Applications”; String y="Iava”; System.out.printin(str.substring(0,4)); rely System.out.printin(x. substring(5)); Cottons System.out.printin(y.substring(1,2)); &— System.out.printin(“Position”. substring(y.length()); f2~ System.out-printin("Hello”.substring(1,1)); ‘System.out.printin(“World Unity”. Sees Oitthuk a Ah Uw 6)toUpperCase() Argument type:-none String it returns the string after converting all the alphabets which are in lower case to upper case. Example:- String sir="malyalam”; String x=”Applications”; String y="Java’; System.out.printin(str.toUpperCase()); X 1) Integer.toString() Argument Type:-int 28\Ft 7 . ‘ Return Type:-String Autoboxing and Unboxing in Java Function:- It converts integer type number to a String. Exampl ; ‘i ° t the int n=24; Autoboxing is the automatic conversion bo int m=42; Java compiler makes between the primitive types String str=Integer.toString(n); System.out.printin(n+m); System.out.printin(str+m); and their corresponding object wrapper classes. For example, converting an int to an Integer, Oubfa= a double to a Double, and so on a . * 242 ‘The reverse i.e Unwrapping the object into 2) Long.toString() corresponding primitive data is called Unboxing. Argument Type:- long, ; Return Type:-String Autoboxing is the automatic conversion that the aaa eee enue nt oes) Java compiler makes between the primitive types Example:- and their corresponding object wrapper classes. Jong n=693524; For example, converting an int to an Integer, sodigad a double to a Double, and so on. String str=Long.toString(n); System.out printin(n+m); Leurevnton. 4, fut eBowi 3) Float.toString() ae oe > 5 D velen ‘Argument Type:- float babs | rer Double (4); //take . float m=45.5f; String str=Float.toString(n); donble a = ES [( Unbruny, ‘System.out.printin(n+m); System out printin(str+m); Ope Primchane 69. BS nade 14-9545-5 ete som | 4) Double.tostring() eS a Argument Type:-double i Dh Return Type:-String es a 't converts double type number to a String, sie Sirk flo Float double n=345.7281; Arikte Double float m=45.5f; Bat String str=Double.toString(n); best System.out.printin(n+m); [Sete | Boolian — Ree ccna, System.out.printIn(str+m); Oukfowk = 2) Integer.valueOf() Argument Type :- String Return Type:-int Function:-Converts the string into integer form Exampl String str="54"; int m=45; int n=Integer.valueOfi(str); System.out.printin(m+n); System out printin(strém); Dupt sees 3)Long.valueOf() Argument Type :- String Return Type:-long ng into long type data String str="2453926"; int m=45; long n=Long.valueOf(str); ‘System.out printin(m+n); System.out.printin(str+m); Outpt - 2As#7! 74 4)Long.parseLong() Argument Type :- String Return Type:-long Function:-Converts the string into long type data Exampl String str="629534"; int m=45; Jong n=Long.parseLong{str); system.out.printin(m#n); ‘System.out.printin(str+m); Oustpak - 629574 62982445 5)Float.parseFloat() ‘Argument Type :- String Return Type:-float Function:-Converts the string into float type data float n=Float.parseFloat(str); system.out.printin(m+n); System.out printin(strém); Out 14043 63h 6)Float.valueOf() ‘Argument Type :- String. Return Type:-float Function:-Converts the string into float type data Example: String str="92.72"; float m=2.9f; float n=Float.valueOf(str); system.out.printin(m+n); System.out.printin(str+m); Ou pu 7)Double.parseDouble() Argument Type :- String Return Type:-double Function:-Converts the string into double type data Example:- String str="25.63259871"; double m=4.3; double n=Double.parseDouble(str); System.out.printin(m#n); System.out.printin(str+m); Output - 24.932754871 15632598 114-3 8)Double.valueOf() Argument Type :- String :-double ‘onverts the string into double type data "243492645"; double m=1.5; double n=Double.valueOf(str); System.out.printin(m+n); System.out.printin(str+m); Outpak ~ 255949 26¢S A+ 3492 6451-5,

You might also like