50% found this document useful (2 votes)
976 views

Class X Computer Text Book Apc

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
50% found this document useful (2 votes)
976 views

Class X Computer Text Book Apc

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/ 441
Revision of Class IX Syllabus Unit 1 : Introduction to Object Oriented Programming Concepts Unit Il: Elementary Concept of Objects and Classes Unit Il: Values and Data Types Unit IV: Operators in Java Unit V (a) : Introduction to Java Unit V(b) : Input in Java Unit VI: Mathematical Library Methods Unit VII: Conditional Statements in Java Unit VIII: Iterative Constructs in Java Unit IX: Nested Loop Library Classes Arrays (Single Dimensional and Double Dimensional) String Handling User ~ defined Methods Class as the Basis of all Computation (Objects and Classes) Constructors Encapsulation and Inheritance Project Work Glossary Answers Scanned with CamScanner 14 28 39 48 60 74 95 118, 138 164 224 271 316 361 392 414 428 433 ~_ Revision of | Class IX Syllabus ted Programming: Concepts i, LEARNING SCOPE : Introduction © Procedure-Oriented Language © Object Oriented Language © petit af Object Oriented Programming (QOP) viz. Data abstraction, Encapsulation, Inherltanc and Polymorphism. Introduction Language is a medium of communication. People can interact with each other if they know a common Janguage. Similarly, a user can interact with a computer, only if he/she knows a computer language. This is, why we learn computer languages. Computer languages are broadly classified into two types viz. low-level languages and high-level Janguages. As you know that low-level languages have certain limitations, therefore high-level languages have been developed. They provide a comfortable platform for the users to understand and design programming logic. The high-level languages are further classified into two types. They are: ‘a, Procedure-Oriented b. Object Oriented Procedure-Oriented Language ‘A programming language in which emphasis is given_on-thefunctions-or-procedures (actions to be taken) rather than data values is known as Procedure Oriented Programming Janguage. It is a type of computer programming language that uses variables, functions, Slatements and conditional operators. It contains a systematic order of statements, procedures or functions and commands on the data values to complete a task. ‘These procedures can be invoked anywhere between the program hierarchy and by other procedures as well. It works basically on the following principles: + Problems are divided into smaller programs called functions. + The functions share global data, + The data move freely from function to function, Revision of Class IX Syllabus | 1 Scanned with CamScanner | | | i | | | It can be understood with the help of the following illustration; (eg) =a Function 1 Function 2 Function 3 Procedure-Oriented Programming Concept The above logical structure illustrates that the data values have no Testriction on. use in different functions of the program. They are independent to flow freely fon Part of the program to other. Due to their fiee flowing nature, they may cayye So complications in advanced or complex programming, The[limitations\pf procedure-oriemtea language are: * No restriction on data values, * Ca for the programmers while. debugging * Noreusability concept and: i wgement, ‘esting and length of the program increases. cc erful compuie, some high level languages such as BASIC, COBOL, language trie FORTRAN, SL-l, PL-l, C, etc., af the procedure | i engineering anaes, oriented languages Beacons > ——— Object Oriented Language To overcome the shortcomi languages have been develo ings of procedure oriented languages, ped. In Object Oriented Programming, Object Oriented Programming Concept 2 | Understanding Computer Applications with BlueJ—X — Scanned with CamScanner ; ing allows user (0 ‘The above diagram illustrates that the object oriented programming. al vects’, It is done in split the complete program into a number of segments called “Objects - ‘aanelons of such a way that the data values of an object ean only be used within the fhe program. the same object, They are not directly accessible to the other objects of the P However, the objects can communicate with each other through functions. « er a | ig laid on data Pm ‘Thus, erereeeted programming isan approach in which stress is laid_on CO block than funetions. The data values remain associated with the functions of a particular of te program 30 as to encourage data secutiy- ladvantaged of object oriented programming language are: + Data values are secured, — + Mishandling of data is protected, + Error detection and correction become easier. + Easier in.coding complex programs. Java, C++, Small Talk, Eiffel, Python are some of the object oriented programming languages. Principles of Object Oriented Programming (OOP) Once a program has been created by using different objects; the following principles will implicitly be embedded into it. They are: * Data Abstraction In real life situation, you might have noticed that you need not require to know the details of the technologies to operate the system or a device. For_cxample, when you drive a car, you use steering wheel, accelerator, clutch and braE~You bothered about how they are designed to ir functions. ; ~~ Similarly, in object oriented programming only the essential information about the data is known to the outside world. Hiding the background details or the implementation of code in order to reduce complexity is known as data abstraction « knowing the background details, * Encapsulation In an object oriented programming, the data and functions are grouped or merged together in such a way that the data items are only accessible within the functions of the same object. Revision of Class IX Syllabus | 3 ee Scanned with CamScanner oy) ‘The function provides an interface between data items of the objects and the cal Program. Thus, we can say that the function used in a class can only acces, ‘hy items. The insulation of data that does not allow it to be accessed directly ouysig “8 class premises, although itis available in the same program, is known as ‘Dar win ie. % Hence, wrapping of data and funct i unit that can_be_used togey® * Inheritance While programming, we may need to create multiple classes to meet our requirements, Under such circumstances, it may happen that some of the features of one class are shared by another class. The mechanism in which one class acquires the features of another class is tion’. Class is a blue print or rope) Sait idan nea ‘and_member functions to tee ia various operations. The objec of, -Q.STRS5 POséeSSthe-data and functions Sescribed within the. class, called inheritance. The class that is inherited is ‘known as a Superclass or Base class and one that inherits from a base is called as Subclass, Derived class or Target. ‘Two Dimensional (Derived Ciass) | | Tentiaeoer anacs en = frend) ee le henry i Data Members: Data Members Data Members Data Members (Atibaes:| (Attributes): radius: (Attributes): length, breadth (Attributes): radius,height Jength, breadth, height {wenn [hgh bean 4 | Understanding Computer Applications with Bluel—X Scanned with CamScanner CO —— on jes) are Inthe given illustration, “Mensuraion is the Base class whose Features tore stare by the derived classes “two Dime etna thee Dimensional’ 10 ca parameters of diferent shapes With the help of inheritane n be reused 10 the Base class cal “fom OER components in the : erived clas: he reusability feature : &s.the following advantages in programming: * Mlows less time in writing a propra * Tokes less memory space for storage + Enables PREF execution Laser, Enables program r. 4 , Hence, heritance is a property by vigue cof which one class acquires some features from another cls, IC POM resualine + Polymorphism Consider a term ‘cell’. The term ‘cell’ in Physics refers to a device that supplies current in the electrical circuits, In Biology, it means a fundamental and functional part of human body/plant The same term is also refered to a small room such as Administrative Cell, Examination Cell, etc, uy fq Lal n Jn object oriented programming,-an_obj include a function that can be used for muliple operations. Using a single function ra carry multiple tasks is said to be ‘Polymorphism’, eee Revision of Class IX Syllabus | § Scanned with CamScanner i REVIE! Winsight | QName two categories of programming concepts. Ans. The two categories of programming concepts are: (8 Procedure Oriented programming (i) Object Oriented programming Q2. Name two procedure oriented and two object oriented programming langy,, Ans. () Two procedure oriented languages are FORTRAN and BASIC ; (i) Two object oriented languages are Java and Fynoy, Q.3 Name four basic principles of object oriented programming, Ans. (i) Data Abstraction (ii) Polymorphism. (ii) Inheritance (io) Encapsulation Q.4 Name an object oriented principle that allows a function to be used for multiple, Ans. Polymorphism 3K QS What is meant by ‘Base’ class and ‘Derived’ class? ‘Ans. ‘The class from which other classes are derived through the process of inheritance ‘base class or super class. The class that inherits properties from a base class is lt derived class. What does reusability mean? During inheritance, the components used to perform a task in base class a in the derived class for other type of processing, This feature is known a Q7 State the Java concept that is implemented through: (A superclass and a subclass (The act of representing essential features ofa class without including the baci details. nN {icse Ans. (i) Inheritance a (ii) Data Abstraction Q8 Define Encapsulation, CSE an ‘Ans, The wrapping of data and function of clas so that they canbe used asa unit en as Encapsulation. Q.9° What is Inheritance? {ICSE 20 ‘Ans. Inheritance is an OOP principle according to which a class acquires some features another class. It promotes a characteristic called reusability. Q.10 What is data abstraction? Explain with an example. LICSE an Ans. It is an act of representing essential features of a class without undergoing backgroud details. For example, while driving a car, you ate only aware of its important parts (using essen features) viz. clutch, brake, gears and accelerator. By applying brakes, you can stop te car and thus you need not require to know the internal mechanism of the brake of at re in tam, S TEUSAbiliy, 6 | Understanding Computer Applications with BlueJ—X Scanned with CamScanner ESE 1. Tick the correct option: 1. In object oriented (@) procedure 2. Which of the followi class premises: (@) data hiding (®) encapsulation _(¢) abstraction {gyal of the above 3. The Process of combining data and functions that enables them to be together as igle entity is called: (@) inheritance by’ encapsulation _() classification _(@) attributes 4. The process by which a class acquires the properties from another class is called: () polymorphism. (uyinheritance (¢) abstraction (A) abject 5. In procedural programming, the stress is laid on: (@) lass DF function (© data io) thn is a set of objects that has common attributes and common behavior. (@) abstraction (@) encapsulation (oyélass (@ function 7. Which of the following is not an object oriented programming language? (@) CH (©) Simula (of BASIC (d) Java 8. The process of restricting the free flow of data from the outside world is known as: (@) encapsulation —_ (bheritance (©) function (@) class 11 Fill in the blanks: ig 2 Objects can communicate with each other through ...AWADCHONE.... in object oriented programming language. 3. Using 2 function for multiple operations is called as FLYMO” hisen, 4. Rak. .cabshoichion is an act of representing essential features without including background details. 5. Feature of wrapping .... A@L@....... and JuNEHONS. as a single unit is called encapsulation. Programming, the stress is given on: (6) methods (6) class Pe ia tie ng principle does not allow to access directly from outside ++ is the fundamental concept in object oriented programming 6. Noheeit@Qed.......... principle of object oriented programming promotes reusability feature. IIL. Write short answers: 1. What is object oriented programming? Name two object oriented programming languages. 2. Name four basic principles of object oriented programming. 3. Why do we prefer object oriented approach in complex programming? Explain. 4, What is meant by a base class and a derived class? 5. Mention two limitations of procedure oriented programming approach. 6. What is meant by encapsulation? ICSE 2006] Revision of Class 1X Syllabus |7 Scanned with CamScanner 7. Define the following with an example each. (@) Inheritance | () Polymorphism i 8. In what way is Data Hiding related to Data Abstraction? Urge 9. Give an example to explain Data Abstraction. teg 10, What is meant by Data Hiding? . io nL Which ofthe Object Oriented programming principles explain the following i, Justify, a te, (@) The variables and methods are put together in a Class. 8 | Understanding Computer Applications with Blued—X Scanned with CamScanner > EE eae BISuSey Concent of Objects and Classe: ° DIANNE iN | Slat . Real world objects and software objects © Characteristics and behaviour | instance of a clase ¢ cd SOftware objects © Class is an object factory © Object is an | Instance OF & class © Clas i a user defced data ore | | Introduction ee mathe cls is st or eategory of tings sharky commion charctedistics or qualities. Each item belonging to a seer ecisics and Behavious described winner © ® SPECifC category possesses the character If . connie ‘furniture’ as a category then different types of furnitures such as table, char bench, le. can be refered to as items of category ‘furniture’, In software terms, category and items are consi n dered to be class and objects respectively. Hence, class is a blue prinvtemplate/prototype that describes the characteristics and behaviours for the similar types of objects. Objects are the entities which possess different characteristics and common behaviour described within the cless Let us consider an ex, s ‘ample of real world class to understand the way different characteristics and common behaviours are embedded in its objects. Class TwSet SONY, Object 1 Characteristics: Sita Size Ske ‘Number of channels Number of channols ‘Number of channels Price Pico Price Character: Chaactersis: Behaviours: Common Behaviours: Viewing TV programs | Vieng TV progams Praying games | Praying games | Vioning moves Vieng moves ___Inthe given illustration, some characteristics and behaviours of TV sets are described inder class named as “TySet’, The objects of class ‘TvSet’ can be created as shown below: T\Set SONY = new TvSet(); Tet LG = new TvSet(); Revision of Class IX Syllabus | 9 Scanned with CamScanner Of ‘The moment the objects are created, they will implicitly possess the charactey, ‘and behaviours described within the class. Here, itis to be noted that the objects Sou and LG will contain different characteristics (Size, Number of channels and Pricg they will posses common behaviours suchas “Viewing TV programs’, ‘laying : » by tnd ‘Viewing movies’. In this way, we can say that the class and objects are internee’Y to each other. "ag When class and objects are used in programming, they are known and objects. The description of class and declaration of the objects the same way as the real world class and objects take (already discu: Let us take an example to understand as how software class an for programming purpose. 88 software : q Will take pig ssed above) objects wl beg class Rectangle | Objects z — Mata Members length breadth eee ia Member Methods length= 36 length= 42 input() breadth= 16 breadth= 20 calculate() input() display, calculate() } display() In the structure shown above, the class ‘Rectangle’ is designed with the data members Gength and breadth) and member functions (input(), calculate() and display(), The objects of the class can be created as shown below: Rectangle Fig_] = new Rectangle(); Rectangle Fig_2 = new Rectangle(); ‘The structure shown above, states when the objects Fig_1 and Fig_2 are created then each object will automatically possess the data members and member functions described within the class ‘Rectangle’. The allocation of data members pertaining to each objec can be different but the functions to be carried on them will be common, Hence, Fig_Linput() —; will accept length and breadth of object Fig_l. Fig_l.calculateQ) : will perform calculations by using length and breadth of objec Fig_l Fig_ldisplayQ): will display the result of calculation of object Fig_l. Similarly, you can show the above tasks for the object Fig 2. Real World ys Software Class and Objects From the real world and software examples of class and objects shown above, it is evident that the characteristics and behaviours of real world class and objects are treated as data members and member methods of software objects respectively. 10 | Understanding Computer Applications with BlueJ—X_ Scanned with CamScanner Characteristics, Size ‘Number of channels Price Behaviours Viewing TV Programs Playing Games Viewing movies Some Meaningful Terms * Class is an object factory — A class is used to create similar objects that possess different characteristics and common behaviours. Hence, class is called an object factory. + Object is instance of a class — The data members declared within a class are also known a instance variables. When an object of a class is created, it includes instance variable described within the class, This is the reason that object is called as instance of a class. * Class is a user defined data type ~ When user creates a class it becomes a data type for his program. Thus, class is referred to as a user defined data type. This data type includes different primitive types such as int, float, char, etc. Hence, it is also said to Composite Data Type. Points to Remember! ‘A class creates many objects and interacts by invoking methods. ‘An object always defines the following: 1 State It is represented by attibules of an obj 2. Behaviour : tis represonted ‘other object. Kt gives @ unique name to an object and enables ona object to interact with other objects. lect, It also retlects tho properties of an object. ‘by methods of an object. also reflects the relation of an object with 3. Identity Acclass is described with some characteristics and behaviours where ch termed as data members (Attributes) and behaviours as the member fun methods). Each object belonging to a class contains the attributes (states) N means that the attribute deals with the contents of an object to make distinct. Attributes are the characteristics or data members of an object, aracteristics are \ctions (member ) and functions, the object more Revision of Class IX Syllabus | 11 Scanned with CamScanner REVIEW if ss QA Name the keyword that defines the characteristics or the data members for the objec, of a class. Ans, Attribute Q.2 Class and Object are inter-related. Justify with reference to object oriented programm ‘Ans. A‘Class’ is used to create various objects that possess different characteristics and commo, behaviours, Each object follows all the features defined within the class. That is why cig, also referred to as a blue print or prototype of an object. This way we can say tha they are inter-related. : Q.3 What is the importance of the keyword ‘new’ while creating an object? Ans. ‘New’ is used for dynamic allocation of the object, ie., it allots space in the dynamic memory for storage of an object. Q.4 In what way would you relate a real world object to a software object? Ans. A real world object contains characteristics and behaviour. The software object replaces characteristics with data members, and replaces behaviour with functions or methods, In this way real world objects and software objects are interrelated. Why is a class called an object factory? LICSE 2009) Class is the prototype of an object. Each object belonging to a specific class possesses the data and functions defined within the class. It also produces the objects of similar type, o/ Hence, a class is termed as an object factory. (Q.6 ) Why is a class known as composite data type? {ICSE 2009) ~ Class name : Television Data members: int cost, int discount, int amount Member functions: Accept() — : to input the cost of Television Caleulate( ) : to calculate the discount Display() : to show the discount and the amount paid after discount % Revision of Class 1X Syllabus | 13 a \ Scanned with CamScanner | ere cree © Character sets in Java © ASCII code © Escape sequences © Tokens © Different types 7 tokens (Literals, Identifiers, Punctuators, Operators, Keywords) © ASSIONMENIE © Constan, and variables © Initializing a variable © Data types in Java: Primi on-Pr types © Type conversion: Implicit and Explicit type conversions. Introduction Program is a set of statements. Each statement of computer program is formeg , using different words called Token’, Each token is formed by using valid charac? ley of computer language in which program is written, Hence, characters are the basic fundamental unit of a programming language. Character sets in Java Java beit a programming language contains various character sets that can be yg while writing a computer program. The character sets used in Java are as follows: Letters siresgayecal i * Letters: All letters are used in Java programming. - Upper case - A to Z Lower case - a to z * Digits: All digits are used in Java programming (ie., 0 to 9). + Operators: These are special signs or symbols used to perform operations in Javg programming, Axithmetical operators: +, -, * /, %, etc. Logical operators: &&, ll, ! Relational operators: <, >> <5, = *+ Delimiters: These are special characters used in Java programming, — Braces: (, ), {, }, [, ], ete. Punctuation marks: comma(,), dot(.), semicolumn(;), ?, ;, ete. Encoding of characters You must keep in your mind that the characters entered from the keyboard are not directly stored in the computer memory. It is because the memory stores a character in numeric form (binary number). Hence, the characters entered from the keyboard are encoded into numeric form before actually getting stored in the memory. Basically, two types of encoding schemes are used in computer to encode the characters. They ae | RASCH and Unicode. 2 114 | Understanding Computer Applications with Blued—X. Scanned with CamScanner CL —— ASCII Codes vs Unicode ASCII stands for Ame code for representing are used while design as numbers, with ea, some of the characi “can Standard Code for Information Interchange. It uses 7 bits Each character. It includes 256 characters but only 128 characters ing and executing a program, ASCII code represents these characters Ch letter assigned a number from 0 t0 127. The ASCII codes of “ers used in Java programming are shown below: | ois Tht 48 - 57 0-9 65-90 A-Z 97 - 122 ei 23, Blank Unicode ‘The Unicode is a wide representation of characters in numeric form. The code contains hexadecimal digits ranging from 0x0000 up to OxFFFF a Escape Sequences There are some characters, known as escape sequences, that are used to control the cursor while displaying the values on the screen. Each escape sequence starts with backslash () followed by a specific character. The complete set (backslash + character) is enclosed within double quotes, e.g., “\t", Normally, a set of characters under double quotes is considered to be a string but backslash (\) acts as a command to control the printing in specific manner. Some of the escape sequences are listed below for the reference: EE wt Horizontal tab Ww Vertical tab \ Backslash v Single quote ? Double quote \b Backspace W Form feed 0 Null v Carriage return \n ‘New line feed Revision of Class 1X Syllabus | 15 Scanned with CamScanner Sequences : Using Escape tes help to control the cursor's movement on the output Screen, en’ ‘The eorape se get a formatted output. t enables the user (0 j .d in Java programming are ey. ome escape sequences whch are commonly Use Pang bow: sag” (Backslash n): This characteris used for new Tine feed. AS sooq a. “\n” ‘kips the current line and moves to yp. trol encounters “\n”, the cursor skips th i ie ‘on the screen for printing the remaining part of the output, Ht red sttal\n"+"Age: my ystem.out printin("Name: Akash Mittal\a"+“Age: 16 yrsin”+"Class: yo, In the print statement shown above, ““\n” is included along with the me. in double quotes. If the print statement contains variables then you neeq to “\n" separately to display the message in different lines, as shown: int a=14,b=26; System out printin "First number="+a+""\n"+"Second mumber= "be", ="+(atb))i ge Use Different vays of using backslash a: 1, The use of backslash m along with the message ame: Akash Mittal 2. The use of backslash n seperated by ‘+! First omber =14 Second muaber = 26 ‘Sam =40 (ii) “\" Backslash 1): This character is used to separate the values on the screet with a gap of 8 spaces between them. It is also used for printing the result im a formatted pattern. 16 | Understanding Computer Applications with Bluel—X Scanned with CamScanner System.out printn(“First numberit"a4'"t"+"Second number” +): Ind **\0 Eb): System.out printn¢“Frst number"s"t"4a4-\"+"Second mumiber#"N-+) Here, you will notice that the output in both the cases is same. ano pein bt cent ae of ening bachalaah 28°) ‘syvten-out.printin(.the tae of bach ‘Syvtensout.printia(uunet Ash Mitta \e"age ‘Sytenvout.printia(2.sha ene of bashes © Sriten.cot-primin("2.tbeDestalanh aleeg withthe nesage and varuabien seperated BY Sretencevtopritia("rizat mber\eteaer\ere*vened pamec\e #8 ain ‘srveenceutpristla(*4.the bctalash t within deble quote wish variables but seperated by 0107 Syvtencout.priseln(*Firat wmbar"er\iai\eaveesd hbase]! Different ways of using backslash tt L.The use of backslash t along with the essage Mane: Akash Mittal Age: 16 years 2.the use of backslash t seperated by ‘+" and within double quotes Mane: Akash Mittal = -Rge:_-16—years, 3.the backslash t along with the message and variables seperated by ‘+! First mmber 14 Second nusber 26 4.the backslash t within double quotes with variables but seperated by ‘+! First number 14 Second nunber 26 Tokens Toker of valid characters used for writing a statement in Java program. In other Words we may say that a Java stalement comprises @ AU Tokens. They are the smallest elements of the program identified by the compiler. Revision of Class IX Syllabus | 17 Scanned with CamScanner - NT en ‘Thus, token is defined as each individu PPT og, ‘meaning and takes active part in program at of Java program that carrie, | in Java are: ‘The different types of tokens used in Jav okens used in Ja¥8 programming. % You have already studied about various | have a brief discussion about different tokens. * Literals ics. They have fixed value sn mathematics. x i You would have heard about constants im mAMOTETE ojerals in ava Progra can’t be changed at all. The term constants are i gn that remain unchanged during entire execution : ws: ‘The various types of literals used in Java are as follo integer”) Real Charaetor | "Boolean Nutt + Integer Literals: The whole numbers (positive or negative) are own inepy literals. They are also called as a fixed point numbers because the decimal poi, always have a fixed position (ie, after the last digit of the number). Hence, yy decimal point in integer numbers is optional. e.g. 16, 345, 8262, etc. ‘ + Real Literals: Real literals are also called as floating point numbers. They ae the fractional numbers. The placement of decimal point may not be same in rea numbers, e.g., 3.42, 43.678, 0.000012, 678.4, ete. + Character Literals: A single letter or a digit or any special symbol enclosed within single quotes is known as a character literal, It does not take part in arithmetical calculations. e.g. ‘B’, ‘u’, ‘6, ‘7’, etc. + String Literals: A set or group of characters enclosed within double quotes is known as a String literal. e.g., “PROCESS”, “System”, “Salary - 2018”, “4357”, etc, Note: A string literal can be.a set of any type of characters within a limit of 26 rammctre m e of characters within TeTS * Boolean Literals: Boolean literals are true and false. A boolean literal can eitet be true or false at a time, + Null Literal: Null literal denotes the absence of a value. It is used to initialize a object or array. 18 | Understanding Computer Applications with Blued—x Scanned with CamScanner eg. Integer n = null; String s = null; + Identifiers Identifiers is a term used for naming a bl i isu in Java program, Identiti ene © beck of statements by which they ae identified : be a class name, a functi bject or an Vi : , a function name, an objec eet fried are ae identifiers because they are used to name a data that holds cera Y- The value can change depending upon our requirements in the + Assignment ‘The term assignment refers to storing a value in a vari i is i th th variable and the value to be sored ust hove ecrpatbledts esas da ee € stored must have compatible data types (same data For example, int a= 12; float f = 8.36; double d = 3.535345; char ¢ String s = “System”; + Operators Operators are the symbols or signs used to specify the operations to be performed in a Java expression or statement. There are three types of operators in Java. (@ Arithmetical Operators: +, -, /, *, ete. (b) Relational Operators: <,>,= =, !=, <=, etc. (©) Logical Operators: &&, II, !, ete, You study more about operators in the next unit. * Punctuators Punctuators are the punctuation signs used as special characters in Java. Some of the punctuators are comma(,), semicolumns (;), dot (), etc. + Separators They are the special characters in Java, which are used to separate the variables or the characters. e.g. Comma(,), Brackets ( ), Curly brackets { }, Square brackets [ ], etc. + Keywords Keywords are the reserved words which are preserved by the system and carry special meaning for the system compiler. They have already been defined in the language and wwe cannot use them as names for variables or identifiers, e.g., class, public, throws, for, sqrt, System, etc. Revision of Class IX Syllabus | 19 Scanned with CamScanner Data Types | Datatype basically refers to asthe type of data, « memory location ean hold, Wheneyy Wwe need to store a value, the respective data type must be mentioned so that the sys may structure the memory location for its proper storage. This is necessary for ye data types. The classification of data types is as shown below: 8 Numeric Types Non-Numeric Types + Integers * Characters * Floating Numbers “+ Boolean enema RSE te Class Array Intertace Primitive Data Types Primitive data types are the basic or fundamental data types used to declare a variable, ‘They are further classified into two categories: 1, Numeric data types: The numeric data types are used to declare varial store numbers. Based on the types of values that can be stored in a numeric data type is classified into the following two types: Integer type: A variable declared under this ty further categorised as: + byte : It is used to store integer data up to 8 bits (ie., 1 byte). eg. byte b; * short : It is used to store a small range of integers uy bles that can variable, the pe contains an integer literal. They are ip to 16 bits (i.e., 2 bytes), e eg. short s; s=25; + int + ILis used for storing integers up to 32 bits (i.e., 4 bytes). eg, int ny n= 345; + long : It is used for storing large integers up to 64 bits (i.e., 8 bytes). eg, long I; 1 = 1234; ‘The user may select a particular data type according to the size of the value to be stored. Real ype: A variable declared under this type contains floating point data (i.e. the fractional numbers including a decimal point), There are categorised as: * float + It represents a fractional number with a small range up to 32 bits (ie, 4 bytes). eg, float f; f=6: 20 | Understanding Computer Applications with Blue—X Scanned with CamScanner «+ double : It represents a fractional number with wide range values up to 64 bits (ie. 8 bytes), double d; d = 0.12543679; ‘The user may decide to declare a variable as float or double as per the size of the values to be stored. g f, ” Precision of the data type ‘When you divide a number by another number, you may get a non-terminating decimal jin some cases. For example, if you divide 5 by 6, it results in 0.83333333...... . Here, 3 repeats itself in the decimal part. If you store the result in float data type then the system will not be able to store such an infinite number. A float data type has the capacity to store numbers up to 32 bits (i.e. up to 7 significant digits), For example: float p = 0.833333 Double data type has more precision. If you declare p as double data type, it will store up to 15 significant digits. [Bee p = 0.83333333...... (14 times) 2. Non-numeric data types: Non-numeric data types do not deal with numbers rather they are used to declare a character or a set of characters. They can be classified into following two categories: + Character type: A variable is declared to be a character type when it holds a character literal (i.e., a single letter or digit or a special symbol enclosed within single quotes). e.g. char ¢; cnx ‘A set of characters enclosed within double quotes is termed as a string. If you want to store a string literal to a variable then the variable must be declared as a String data type. eg. String s; s = “Computer”; ae * Boolean type: Boolean literals ate true "Note: or false. To store a Boolean literal, the 4 boolean literal true or false variable must be declared boolean. ‘must not be enclosed within double eg., boolean b; quotes otherwise, it will become a aes string literal, Declaration vs Initialization Declaration is the term used to declare the type of a variable whereas initialization refers to assigning or storing a specific value to the variable. eg, int a; //variable declaration 5; Mvariable initialization __ First of all, the variable ‘a’ is declared to hold an integer type data and then it is initialized with the integer value 5. of Class IX Syllabus | 21 Scanned with CamScanner Default Initialization -— ggod in the program, then the system inti, Ifa variable is not initialized but IS ee ital Valve. Itis indeed rece’, implicitly with a specific value calle into! a variable of specific data y, sy know what inital value can be stored PY de aa Front variables and their deta, 1 table shown below demonstrates data types Vay, Ng Sea rete ‘The variables Which are declared within the clasg * a0: bers ther in integer tS 0: data members then thy = initialized with default jc oe neat om values. The variable deg double doubled; d=0.04 under pai as lca fables need (0 be initia: character char chr: chr= “W000 re 5 iitiaingy string String st; fie boolean boolean p;——_P=falses ~ Here, “\u0000" means blank/space character. Static and Dynamic Initializations " jable by usi . aa jtizcdon in way to store x tus Cue) 1 ALS Oe Sen the variable must be same a, operator (=). You must take care that the data type Oo} type of value is to be stored. ay integer int a; float float f double double d; character char chr: string String st; st= “JAVA”, boolean boolean pi p-false: Dynamic initialization is used to initialize a variable at run time (ie., during executic of the statement). In this system, the variable is initialized with the value which is tt outcome of some expression or a function. a i integer int a,b,c; carb; | float float p=2.2,k=4.22,f; feptk; double int a=49; double d; d=Math.sqrt(a); String String st], st2, st st3=stl+st2; 22 | Understanding Computer Applications with BlueJ—X Scanned with CamScanner Non-Primitive Data types primitive data type i a A non Ot - fee 'S one that is derived from primitive data types. In other a ave fe ae, number of primitive data types are used together to represent er ype. Hence, a non-primitive data type is also called a composite gata type. Some of the examples of non-primitive data types are array, class and interface. ype Conversion AArithmetical expression is defined as a set of variables, constant and arithmetical operators. eg. at bie - 4; Here, a, b, and c are the variables, operators. 4 is a constant and +, -, * are the arithmetical If an arithmetical expression contains all the data values (variables or constants) of same data types is known as Pure Arithmetical Expression. egs int a,b,c; at bt The above expression contains all the values (a, b, ¢ and 2) of same data type, i.e., integer. Hence, it is a pure expression. The expression will obviously result in integer type value. On the other hand, when the data items in the expression may have different data types then the expression is called as Impure Arithmetical Expression or Mixed Mode Expression. Here, our discussion is based on impure arithmetical expression. If various types of data are used in an expression, a question obviously comes to your mind what type of, result it will return afier execution. In fact, the system converts the result into a specific data type known as Type Conversion. Basically, the data type conversion takes place in two ways as discussed below: type conversion In a mixed mode expression, when the data type of the result gets converted into the higher most data type available in the expression without any intervention of the user, is known as implicit type conversion. Implicit type data conversion is also known as Coercion. 49, int a; long b; long cea + b { int Hierarchy Revision of Class IX Syllabus | 23 Scanned with CamScanner the data type of the resutt j, fs per user's choice, The! ® ny i Cho,” pression. The expligi, wee De g * Explicit type conversion It is another type of data conversion mode expression gets converted into a SPe data type must be written within braces () conversion is also known as Type Casting: eg int a, float b, char ¢; d = (char) (a +b * 6); . ob data. In the example shown above, a, b and ¢ are tee as a re " the system is forceq ie a Prot in which float type. But, the use implicitly be in higher most vane " ta types. Hence, which is a lower type among all the da a char type result using type casting. e variables of Column B. Assign the following literals of Column A with the ~ Column B “| iv, boolean m_¢- ae _ _ | £, 0.004125 "wi. float y Hint: (@) string (@) floating point number (©) integer value _() boolean value (e) character value _(f) double floating point number 24 | Understanding Computer Applications with Bluel—X Scanned with CamScanner Yr REVIEW insight qi Ans. Q2 Ans: 03 Ans. o4 Ans. os Ans. 26 Ans. qv Ans. Qs Ans. 29 a0 Ans. What is meant by boolean variable? Boolean variable is a variable that holds boolean value, i.e., true or false. What is the difference between “true” and true? “true” (enclosed under double quotes) is a string literal whereas true (without double quotes) is a boolean literal. State the escape sequences for horizontal tab and new line feed. Escape sequences for horizontal tab is “\t" and for new line feed is "\n". Is String type a primitive or non-primitive data type? String is a specific data type that is framed using various character data types. It is neither a primitive nor a non-primitive data type. In what way float initialization is different from double type initialization? A float type variable is initialized with a fractional value as 0.0L whereas, a double type variable is initialized with a fractional value as 0.0D. The difference between initializations is the suffix, i., L and D respectively. What is a variable? Variable is a named memory location that is used to contain a value that can change depending on the circumstances during the execution of a program. Differentiate between pure and impure type expressions. A pure expression contains the elements of the same data type whereas, an impure expression contains elements of different data types. What is meant by type conversion? How is an implicit conversion different from an explicit conversion? (ICSE 2010] In a mixed mode @ ina.single. specific.data ‘Tipe, Hence, the data type is converted fo a required type. This process of conversion is Tknown as type conversionn a Ivan implicit type conversion, the result of a mixed mode expression is obtained in the higher most data type of the variables without any intervention of the user. eg, int a; float b; float ¢; caath; In case of explicit type conversion, the data gets converted to a type as per the user's choice and requirement. eg, int a; float b; double ¢; b = (floatj(a * c); Give one example each of a primitive data type and a composite data type. [ICSE 2012], Examples of primitive data type: int, float, double, long, char, ete. (any one) Examples of composite data type: array, class, interface, etc. (any one) State the values of n and ch. char int n=c#; ‘har che(char)n; ICSE 2012] ‘The value of () n= 66 (i) ch Revision of Class 1X Syllabus | 25 Scanned with CamScanner 213 Ans. Qu Q15 Q16 Ans. Qa7 Ans. Qus Ans, Qu9 Ans, ie | What is a literal? ; UCSE 2013) Literal is.a constant that remains fixed throughout the discussion of a program. It is the Value that can be assigned to a variable. For example, Integer literals: 12, 4, 342, ete. Real literals: 1.02, 345.657, 0.00002, 1.0e-05, ete. Character literals: ‘A’, ‘p’ - String literals: “COMPUTERS”, “PAY2013", “3421”, etc. Boolean literals: true or false What are the types of casting shown in the following examples? double x = 15.2; int a = 12; (O int y = (int) x; (ii) long b = a; UCSE 2013) (® Explicit type casting (i Implicit type casting Name the primitive data type in Java that is: (@ A 6Lbit integer and is used when you need a range of values wider than those provided by int. , (i) A single 16-bit Unicode character whose default value is ‘\w0000'. [ICSE 2014) (@) long (i) char ; State one difference between the floating point literal and double type literal. {ICSE 2014) + Floating point literal is a fractional number with short precision and the values can range from -3.4E+38 to 34E+38, whereas double type literal is used for long precision and the values can range from -1.7E+308 to 1.7E+308. What are the default values of the primitive data type int and float? TICSE 2015) The default value of int is 0 (zero) and float is 0.0F. Identify the literals listed below. () 05 (i) “8 (it) false (i) “a” LICSE 2015] ( Real (i) Character (fii) Boolean (i) String Arrange the following primitive data types in an ascending order of their size: (char (i) byte (iit) double (iv) int ICSE 2015) byte, char, int, double ‘What are the types of casting shown by the following examples? LICSE 2016) (@ char c = (char) 120; : (i) int x =; (Explicit (i) Implicit Write one difference between primitive data types and composite data types. | {ICSE 2016] The fundamental or basic data types (viz int, float, chat) that are provided in the language are known as primitive data types. Whereas, dee types i E » derived data 4 ive data ‘pes are called as composite data types, eg. clase, array. ee 781 Understanding Computer Applications with Blunt__w Scanned with CamScanner 1, State whether the following statements are ‘True’ or False!: 1, There are 128 set of different characters used in a Java program. 2 The ASCII codes of upper case letters range from 97 to 122. 3. A variable gives the exact representation of data, 4 The data types int, float, char are called non-primitve types. 5. AString literal is assigned to a String variable, ti | A 6. A character literal is always enclosed in double quotes 1, String constant can be written by using a set of alphanumeri characters. 8 An object is said to be a non-primitive data. 4, The data type int stores fractional values, 410, Boolean type data is used to testa condition and resulls in either true or false. HU 1. Write short answers: 1, What is meant by data type? Name two types of data type. 2, Why is it necessary to define data type in Java programming? 3, Define the following with an example: (@) variable © constant (0 boolean data type (@ coercion (©) primitive data type () non-primitive data type 4, What isa token? Name different types of tokens. {ICSE 2007} 5, Explain the term type casting, 6 Assign the following to a variable with suitable data type. © 2 (@) p= 14142135 (value of square root of 2) (© k= 00008585 (@ n=2450 7. Distinguish between (@) Token and Identifier [ICSE 2008) (© Character and Boolean itera UICSE 2008) 4 Explain the term type conversion. How is implicit conversion different from explicit conversion? T1CSE 2010) 4. Classify the following as primitive or non-primitive data types. (@ car @) arrays (@) classes [ICSE 2018) 9 int 10. In what way is static initialization of datatype different from dynamic initialization? 1 Predict the return data type of‘ and ‘n’ from thie snippet (© int p; @) Rat mi; pem; = m/3*(Math pow(43) System outprintin(); System outprintn(n) 12. Give reason whether the following assignments are correct or not (&) float F =0.002654132; (@ int m 2155 { String ste = ‘Computer; (@) boolean p = false; (© String b = "tue"; (9) char ch = "apps"; (@) Sting st= “Application”; (0) double n= 45520044125, Revision of Class IX Sylabus | 27 - Scanned with CamScanner & TU yrit a 0 ane) lst Java Binary and Ternary; Arithm jon and Statement © Types of Operators: Unary, ; tea sion uational; Increment and Decrement; and Postfix and Prefix operators ‘You have already learnt that an operator isa symbol oF sign used (> specify an operat qo be performed in Java programming, Tt represents the action to be taken whereas, vvamens used inthe operation on which the action is tobe taken are known 2s operangs Expression and Statement Expression isa set of variables, constants and arithmetical operators. In other words, expression is a combination of operators and operands. Let us consider an expression as a * b + 8. Statement ‘When an expression is assigned to a variable, the complete set is referred to as an arithmetical statement. Hence, m = a * b + 8 is an arithmetical statement. Mathematical expression vs Java expression Some of the operators used in Java programming are different than the mathematica! operators. Hence, writing an expression in Java will differ from mathematical expression Here, few examples are given below to illustrate how mathematical expressions are written in Java, oe anys (a+b (a4b)*(a+b)/(a-b) an ety 15 4 0 23*a*a40.05/b4e%e%e ze OH 2*yV/3- (y*yV5 24 Ward)+3/(c%c)+5/(a*b*c) ab 28 | Understanding Computer Applications with BlueJ—X Scanned with CamScanner ypes of Operators java uses three types of operators. They are arithmetical, logical and relational operators. yet us discuss them in brief. Arithmetical Operators ‘The operators that are used to perform arithmetical operations on the operands are known as arithmetical operators. The arithmetical operators are further categorised into three types: Arithmetic Operators Bary Cpariar”|) (Pvriaty/Opoebt ) nary Operator ‘An arithmetical operator that operates on a single operand is known as Unary Operator. ‘The different types of unary operators are: unary plus (+) ‘This operator is used before the variable to keep its sign unchanged. Writing + (unary operator) before an operand is optional. eg, ifa=4 then +a will result in 4, If a =-9 then +a will result in -9. Unary minus (-) This operator is also used before the operand, It reverses the sign of the operand before which it is used. eg, if a= 6 then -a will result in -6. Ifa = -3 then ~a will result in 3, Unary Increment (++) and Decrement (--) ‘The unary increment and decrement operators used with single operand will increase and decrease the value of an operand by 1 respectively. Based on the position of its use the unary increment and decrement operators are further classified into prefix and postfix operators. Unary Increment! sment Operator prefix operators. ' taken place. Let us see how they work. - Prefix increment: In this case, the increment operators (++) are written before the operand. >») Revision of Class 1X Syllabus | 29 Scanned with CamScanner Executi¢ ” The value m int by using | Finall . Befo Process continues nally, ps Before a did in further operations. wi rea execution ‘mi " fase ‘passigned | by 1 ie, | 6. 1. a — Prefix decrement: In this case, the decrement operators (--) are written te the operand. Execution of Prefix decrement: | Gara > [6+3%> [andy ee: ae “The variable | The value of After decrementing the Finally, “ais “‘w decreases vale of ‘a’, the process will reut assigned as by lie, continues by using a = 6 in| in 24, 7 initial 256, further operations | + Postfix {When the- increment or decrement operators are written after the operand, they y ‘ermed as postfix operators. They increase or decrease the value after the acilork taken place. Let us see how they work. ~ ~ Postfix increment: In this case, the increment operators (+) are written afer operand. Execution of Postfix increment: int d int p d=8 d+ 8*4 3249 Pee. | Before : The value of | After The process | Bem jt [fe remmins fi product, the [continues || wil real in| eee fisame (ie, livalue of a” [I by using the [a1 | {as 8. 8) before the || increases by || value of ‘a i | action, | 1 fie, d=9). | as.9 | | 7 ————eEeEEE, 30 | Understanding Computer Applications with Bluel—x Scanned with CamScanner Postfix decrement: In this ease, the decrement operators (~) are written after the operand. 795 [a5+6"3) 4-53 Ep | The value of | After ‘The process | | Finally, ‘q ‘p’ remains | product, the | continues will same (ie. 7) value of ‘p’ | by using the | result in 53. before action, | decreases by value of ‘p’ “1 (he, p=6). | |as 6. Binary Operators ‘The operators that operate on two operands are said to be binary operators. The binary ors are +, -, *,/ and %. These operators are used to perform fundamental arithmetic operations such as addition, subtraction, multiplication, division, etc. A table is given below to illustrate binary arithmetic operators or binary operators: a Addition + atb Subtraction = ab ‘Multiplication " ath Division 1 a ‘Modulus/Remainder % ame Shorthand operations ‘The binary operators available in Java language can also be written in short form. The table shown below illustrates the application of shorthand operators: ri a= 98 qi=8 ‘You already know that an accumulator is a variable that m=m %3 me=3 contains cumulative sum of a number of values and counter p=pts pte is a variable that increases by anet a one after each execution. m= m+n msn = a ‘A shorthand operator can be used only when a variable acts as an accumulator or a counter. Revision of Class IX Syllabus | 31 i Scanned with CamScanner EE“ al Operator) itis yon a log also called conditional opera, Ternary Operators (Condition seal expression OF a cong OS ition | y ‘Ternary operators operate on three the value assigned to a variable depe Syntax: variable = (t ‘The variable will be assigned wit the test condition is true or false respectively. For example: a= b=3 max = (a>b)? & Here, the value 5 is stored in ™ min = (b>a)? arb; In this case, value 3 is stored in min, aS TNS es 1. Rewrite the snippet by using Ternary operators: if((a+b)>c) { String s ) if((atb)c)? “Third number is smaller": “Third number is greater”. 2. Rewrite the following program segment using if....clse statement. , comm = (sale>15000) ? sale*5/100 : 0; [ICSE 2013) ‘Ans. Snippet by using if....clse statement: if(sale > 15000) comm = sale * 5/100; else comm = 0; operands. ds Up test condition)? Expression ° . fh the value of "EX! yn a>b is true, ax, as the test condition bpa is false. “Third number is smaller”; “Third number is greater”; « Nested Ternary Operator When a conditional operator is used within another conditional operator, it is called « ‘Nested Conditional Operator’ For example: ‘A program snippet to find the greatest number am i jong thre mbers nested ternary operator: = ima = 5, b= 12,¢=3; 32 | Understanding: Computer Applications with BlueJ—X _—_—e Scanned with CamScanner max= (> py (@>o)2a: ib >) 2b: ¢; Seni aa Test condition Expression | Expression 2 The test condition a>b is false, Hence, the test condition b>e is true which enabli Hence, max = 12, it will operate expression 2. In expression 2, les value 12 to be stored in max. « Relational Operators There are some operators that are used to show the relation among the operands such as less than, greater than, equal to, not equal to, etc, They are basically used to compare the values of tWo operands and results in True or False accordingly. The different types of relational operators are as follows: CL < Less than = > Greater than ab <= Less than or equal to aS-4 id Greater than or equal to aed Equal to aanl Not equal to aleb « Logical Operators The logical operators are the operators that are used between two or more conditions in a Java statement. They result in true or false depending upon the values in all the conditions. The logical operators used in Java are && (AND), ll (OR) and (NOT). + Logical AND (&&) This operator results in true if all the conditional operands associated with it are true. eg, (a>b) && (arc) The following table illustrates the use of logical AND (&&) operator. False False False False ‘True False ‘True False False True True True + Logical OR (|) This operator returns false when all the conditional operands associated with it are false, otherwise true. CB (a> b) Il @e) la Revision of Class 1X Syllabus | 33, Scanned with CamScanner ferstand its return value with a table shown below: Let us unde Prise wre us yaees oa] False False False False True Truc ‘Truc False ‘True ‘True ‘True ‘Truc + Logical NOT () ical NOT operator used along with a conditional operand reverses the result, 4 cas if the condition is false it will result in true and vice-versa. eg. \a>b) a>b "a> b) False True True False | Points to Remember! Precedence of logical operators fs NOT (!), AND (&&) and OR (I). When a statoment Contains all the three logical operators then NOT operator will be performmed first. Example: it (arb) && (Oe) (ba) 4 (eob)) oa a o Oo Order of the operations is: 1 ———» 2» 3 NoT AND oR Solution 2 = (Hy * (yHt + 5) 15 * (15 +5) = (15 * (20)) = (15 * 20) = 300 34 Understanding Computer Applications with BlueJ—X Scanned with CamScanner [BREED 10a = 5; fina the value of a- = 4404 ane 44 Solution = +atatt+4 8-9 +944) =8-22 =-14 EEE a= 12, b=8; find the value of a = +4a/6 + bt+ % 3 Solution ++al6 + b+ % 3 12*(++4a/6 + b++ % 3) = 12 *(13/6 + 8%3) = 12*(242) = 48 If x = 45 find the value of x+ = x44 * 44x % 2 Solution Xt = Xt++ * 44x % 2 X= 4+ (46) %2 = 4+ (24%2) eden If a = 48, b =13; find the value of a+ = b++ * 5 /a+++b Solution at = bt+ * 5 /at++b a= 48 + (13 * 5/48 + 14 48 + (65 / 48) + 14 4841414 63 " Revision of Class IX Syllabus | 35 Scanned with CamScanner REVIEW insight 2 | Q4_ What are the values of x and y when the following statements are executed? | int a=63, b=36; boolean x=(a>b)2a: int y=(acbyrat; in| Ans. The given condition statement is incorrect: boolean x=(a>b)Pab; It should be : boolean x=(a>b)?true : false; then, the values of x and y will be x= true y= 36 Q2 What is meant by the precedence of operators? LICSE 2013) ‘Ans. The hierarchical order in which the operators are used for carrying out operation is known, as precedence of operator. ©» Precedence of arithmetical operators : Brackets, Exponent, Multiplication/ Division, Addition /Subtraction. Precedence of logical operators + Not, and, or (, && and | |) 23 Operators with higher precedence are evaluated before operators with relatively lower Precedence. Arrange th _ ' operators given below in order of higher precedence to lower Precedence. @ && (i) % (ii) >= (io) ++ ICSE 2014) Ans. The correct order of precedence of operators is: Ow j) % (i) >= (o) &&e 4. Give the output of the following method Public static void main(String{] args) ( int a = 5; at; System.out printin(a); ais a System.out.printin(a); 1 Ans. 6 and +4 oe QS Evaluate the value of n, if value of P=5, q=l9 int n= (a>) > (Pa? Gp): (gh Ans. n=14 rar (ap) na UICSE 2015] $61 Understanding Computer Applications with Blued—x Scanned with CamScanner I, State whether the following statements are “True’ or ‘False’: 1. The precedence of operators in Java follows BODMAS. 2. The output of at+ will be 1, if int a = 3. The relational operators always result in terms of ‘True’ or ‘False’. j 4, Given: int m=5; m*=5 then the value stored in m results in 55. 5. The statement (a>b)&&e(a>c) uses a logical operator. 6. If int a=: b=4,c=0; then ¢ = a%b; results in 3. 7. The statement p+=5 means p=p'5. 8. In the precedence of logical operators; NOT is followed by AND. Il. Write the Java expressions for the following: L2=58 4 2yx+y (ICSE 2011] 6. p= a2 + b% 2ab [ICSE 2015] eae 2m= aH 7. y = Alb+bhsth) ee a,b 3.5m uts Sat NcsE 2013] & p= + ww ate gave d [ICSE-2006] Vara WT. fas s.a=SEis UCSE 2018) 10. q= he + IIL. Predict the output: 1. int c= Bcd)? 34344; 2. int a = 14, b=4; boolean x = (a>b)? true: false; 3. int x = 90; char ¢ = (x<=90)? ‘2; 4, int a = 18; int b = 12; boolean t = (3>208& be 15)? truesfalse; 5. ¢ = (val + 550 < 1700)? 200: 400; ifs (a) val = 1000 (@) val = 1500 IV, Answer the following questions: 1. What is an operator? What are the three main types of operators? Name them. 2. How is Java expression different from statement? 3. Explain the following with one example each. (a) Arithmetic operator (®) Relational operator (©) Logical operator (@ Ternary operator 4. Distinguish between: (a) Unary & Binary arithmetic operator (b) Postfix increment and Prefix inerement {6) Postfix decrement and Prefix decrement (@ (p= q) and Mp == 4) Revision of Class IX Syllabus | 37 Scanned with CamScanner

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy