Formatting page ...
CHAPTER NO.1 OBJECT ORIENTED PROGRAMMING 1. What is OOP? Name any two OOP languages. Object Oriented Programming is an approach to standardize the program by creating portioned memory area for both data and function. It has been developed to increase the programmer s productivity and also to overcome the traditional approach of programming. In this system, the complete problem is decomposed into a number of entitles called objects. OOP languages are C++, Java, Small talk etc. 2. What are the features of OOP? It gives stress on the data items rather than function. It makes the complete program simpler by dividing in into number of objects. You can easily modify the data without any change in the function. 3. Name the Basic Elements (Principles) of OOP. Object, Classes, Data Abstraction, Encapsulation, Data Hiding, Inheritance, Polymorphism and Dynamic Binding. 4. Define the following with examples each. i) Object: It is a unique entity, which contains data and functions (characteristics and behavior) together in an OOP language. Eg. Book: - Characteristics Chapter, pages, topics. Behaviors Used to read, prepare notes. ii) Class: Class is a set of similar objects. Each object of a class possesses same attributes and common behavior defined within the same class. Eg. If we define a class Car , then different types of cars like Maruti, Santro, Indica, Nano are referred as objects under that category. iii) Data Abstraction: Abstraction refers to an act of representing essential features without including background details. In OOP, abstraction is the absolute property of a class. The class encapsulates the data items and the functions to promote abstraction. Eg. If we create an object Employee from a class name Salary and let name, designation and basic pay are the data members and Gross( ), PF( ) and Net ( ) are the methods, then the object Employee allows to access only essential features i.e. the methods, which in turn manage the data internally to perform the tasks. iv) Inheritance: It is the process by which objects of one class can link and share some common properties of the object from another class. Eg. Circle is a part of the class two-dimensional, which is in turn a part of the class Mensuration. v) Polymorphism: It 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 interface. 1 | Page Important Notes for Java Eg. If you develop a function to perform the addition of two numbers, the same function will produce the concatenated string, if string arguments are passed to the function. vi) Dynamic Binding: It is the process to link the function call with function signature at run-time. vii) Encapsulation: The system of wrapping data and function into a single unit (called class) is known as Encapsulation. Eg. A remote control of a TV set (a real world object) is used for operating all the function of that particular TV, but can t be used for operating various functions of another TV. 5. Explain Data Hiding. The insulation of data that does not allow it to be accessed directly outside the class premises, although they are available in the same program, is known as Data Hiding . 6. A class is termed as Object Factory, explain. Class is a prototype (model) of an object. Each object belonging to a specific class possesses the data and methods defined within the class. It produces objects of similar type. Hence, a class is termed as object factory. 7. Class is a user defined data type. ( OR ) Why is class known as composite data type? Comment. Java language uses some pre-defined data types viz. int, float, and char. These data types are also known as Composite Data Types , which provide some preliminary facilities in java programming. Similarly, a user may create data type and declare certain characteristics and behavior within it. This can be done by using a class. This is the reason why a class is referred as user defined data type. 8. Why an object is called an instance of a class? As the object encapsulates the state and behavior present inside the class thereby we can say object is an instance of class. 9. How will you consider Mobile Phone a real world object? Anything which has characteristics and behavior can be called as an object. Characteristics of mobile phone are it is portable, small in size etc. Behavior is used to talk with friends anywhere in the world. That is why mobile phone is a real world object. 10. What does the following mean? / Steps to create an object of a class. Flower rose = new Flower ( ); This statement will create an object name rose, of Flower class. The new operator allocates memory and calls the default constructor of Flower class. 11. State the Difference between Class and Object Class It is a representation of only an abstraction. It is an object producer and hence called a blue print for a set of objects 2 | Page Object It is a real and unique entity having some characteristic and behavior. It is created with the use of new operator. Important Notes for Java It is known as Object Factory It is known as an Instance of Class 12. Why class is called an Abstract data type? In OOP the class encapsulates the data items and the functions. The data members are accessed only through the related functions. Since, a class uses the property of abstraction; it is also called as abstract data type. 13. Give the file extensions in java programs. The source code of java programs are (.java) and the compiled byte code files are (.class) files. 14. What is BLUEJ? The BlueJ is an integrated development environment (IDE) to teach java language to the beginners and new users. It has a features like built-in program editor, virtual machine, debugger etc. CHAPTER NO.2 HISTORY AND DEVELOPMENT OF JAVA 1. State the different types of Java programming. Stand Alone System (Java Application) and Internet Applets (Java applets) are the two types of Java programming. 2. State the basic features of Java. 3 | Page Important Notes for Java Java is an OOP language. Java programs are both compiled and interpreted. Java programs are platform independent. It can be access data from a local system as well as from net. It is case sensitive language. 3. Define the following terms i) Compiler: The software by which the conversion of the high level instructions to machine level language is done all at once and all the errors are listed together, it is known as compiler. This is a much faster process but sometimes it become difficult to debug all the errors together. ii) Interpreter: The software, by which the conversion of the high level instruction is performed line by line to machine level language, is known as an Interpreter. If an error is found on any line, the execution stops till it is corrected. iii) Byte Code: The program (HLL) written in Java is compiled for conversion to an intermediate code called Byte Code. This code is independent of the machine on which the program is to run. This makes a Java program highly portable as its byte code can easily be transferred from one system to another. iv) JVM : When the Byte code is run on any system, an interpreter, known as Java Virtual Machine (JVM) is needed which translates the byte code to machine code. Java machine code varies for different platforms like Windows, UNIX etc. Thus, Java interpreter converts byte code to the machine code accordingly. JVM acts as a virtual processor. That is why it is called as Java Virtual Machine. 4. A Java program uses a Compiler as well as an Interpreter. Explain. The program(HLL) written in Java is compiled for conversion to an intermediate code called Byte Code. This code is independent of the machine on which the program is to run. When the Byte code is run on any system, an interpreter, known as Java Virtual Machine (JVM) is needed which translates the byte code to machine code. Thus a Java program uses a compiler and interpreter. 5. Explain the significance of the following Java library packages. i) java.lang : to support classes containing String, character, Math, Integer etc. (called by DEFAULT) ii) java.io : to support classes to deal with input and output statements. iii) java.applet : to support classes to generate applet. iv) java.net : to support classes for network related operation and URL v) java.awt : to support abstract window took kit and to manage GUI vi) java.txt : for supporting text elements such as dates, times, currency. vii) java.math : to support mathematical functions (square roots) int and deci. 6. What are reserved words (key words)? Give examples. They are the words preserved with the system and they cannot be applied as a variable name in any program. Eg. int, float, double, if, else, for, switch, break etc. 4 | Page Important Notes for Java 7. Name the different styles of expressing a comment in Java programming. (OR) State the significance of comment in Java Programming. Sometimes it become difficult for a user to understand the logic applied in a program particularly when any other person has developed it. In such cases, the programmer keeps mentioning the purpose and action being taken in different steps. This can be made possibly only by applying comment in the program. There are three ways to give a comment in programming. i) // : used for single line comment ii) /* comments to be written */ : used for multi-line comment iii) /** documenting comment */ : used for brief documents. 8. Why JVM is termed as a machine although it is software? JVM acts as a virtual processor, which processes the byte code to machine code instruction for various platforms. JVM acts as if it is a machine that is why JVM termed as a machine although it is software. 9. Explain the significance of the following terms. i) public : It is used to declare that the file access has no restriction. ii) static : It is a keyword that instructs the complier that the following functions should run before anything else in the program. iii) void : It indicates that the following function will not return any value. iv) class : It is keyword to declare a class. The keyword is followed by the class name. CHAPTER NO.3CONCEPT OF DATA TYPES IN JAVA 1. Explain Tokens and its types. Each individual character used in a Java program is termed as token. It is the fundamental unit of a Java program. The various types of tokens available in Java are Literals, Identifiers, Assignments, Punctuators, Separators and Operators. 2. Define (Explain) the following 5 | Page Important Notes for Java i) Literals (Constant): Literals are the constants in Java program. When you write a program in Java, you may come across some quantities which remain fixed throughout the discussion of the program. Such quantities are termed as Literals /Constants. Eg. String Literals, Real literals, Character literals, Boolean literals, Integer Literals. ii) Punctuators: They are the punctuation signs used as special characters in Java. Eg. ? (question mark) ; (semi colon) . (dot) etc. iii) Separators: They are special character in Java, which are used to separate the variables or the characters. Eg. Braces (, ) Curly braces {, } Square braces [, ] etc. iv) Operators: They are basically the symbol or tokens to perform arithmetical or logical operations to yield meaningful result. They are of three types : Arithmetical Operators: +, - , /, * etc. Relational Operators: <, >, ==,!=, <=, >= etc. Logical Operators: &&, || and ! Etc. v) Static initialization: This process uses direct assignment of a variable with defined constant. The variable is initialized during its declaration (i.e. before the actual use in the programming logic) e.g. int a=5; double d=5.3; vi) Dynamic initialization: When a variable gets initialized at run time i.e., during the execution of program logic is termed as Dynamic Initialization. E.g., int a,b,c; c=a+b; vii) Pure Arithmetic Expression: An arithmetic expression which, contains same type of data items (variables or constants) is called Pure Arithmetic expression. E.g. int a,b,c; c=a+b*8-a; viii) Mixed Expression: An expression, which includes different types of variable or values to yield a result, is known as Mixed expression. E.g. int a, float b, double d; double x = a+ b*d; ix) Implicit type conversion: In mixed expression, the data type of the result gets converted automatically into its higher type without intervention of the user. This system of type conversion is known as Implicit type conversion or coercion. Hierarchy of data type is as follows from lower to higher byte char short int long float double. x) Explicit type conversion: When the data type gets converted to another type after the user intervention, the type conversion is known as explicit type conversion. This type of conversion is also called forced conversion or type casting. E.g. int a,b; float x=(float)(a+b); 3. Explain the significance of Escape Sequences with examples. There are some non-graphic characters, which are used as commands to direct the cursor while printing. These characters are frequently used in Java programming called escape sequences. An escape sequence character begins with a black slash (\) and it followed by one or more character. Escape Sequences Non Graphic Character \t Horizontal Tab 6 | Page Important Notes for Java \v Vertical Tab \\ Backslash \ Single Quote \ Double Quote \f Form feed (Clear Screen) \n New line feed. 4. Explain Primitive and Non-Primitive Data types. The data types, which are independent of any other type, are known as Primitive data types. These types are also called Basic Data Types. E.g., byte, int, long, float, double etc. Primitive data types are pre-defined or built-in data types because the system developers of Java have defined them. Non-Primitive are basically defined as derived data types. They are directly or indirectly dependent on primitive data types. The method of storing non-primitive type data is different from primitive type data. They store the data values with reference to the addresses or locations. So, they are also called Reference Data type e.g. classes, arrays etc. 5. What is the difference between a with example. Expression An expression may contain variables, constants and arithmetical operators together to produce meaningful result. Eg. x+y*4-c statement and an expression? Explain Statement If an expression is assigned to a variable then it is known as statement. Z=x+y*4-c CHAPTER NO.4OPERATORS AND EXPRESSIONS IN JAVA 1. What are operators? Explain its types. 6. An operator is basically a symbol or token, which performs arithmetical or logical operations and gives meaningful result. (The values, which are involved in the operation, are termed as operands) Basically there are three types of operators. i) Arithmetical operators: They are used to perform arithmetical calculations in a program. E.g. +,-,*, / and % etc. ii) Relational operators: They are used to show the relationship among the operands. They compare the values of the variables and result in terms of true or false. E.g. <, >, <=, >=, ==, and !=. 7 | Page Important Notes for Java iii) Logical operators: They are used to apply logical condition is a decision control statements. E.g.&& (AND), ||(OR) and !(NOT) 2. Define (Explain) the following terms i) Unary Operator: An arithmetical operator, which is applied with a single operand, is known as Unary Operators. E.g. +, -, ++, --. ii) Binary Operator: An arithmetical operator, which deals with two operands, is known as Binary Arithmetic operators. E.g. +, -, *, / and %. iii) Ternary Operator: It deals with three operands. It is also called conditional assignment statement because the value assigned to a variable depends upon a logical expression. Syntax- variable= (test expression)? Expression1:Expression2 the variable contains the result of expressio1 if the test condition is true, otherwise expression2. iv) Shorthand operations: Java allows the use of shorthand binary operations i.e., an expression can be written in short form eg. A=a+b can be written as a+=b, it can be formed only when a variable is used as an accumulator in the expression i.e., same variable is to be used after and before the assignment sign. 3. Differentiate with two points between operator and operand. An action performed on one or more variable to modify the value of one or more variables is known as an operation. A symbol used in an operation is called as operator. A variable or a value involved in an operation is called an operand. Eg. a+b, a and b are operands while + is operator. 4. Distinguish between i) Increment and Decrement operators ii) 8 | Page Increment Operators Increment Operator (++) increases the value of an operand by one. E.g. x=x+1 by applying increment operator it can be written as x++ or ++x. Postfix and Prefix increment Decrement Operators Decrement Operator (--) decreases the value of operand by one. E.g p=p-1 by applying decrement operator it can be written as p- or --p Postfix increment This operator is used after an operand whose value is to be increased by 1. It works on the principle CHANGE AFTER THE ACTION E.g. p=5; p=p++*4 Result is 20 Postfix and Prefix decrement Prefix increment This operator is applied before the operant whose value is to be increased by 1. It works on the principle CHANGE BEFORE THE ACTION E.g. p=5; p=++p*4 Result is 24 Postfix decrement This operator is used after an Prefix decrement This operator is applied before the Important Notes for Java iii) operand whose value is to be decreased by 1. It works on the principle CHANGE AFTER THE ACTION E.g. p=5; p=p--*4 Result is 20 / and % operant whose value is to be decreased by 1. It works on the principle CHANGE BEFORE THE ACTION E.g. p=5; p=--p*4 Result is 16 7. / is a division operator whereas % is a modulus operator int a=5,b=2 then a/b will return 2 whereas a%b will return 1 iv) (p!=q) and !(p==q) 8. (p!=q) in this case the computer is checking whether the value of p is not equal to q. !(p==q) in this case the computer will reverse the logic of the output (p==q), if it is true it will become false and vice versa. 9. What is meant by precedence of operator? Precedence of operators means the hierarchy or order in which the operators in an expression are evaluated when the expression has several operators. 10. Explain Scope of Variable with example. A variable declared in a block exists only within the visibility of that block. In the program snippet shown below the variable x is declared under if block. Hence, it remains alive till the internal block does not end. It is invalid to apply x outside the internal block. if(c>10) { int x; x=2*c; } CHAPTER NO.5 GENERAL PROGRAMMING AND DECISION MAKING IN JAVA 1. What is a compound statement? Give an example. A compound statement means a block of statements that are a part of single programming statement, and which are enclosed in a pair of parenthesis { }. For example if(a>0) 9 | Page Important Notes for Java {System.out.println ( Positive ); a=a*2; System.out.println (a) ;} 2. What are packages? How do we include it in a program? Package is a collection of classes to perform various functions. Every package has a name and it can be included with the program by using the keyword import. 3. What is the significance of import java.io.* in a program. Every package has a name and it can be included with the program by using the keyword import. Import java.io.*; is used to import the input output java library package. 4. All-important Mathematical functions NAME Math.sqrt( ) Math.min( ) Math.max( ) Math.pow( ) Math.log( ) Math.abs( ) Math.round( ) Math.floor( ) Math.ceil( ) Math.sin( ) Math.cos( ) Math.tan( ) Math.asin( ) Math.acos( ) 10 | P a g e DESCRIPTION RETURN TYPE To find the square root of a double positive number To find the minimum of the int or double two given arguments depends on given argument To find the maximum of the int or double two given arguments depends on given argument To find power raised to a double specified base To find natural logarithmic double value of a given argument. To find absolute value. Same as the input argument To find value in rounded Double form(same rule as we use in math for rounding) It returns a number down to Double the nearest integer.(watch closely for negative numbers) It return a number to the Double next higher integer. (Watch out the difference between floor and ceil with the help of the given examples) To find the sin, cos, and tan Double values of a given angle in radian as an argument Used to find the angle Double corresponding to the given Important Notes for Java EXAMPLE a=Math.sqrt(4) Output: 2.0 b=Math.min(5.3,4.8) Output:4.8 c=Math.max(5,4) Output:5 D=Math.pow(2,3) Output: 8.0 E=Math.log(6.25) Output=1.8325 int f=Math.abs(-9); Output: 9 G=Math.round(6.82f) Output=7 here f is for float data type. H=Math.floor(6.9); Output=6 H=Math.floor(-6.25) Output =-7 I=Math.ceil(6.9) Output =7 I=Math.ceil(-6.25) Output=-6 J=Math.sin(x) Here x is the angle provided in radian. J=Math.asin(x) Math.atan( ) Math.exp( ) value in sin, cos and tan respectively. It is used to find the Double exponential value i.e. ex. where e is the number K=Math.exp(6.25) Output: 518.0128 (approximately 2.718281828) it is similar to b=Math.pow(2.718281828,6.25); Math.rint( ) It return a truncated value of double L=Math.rint(6.25) the number(integer part by Output =6.0 removing fraction) and rounding Math.random( To return a random number Double M=Math.random( ) ) between 0 and 1(Check for all the possible modification in the book) 5. Name the different ways to get the data value within a Java program. 1) By assigning the value. 2) By using BlueJ system 3) by using Input Stream 4) by using scanner class 5) by using command line argument. 6. Explain the significance of Buffer . Processor is the fastest device in computer. Other peripheral devices are comparatively slower then processor. Due to speed difference it becomes difficult to have data communication between processor and peripheral devices. Hence a high speed memory is applied between I/O devices and processor used as a bridge to synchronize their speed. This high speed temporary storage (cache memory) is termed as Buffer. 7. Explain the purpose of default in a switch statement. Each case ends with a break statement, which acts as a terminator and the control comes out of the block. The switch case statement has a default statement, and it is executed only when the switch value doesn t match with the case. It doesn t require any usage of break as it is the last segment of the switch case structure. 8. What do you understand by Fall through ? In a program where multiple cases are available, the control needs to execute a specific case block for a given switch value. Under these circumstances, if break statement is not applied at the end of a case then the control enters into the next case statement for the execution. This unusual execution of more than one case at a time is termed as fall through. 9. State the difference between if else and switch case. if else 11 | P a g e Important Notes for Java switch case It results in a Boolean type value. It result in int/char type value. For true/false condition, either of two Specific case is operated for a given blocks are operated. switch value. It can perform tasks on a relational or It can only perform test for equality. logical expression No default operation A default case is used. 10. State the difference between testing and debugging Testing Debugging Testing is a process in which a program Debugging is a process in which the is validated errors in the program are removed Testing is complete when all desired Debugging is finished when there are verification against specification have no errors and the program is ready for been performed. execution. 11. Explain the types of error with examples. In general there are three types of errors that occur in a computer program. i) Syntax error: These errors result when the rules or the grammar of the programming language are not followed. Such errors typically involve punctuation, incorrect word sequence, undefined terms or misuse of terms. E.g. c= (a+b/2) has a syntax error because (;) is missing. ii) Logical error: It is an error in planning the program s logic. The computer actually does not know that an error has been made. It follows the instructions and executes the results, but the output may be wrong. The problem is that the logic being followed does not produce the desired result. iii) Run time error: In a program there may be some errors other than syntax and logical error which may come in the way of execution, known as run time error. These errors may occur due to dividing a number by zero or to find the square root of a negative number etc. CHAPTER NO.6ITERATION THROUGH LOOPS 1. What do you understand by a loop? What is its significance? Loop is Java programming is a set of instruction which will get repeatedly executed as many times we want. Loop helps to solve the real life complex problems, if we want to perform a particular task for the specified number of times, we can do it very easily with the help of loop statement. 2. What are the different ways to generate a loop? Loop can be generated in three ways 1) Using the keyword for 2) using the keyword while 3) by using the keyword do and while . 3. Write the general format of : i) for loop for(initialization of counter ; testing of counter with condition ; increment/decrement of counter ) 12 | P a g e Important Notes for Java { Multiple statements; } ii) while loop Initialization of counter; while(testing of counter with condition) { Multiple statements; Increment/decrement of counter; } iii) do while loop do { Multiple statements; } while(testing with condition); 4. Explain the use of break statement with example. (Also called as Jump statement) A break statement is used for unusual termination of a block. As soon as you apply a break statement, the control exits from the block.(A set of statements under curly braces). while(condition) { Multiple statements; if(condition is true) break; } 5. Explain the use of continue statement with example (Also called as Jump statement) The statement continue is just opposite of break statement. As soon as the continue statement is executed in a loop, the control skips rest of the statements for that value and resumes for the next iteration. while(condition) { Multiple statements; if(condition is true) continue; statements;} 6. Write the difference between while loop and do-while loop (entry controlled loop and exit controlled loop) While loop The while loop will not executed at all if the condition is not satisfied The while loop checks the condition first and then execution begins. It has a check before the entry in the 13 | P a g e Do-while loop The do-while loop will continue at least once. The do-while checks the condition after executing the loop once. It has a check after the loop is over for Important Notes for Java loop hence it is called as entry the first time hence it is called as exit controlled loop. controlled loop. Similarity between them is that both are looping statements. 7. What do you mean by infinite loop? Infinite loop is a loop in which the test condition always remains true and the loop repeats infinitely. In it the increment/decrement counter does not exists, so the condition will never be false. 8. Explain user controlled loop Sometime in a program we do require a loop, which make iteration based on the needs of the users. Such looping structure is termed as user controlled loop. E.g String m= yes ; while(m.equals( yes )) { Multiple statements; System.out.println( Want to continue . If yes press yes else no? ); m=in.readLine( ); } This loop shown above will keep repeating as long as the user enter yes for continue question. 1. 2. 3. 4. CHAPTER NO.7USING LIBRARY CLASSES What are library classes? Give examples. The classes which are already built in java are called library classes. These classes are grouped together and stored in a package. E.g. java.io contains input/output functions. Explain about input/output operations in Java. Java language uses the function read ( ) (E.g. a= System.in.read ( )) to accept a character from the keyboard and print ( ) or println ( ) (E.g. System.out.print(x)) to display the result on the screen. Here System.in.read( ) is an input stream belonging to the system class, which is, in turn an object of input steam class available in java.io package. Explain the different types of I/O streams used in Java programming. There are 3 types of I/O streams available with Java system. System.in, System.out and System.err The stream System.in is an input stream related with keyboard, System.out and System.err are output streams related with VDU. What do you mean by exception handling? How it can be done in Java system? 14 | P a g e Important Notes for Java Sometimes, during java programming, we come across a situation that it is difficult to say that our code segment is error free. Such unexpected situation may appear due to improper use of input resources or overflow situation. These situations are termed as Exception and to overcome such situation is known as Exception Handling. i) Try and catch keyword plays an important role in exception handling in a java program. (try-catch method) ii) If you want that the system is to be reported for an error then you can apply throws keyword. (exception handling with throws keyword) e.g public void getdata( ) throws IOException 5. What is a wrapper class? Give example. A wrapper class is a member of Java library Java.lang. It wraps the primitive data values in object. Some examples of wrapper classes are Integer, Double, Character etc. These classes extends the feature of basic data types. 6. Define Static Data member: A static data member is an instant variable which is global in the class and used commonly by all the objects of that class type. 7. Define Static Member method: A static member method is a member method which uses only static data member or static instant variables. 8. What are packages in Java? Package is a group of classes, which can be imported to a program so that the user may exercise the implicit facility available in it. A package in java program can be included by using import command. E.g. import java.util.*; some basic packages which can be imported for various fundamental operations are java.io, java.util, java.awt, java.net. 9. How is the scope of instance variable different from a local variable? The scope of instance variable is throughout the class, whereas the scope of local variable in only within the function in which it is declared. 10. Name the keyword which makes class member accessible outside the class in which they are declared. public 11. Name the package that is involved to manipulate characters as well as Strings. java.lang 12. State the difference between the following two functions. i) nextInt( ) ii) hasNextInt( ) nextInt( ) hasNextInt( ) It receives the next token from scanner This function returns true if the next object which can be expressed as an token can be expressed as an integer integer and stored in an integer type value, otherwise returns false. variable. 15 | P a g e Important Notes for Java CHAPTER NO.8STRING MANIPULATION IN JAVA ALL IMPORTANT CHARACTER FUNCTIONS NAME DESCRIPTIO RETUR N N TYPE Character.isLetter( ) To check Boolean whether a given argument is an alphabet or not. Character.isDigit( ) To check Boolean whether a given argument is a digit or not. Character.isLetterOrDigit( To check boolean ) whether a given argument is a letter or digit. 16 | P a g e Important Notes for Java EXAMPLE C=Character.isLetter( a ); Output=true C=Character.isDigit( a ); Output=false C=Character.isLetterOrDigit( % ) Output = false Character.isWhitespace( ) Check for given argument is a space or not. Character.isUpperCase( ) Check for argument is upper case letter or not Character.isLowerCase( ) Check for argument is lower case letter or not Character.toUpperCase( ) Convert the argument to upper case Character.toLowerCase( ) Convert the argument to lower case ALL IMPORTANT STRING FUNCTIONS NAME length( ) charAt( ) indexOf( ) lastIndexOf( ) substring ( ) toLowerCase( ) toUpperCase( ) replace( ) 17 | P a g e DESCRIPTION Find the length of the string Returns the character for the given position no. Returns the position no. of the string Returns the index of last occurrence of a character Returns the extracted part of the string Converts the string to lower case Converts the string to upper case Replace the char by another char or string by another sting. Boolean C=Character.isWhitespace( ) Output =true Boolean C=Character.isUpperCase( a ) Output= false Boolean C=Character.isLowerCase( a ) Output= true Char B=Character.toUpperCase( a ) Output =A Char B=Character.toLowerCase( S ) Output =s RETURN EXAMPLE TYPE Int A= Wisdom .length( ) Output =6 Char C= Wisdom .charAt(3); Output=d Int int a= Wisdom .indexOf( d ); Output= 3 Int int a= Malayalam .lastIndexOf( a ) output = 7 A= Wisdom .substring(3) Output=dom A= Wisdom .substring(2,5) Output=sdo A= WISDOM .toLowerCase( ) Output=wisdom String String String A= wisdom .toLowerCase( ) Output=WISDOM String A= wisdom .replace( s , x ) Output=wixdom A= all the best .replace( best , worst ); Important Notes for Java concat( ) To join two string String equals( ) Compare two string for equality (same) Compare two string for equality (same)with ignoring case Check for equality of two strings, and also check whether a string is bigger, smaller than the other. Removes blanks from either side Boolean Check whether given string has specified suffix or not Check whether given string has specified prefix or not Boolean equalsIgnoreCase () compareTo( ) trim( ) endsWith( ) startsWith( ) 18 | P a g e Boolean int String Boolean Important Notes for Java Output=all the worst A= wisdom .concat( high ); Output=wisdomhigh Z= wisdom .equals( high ) Output=false Z= wisdom .equalsIgnoreCase( hig h ) Output=false A= TOY .compareTo( CAR ); Output=17 (check with different inputs) A= computer application .trim() Output=computer application Z= car is a toy .endsWith( car ); Output=false Z= car is a toy .startsWith( car ); Output=true CHAPTER NO.9ARRAYS 1. What is an array? (Dimensional Array) An array is a structured created in the memory to represent a number of same type of data (int/double/string etc.) with the help of single variable. An array is also called as subscripted variable. 2. Explain the difference between linear search and binary search Linear search It works for both sorted and unsorted data. The search begins at the start of an array (i.e. from 0th position of an array) Binary search It works only for sorted data items. An array is divided into two halves and then the search stats either in the first half or the second half 3. Explain the difference between selection sort and bubble sort Bubble sort In this method the array is sequentially scanned several times and during each iteration the pairs of consecutive elements are compared and interchanged, if necessary, to bring them into specific order. 4. Explain the difference between length Selection sort In this method the successive rounds are executed to select the element in some order and place them into their positions. and length ( ). Length length( ) It is a variable used with array which It is a function used with strings which returns the number of elements present returns the number of character present in it. in it. 5. Explain the difference between ordinary variable and array (subscripted) variable 19 | P a g e Important Notes for Java Ordinary variable Array variable It has a capacity to store only 1 value at It has a capacity to store multiple a time. values at a time. It is not accompanied by [ ] It is always accompanied by [ ] 6. What is a subscripted variable? State its advantage. It is a structured created in the memory to represent a number of same type of data (int/double/string etc.) with the help of single variable. Its advantages are as follows: It uses optimum memory space. User can use one variable (subscripted variable) to store hundreds of value in it with the help of an array. 11. How many bytes are required to store an int type of array arr [15]? Since int require 4 bytes(32 bits) to store a value, the array is having 15 elements in it. 15 x 4 = 60 bytes (15 x 32 = 480 bits) 12. Write a short note on Binary search. It s a technique in which an array is divided into two halves, then the searching takes place in either half of the array, the searching continues by further dividing the either half in two, if the element is not present. However, the binary search can be applied only when the array elements are sorted. It works in minimum possible time. 20 | P a g e Important Notes for Java CHAPTER NO.10BASIC INPUT/OUTPUT (Scanner and Printer Classes) 1. Name the package in which the scanner class is defined. It is defined within a package java.util. 2. What is the use of Scanner class? Scanner class is use to input the values of various data types through keyboard or file without going through any conversion system. 3. Name the package which can be imported to allow the use of scanner class. import java.util.Scanner; 4. Write the syntax to create the scanner object. Scanner sc= new Scanner(System.in); 5. Write a syntax to create the PrintWriter object. PrintWriter so=new PrintWriter(System.out, true); 6. In what way the following data can be read from scanner object? Integer type : int p=sc.nextInt( ); Float type : float f=sc.nextFloat( ); Double type : double d=sc.nextDouble( ); String type : String p=sc.nextLine( ); where the scanner object is Scanner sc= new Scanner(System.in); 7. What is mean by invoking a function? A process of using a method in a program is referred as calling a method or invoking a function. 8. Explain Formal Parameter The parameter, which are described in the function definition (receive the value) are called as Formal Parameter. E.g. int Add (int m, int n) here int the return type of the function name Add and (int m, int n) are formal parameter. 9. Explain Actual Parameter The parameter described in the caller definition (the values passed to the method) are known as Actual Parameter . E.g. p=ob.Add(a,b); here function Add is being called by ob.Add and (a,b) are actual parameter. 10. Explain Pass by Value It is the process of passing a copy of actual parameter to the formal parameter. Any change made in the formal parameter does not reflect on the actual parameter. All 21 | P a g e Important Notes for Java primitive data type such as int , float, char, double are by default passed to the function by using pass by value system. 11. Explain Pass by Reference It is the process of passing a reference (address) of the actual parameter to the formal parameter and any change made in the formal parameter will be reflected on the actual parameter. In java the non-primitive data (arrays, objects) to be passed to the method as pass by reference. 12. Explain Pure Function A function, which returns a value to its caller module, is called as Pure Function . It is also called accesser method, as it doesn t change the state of an object. 13. Explain Impure Function An impure function may not return a value. It basically changes the state of an object during call. It is also called as Mutator. 14. Explain Function Overloading Javalanguage facilitates designing a number of functions with the same function names. However their parametric types must be different. Such functions are called overloaded functions and the system is said to be function overloading. Through function overloading java implements Polymorphism. 15. Explain Static Binding When the programmer uses the concept of function overloading the compiler during compilation finds the function by matching the types and number of arguments to insure which of the function will be called. This system is known as Early binding or static binding. 16. What are the two ways of invoking a function? They are 1. Call by value 2. Call by reference. 17. What are the advantages of defining a method/function in a program? Method/Function is a set of statements referred by a single name. Its advantages are i) Reusability ii) To cope up with complexities. 18. Explain as how you define a method/Explain function prototype. The general form of defining a method is as follows <Access-specifies><Return Type><Function Name>(Parameter list) A function prototype is the first line of a function definition. With reference to the above form the function prototype is : public int Add(int a, inb b) 19. What is the role of keyword void in declaring a function? Void specifies that the function will return null value. The function which explicitly does not return a value has a return type void. 20. Write the features of return statement. i) It is applied at the end of a method, from where it terminates. ii) No statement in the method can be executed after return statement. iii) It can return a single value from a method to its caller. 21. Write the prototype of a function search which receives a sentence sente 22 | P a g e Important Notes for Java and a word wd and returns 1 or 0 and having a default access specifier. public int search (String sente, String wd) CHAPTER NO.12 CLASS AS A USER DEFINED TYPE 1. Write the syntax of creating object of a class. Sum ob=new Sum ( ); Here Sum is a class name ob is the object (you can use any name here) new is the keyword used for allocating dynamic memory of an object Sum ( ) is a constructor 2. Write the difference between User defined data type and Primitive data type User-defined data type Primitive data type These data types are created by the These are built in data types, which are users. provided by the system. They are available in accordance to These data types are available with the their visibility modes throughout the system. program. 3. Which OOP concept is implemented by using class? Data Hiding 4. Explain the contents of a class. The content of a class is divided into two. i) External wrapper ii) Internal content External wrapper is the class declaration enclosing inner part within a pair of curly brackets. E.g. class calculate { // inner part of the class } Internal content of a class contains the following Instant variables, Constructor and Member method 5. Explain Access Specifier Access specifiers are also known as visibility modes. They are categorized as follows i) Public ii) Private iii) Protected 23 | P a g e Important Notes for Java Public: The class members (variable or method) specified as public can be used even outside the visibility of a class. Private: The data members (Instant variables or member methods) which are specified as private can be used only within the scope of a class. These members are not accessed outside the class. Protected: The protected members are used in the class as private members which can only be applied within the class but can be applied to another class during inheritance. 6. Explain the significance of new operator. New operator is used to create a class object or an array. It allocates memory and returns the reference of memory at run time. 7. Differentiate between static and non-static data member. Static data member Static members are the members which maintain a single copy for the whole class and are shared by all the objects of that class. They are also known as class variables Non-static data member Non-static members are the members which maintain a separate copy for each and every individual object of that class. They are also known as instant variables Imp:- the keyword that differentiate between instant variable and class variable is static. 8. State the significance of the following keywords i. this :- it is used to store the address on the currently calling object. The object on which the function is called can be referred in the function with this. It is also used to shift the values of function arguments to the instant variable of an object with the same variable name. 9. Difference between throws and throw keyword Keyword throws written on the method header indicate that the method has instructions that might create some kind of exceptions and hence must be handled by the Java system even without writing a separate error handler. Keyword throw is used to force an exception even if some system error has not occurred. This can be used to give some user defined error message when some unwanted condition is reached and the user wants the program to be discontinue after the particular instruction. 10. Write a short note of Visibility Modifiers public : the member is accessible from all classes inside or outside the package. private : the member is accessible only within its own class. protected : the member is accessible by any subclass or other classes in the same package. Modifiers 24 | P a g e Class Subclass Important Notes for Java Package Everywhere/ outside package private protected public Yes Yes Yes No Yes Yes No Yes Yes No No Yes CHAPTER NO.13 CONSTRUCTOR 1. What is constructor, name its types. A constructor is a member function with a name same as that of all the class name and is used to initialize the instant variable of the objects. Constructors are of three types. i)Default constructor ii) Parameterized constructor iii)Copy constructor 2. Mention the features of Constructor. i) Constructor is defined with the same name as a class name. ii) Constructor is automatically called while creating an object. iii) Constructor needs no return type. iv) Constructor is always public. v) Constructor is overloaded automatically vi) Constructor is only created to initialize the data members/instant variables. 3. Explain Default constructor. A constructor which initializes instant variable of an object with definite values readily defined is known as default constructor. 4. Explain Parameterized constructor. A parameterized constructor is a member function with same name as the class name which is used to initialize the object variables by passing parametric values at the time of its creation. 5. Explain Constructor Overloading A process to use a number of constructors with the same name but different types of parameter list is known as constructor overloading. E.g. class constructor { inta,b; constructor ( ) { a=0; b=0; 25 | P a g e Important Notes for Java } constructor(int x, int y) { a=x; b=y; } } 6. Differentiate between constructor and method Constructor Function/Method Constructor has the name same as that Function has name other that class of the class name name. Constructor doesn t require to be called Method is called from the main class. from the main class It does not return any value It may or may not return any value. 7. Define Encapsulation It is the process of wrapping of data and function together as a unit and this can be made possible by using class member private. 8. Define Inheritance It is a process according to which some properties of a class are shared by another class or classes is known as inheritance. 9. Explain Base class and Derived class A base class is a class which is inherited to another class. A derived class is one which inherits a base class. 26 | P a g e Important Notes for Java PREDICT THE OUTPUT 1. 2. 3. 4. 5. 6. 7. 8. 27 | P a g e int a=300,b=400,c; if(a>=400) b=300; c=200; System.out.println(b+" "+c); int x=10,y=20; if(x==y) System.out.println(x+" "+y); int x=3,y=5; if(x==3) System.out.println(x); else; System.out.println(y); int x=3; double y=3.0; if(x==y) System.out.println("x and y are equal "); else System.out.println("x and y are not equal "); int i=65; char j='A'; if(i==j) System.out.println("Java is WOW"); else System.out.println("Java is Headache"); What is the resultant type if the following implicit conversion is performed? int i, float f, double d, char c, byte b; i +f c + b/d Evaluate the following expression, if the value of the variable p=6,m=15, and r=9; w=p*(m++/3)+p+(--r+r++) Write the output when int cash=1100, bal=350; Important Notes for Java 9. 10. 11. 12. 13. 14. 15. 16. int sum=cash+bal>1850?4000:2500; System.out.println(sum); Write the following expression in the Shorthand form. f=f*65 System.out.println(Character.isUpperCase( g )); System.out.println(Character.toUpperCase( H )); Rewrite the following using i. for loop. int a=1; while(a<=5) { int b=1; while(b<=a) { System.out.print(b); b=b+1; } System.out.println( ); a=a+1; } ii. Write the output of the program. Rewrite the following snippet using ternary operator. if(a>b) { if(a>c) max=a; else max=b; } else { if(b>c) max=b; else max=c; } Write all the possible values of n for the given function. int n=(int)((Math.random( )*6)+1); Give the output of the given program int z=18; for(int x=1;x<=z;x++) { if(z%x==0) System.out.println(x); } Write what mathematical operation in carry. Analyze the following program segment and determine i. How many times the loop will get executed. 28 | P a g e Important Notes for Java 17. 18. 19. 20. 21. 22. i. ii. iii. 23. 24. 25. 26. ii. Write the output int z=148; while(10>9) { if(z<139) break; System.out.println( Computer +z); z=z-3; } System.out.println(z); System.out.println( Computer Application .lastIndexOf( C )); String p= "Computer Application"; String s=p.substring(3,6); int c = s.length(); System.out.println(c); String a = Gopal is a Good boy ; a=a.replace( good , bad ); a=a.replace( o , a ); System.out.println(a); String b= COMPUTER s WORK SHOP ; System.out.println(b.toUpperCase()); int s=7, t=11; s+=s++ - ++t +s; System.out.println( s= +s); System.out.println( j= +j); Write the output of the following System.out.println(!(8>5)||((5==5)&&(3>3.0))); System.out.println(5>3); System.out.println( We are the Students of\ Computer Application\ Class ); Rewrite the following code using switch case: if(mrk==100) System.out.println( Excellent ); else if (mrk==90 || mrk==80) System.out.println( Good ); else if(mrk==70 || mrk==60) System.out.println( Fair ); else System.out.println( Average ); What is the result produced by 2-10*3+100/11? Show the steps. Predict the output of the given statements or mention syntax error if there is? void main( ) { int j=4; System.out.println(!(j!=4)? \nWelcome : \nGood Bye ); } Write the output for the given statement. int z=13,y=10,a=100; 29 | P a g e Important Notes for Java 27. 28. 29. 30. 31. i) ii) 32. 33. 34. 35. a/=z++ + ++z *(--y y--)%3+z++ - ++y; System.out.println(a); Write the output of the following i. System.out.println(Math.abs(Math.ceil(-6.7))); ii. System.out.println(Math.sqrt(Math.max(5,Math.floor(9.9)))); Predict the output of the following int mrk_obt=256, tot=500; double per=mrk_obt/tot*100.0; System.out.println( The Percentage is +per+ % ); Spot the error if any in the program else write the output. int x=100,y=0,z=0; if(x>50) y=25; z=30; else y=80; z=90; System.out.println(x+ , +y+ , +z); Write the output data type of the given expression int a; float f; double d; char c; (float) (a/f)-d*c; Write the java expression for the following m=uv/(u+v) t= a+(cd)3 Solve the following and write the value of a when printed. int a=0,b=30,c=40; a+=--b + c++ +b*c + ++a%5; Rewrite the following snippet using ternary operator. if(income>200000) tax=10 else if(income>100000) tax=5; else tax=0; int a=1,b=2,c=3; switch(p) { case 1: a++; case 2: ++b; break; case 3: c--; } System.out.println(a+ , +b+ , +c); Write the output when p=1 and p=3 Observe the following snippet and answer the following questions 30 | P a g e Important Notes for Java intj,k=5; while(k>=1) { j=1; while(j<=k) { System.out.print(j); j++; } System.out.println( ); k--; } i) Rewrite it using for loop. ii) Write the output of the snippet. 36. Write the output of the following snippet String x= Applications ; String y= Computer ; System.out.println(x.indexOf(x.charAt(2))); System.out.println(y.substring(0,3)+x.substring(7)); System.out.println((x.length()>y.length())?(5>3):(4<33)); System.out.println(x.charAt("Kareena".compareTo("Karan"))); 37. Write the output of the given statement. System.out.println(Math.max(Math.ceil(8.3),Math.floor(8.3))); 38. i) ii) iii) iv) 39. 40. i) ii) System.out.println(Math.pow(Math.abs(-2),Math.rint(3.8))); What output will the following statement produce? String a = Wisdom ; String b = High ; System.out.println(a+b); System.out.println(a.length()+b.length()); System.out.println(b.charAt(2)); System.out.println(a.equals(b)); Write the output of the following: System.out.println(Character.isUpperCase( g )); System.out.println(Character.toUpperCase( H )); Analyse the following program segment and determine how many times the loop will be executed and what will be the output of the program segment? int a=100; while (true) { if(a<90) break; System.out.println("Wisdom"+a); a=a-2; } System.out.println(a); 31 | P a g e Important Notes for Java 41. What will be the result (true or false) of following two expression if i=10 initially. i) ++i<=10 ii) i++<=10 42. Write the corresponding expression of the following mathematical operation: z= x3+y3- xy/z 43. If a=4, b=3; find the value of c = a++ * 6+ ++b * 5 +10; 44. Write the output of the following String str= Rajesh ; System.out.println(str.replace( j , k ); 45. String x= Computer ; System.out.println(x.indexOf(x.charAt(4))); 46. Give the output. void test(int a, int b) { while(a!=b) { if(a>b) a=a-b; else b=b-a; } System.out.println(a); If a=4 and b=16 are passed to the function. 47. Write a java statement for the following. i. To display the 4th character of the string computer ii. To display 100th element of the array arr[ ] 48. Write the output of the following functions i. THAN .compareTo( THEN ) ii. Math.min(Math.max(60,70),5) iii. computer .startsWith( Comp ) iv. Math.ceil(-28.25) 49. Write the output of the given segment int a = 0; if(a>0 && a<20) a++; else a-- ; System.out.println(a); 50. What is the result of: i. Math.abs(q++* -2) if q=3 ii. char c= E ; short m = 26; int n = c+m; System.out.println(n); 51. What will be the output of the following code int i= 0, a=0,b=0,c=0; while(i<=5) 32 | P a g e Important Notes for Java 52. i. ii. iii. 53. 54. i. ii. 55. 56. 57. { switch(i++) { case 1: a++; case 2: case 3: b++; case 4: default :c++; } } System.out.println(a+ + b+ + c); Write the output of the following (int)( Scholar .charAt(2)) MISSISSIPPI .lastIndexOf( S ) kumarvivek .substring(3,4) Write all the possible values of n for the given function. int n=(int)((Math.random( )*6)+1); If int p=7 and int q=2 output the values of p and q after execution of p*=q; q=p+p/q Predict the output of the following statement System.out.println(!((7>5)||(13<1))&&(11>5)); Evaluate the given expression int k=5,m=13, r=7 p=(r++%7)+(--m/5)+k*(++k-10) Predict the output of the following statement System.out.println(Math.pow((Math.floor(3.80)),(Math.ceil(4.59)))); 58. i. ii. 59. Write the output of the following System.out.println("malayalam".substring(3,8).lastIndexOf('a')); System.out.println("computer".toUpperCase().replace("TE","te")); Correct the error in the following program segment and rewrite it: public void Add(int a,b) { int c=a+b; return(c); } 60. Predict the output of the given statements or mention syntax error if there is? i. void main( ) { int j=4; System.out.println(!(j!=4)? \nWelcome : \nGood Bye ); } ii. void main( ) { int i=1; while(i<=10); { 33 | P a g e Important Notes for Java System.out.print(i+ , ); i++; } } iii.float x=1.1f; while(x==1.1f) { System.out.println(x+","); x=x-0.1f; } 61. int count =0,sum=0; while(count!=10) { count=1; sum=sum+count; count++; } System.out.println(count); 62. 63. 64. 34 | P a g e Write the output for the given statement. int z=13,y=10,a=100; a/=z++ + ++z *(--y y--)%3+z++ - ++y; System.out.println(a); Rewrite the following code using switch case: if(mrk==100) System.out.println( Excellent ); else if (mrk==90 || mrk==80) System.out.println( Good ); else if(mrk==70 || mrk==60) System.out.println( Fair ); else System.out.println( Average ); Study the given function and answer the questions that follows it. int function(int a, int b) { intsm,la,ans; if(a<b) { sm=a; la=b; } else { sm=b; la=a; } ans=la; Important Notes for Java i. ii. 65. i) ii) iii) iv) v) vi) 66. 67. 68. 69. 35 | P a g e while(ans%sm!=0) ans+=la; return(ans); } What value will the function return if 7 and 5, are supplied to the function. What is function ( ) doing? Give the output of the following statements String s= There ,w= TheRE , x=s; System.out.println(s.equals(x)); System.out.println(s==x); System.out.println(w.compareTo(s)); System.out.println(s.toUpperCase( )==w.toUpperCase( )); System.out.println(w.endsWith( eRE )); System.out.println(s.indexOf( e )); What output will the following code fragment produce? char opn= b ; switch(opn) { case a : System.out.println( Java is platform independent ); case b : System.out.println( Java is Object Oriented ); case c : System.out.println( Java is Robust and Secure ); default: System.out.println( Wrong Input ); } What output will the following code produce? for(int i=1,j=2; i<=8; i++, j--) System.out.println(i++*j); What output will the following statement produce? System.out.println("BLUEJ".length()> "bluej".length()?true:false); System.out.println( Grade X Students .charAt(5)== X ) Does the following program is having any error, if no, write the output. public class trial { public static void main( ) { trialfunc = new trial( ); double x=func.first(2,8); double y=func.first(16); System.out.println( The value of x is +x+ The value of y is +y); } public double first( int x, int y) { return(Math.pow(x,y)); } Important Notes for Java public double first (int x) { return (Math.sqrt(x)); } } 70. 71. 72. 73. 36 | P a g e Study the following program and answer the question below. class q3 { static void main( ) { q3 paper = new q3( ); int m[ ]={15,13,11,9,7}; int k=paper.pro(m[3]); System.out.println( The value of k in the main function is +k); } int pro(int x) { x=x+2; System.out.println( The value of x in the pro function is +x); return(x); } } i. Is the program having an error? If yes, then after rectifying the error answer the following questions ii. What is the value of k in the main function? iii. What is the value of x in the pro function? iv. Name this style of passing the value to the function. v. What is the disadvantage of this style? vi. Name the data type that can be passed by this style. Analyze the following program segment and determine i. how many times the loop will be executed ii. And what will be the output of the program segment? int x=4,y=0; while(x>=0) { x--; y++; if(x==y) continue; else System.out.println( Value of x is +x+ Value of y is +y); } Evaluate the given expression int p=7,q=9, r=11 p+=(--p+5)*(q++)+(--r/2) Write the output of the following statements Important Notes for Java i. int num = 30; System.out.println(( num> 5 ? ( num<= 10 ? 100 : 200 ) : 500 )); ii. System.out.println(Math.abs(++t* -6)) if t=4 iii.System.out.println( Computer .compareTo( Commercial )); 74. Write the output of the following int i, j ; for ( i = 1 ; i <= 2 ; i++ ) { for ( j = 1 ; j <= 2 ; j++ ) { if ( i == j ) continue ; System.out.println(i+" "+j) ; } } 75. Correct the error in the following program segment and rewrite it: Int n[ ]=(3,6,9,12,15); for(int i=0;i<=5;i++) System.out.println( The value is +n[j]); 76. Write the output of the given statements while ( 'a' < 'b' ) System.out.println("\nmalyalam is a palindrome" ) ; 77. Study the following program and answer the question below. classgradeX { String na; inta,b,c; gradeX( ) { a=5; b=90; na= Wisdom High ; } voidgradeIX( ) { int x=1; for(int i=1;i<=a;i++) x=x*i; c=x; na=na+ International School ; } voidgradeXI( ) { System.out.println( The answer is +c); System.out.println( The answer is +na); } } 37 | P a g e Important Notes for Java i. Does the program have any error? If yes than after rectifying answer the following questions. ii. Name all the instance variables of the program. iii. Name all the local variables of the program. iv. Name all the member function of the program. v. What is the significance of the member method gradeX( ) vi. State the reason why x cannot be printed in member function gradeXI( ). vii.Do we required to execute the member method gradeX( ) if no, why? viii. What is the out of the program? (assuminggradeIX( ) is executed first and then grade XI ( )). 78. Predict the output of the following snippet i. int a[ ]= new int [5]; a[0]=4; a[4]=8; a[3]=12; a[1]=3; a[2]=7; System.out.println(a[2+1]); 79. int a [ ] ={2,4,6,8}; for(int i=0; i<2;i++) { int S=a[i]+a[3-i]; System.out.println(S); } 80. int a[ ]={5,7,9,11,13}; a[0]=9; a[3]=a[4]; int c=a[0]+a[3]+2+0; System.out.println(c); 81. int a[ ]={5,1,15,20,25}; int i=++a[1]; int j=a[++1]; System.out.println( The value of i is +i); System.out.println( The value of j is +j); 82. Study the snippet given below and answer the following questions. int perform(int num) { int r=0; do { int d=num%10; r=r*10+d; num=num/10; } while(num>0); return(r); } i. What value will the function return if 2008 is passed to the function? ii. What mathematical process is the function doing? 83. Evaluate the following expression where a=2, b=5, and c=7 here a,b,c are of 38 | P a g e Important Notes for Java 84. 85. is integer type a=++a * b--/(a++)%20+(++c) Write the output and justify your answer int a=1; for(;a<=10;a++); System.out.println(a); Write a block of code using switch case to check whether value in variable a odd or even. Write all the possible values of the following statement. System.out.println((int)((Math.random()*Math.rint(5.8)+Math.ceil(3.8)))); 87. Write the output of the given snippet for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print( * ); } System.out.print( ); } 88. Study the snippet given below and answer the following questions. void test(String m, String n) { if(m.compareTo(n)>0) System.out.println(m.compareTo(n)); else System.out.println(n.compareTo(m)); } i) If AMIT and amit are passed to the function. iii. If 15 August 1947 and August 15 2010 are passed to the function. 89. Predict the return data type of the following float m; System.out.println(m/3*(Math.pow(4,3)); 90. Write the java expression for the following (a+b)3+(m+n)1/2 91. Declare and Initialize an array of float type with the following values 3.2,5.7,2.9,7,4,6.6 92. For the given function write down the main function which calls it: int square (int a) { return(a*a); } 93. Write two ways to concatenate the following two strings together to get the String computer String fst= uter ; String lst= comp ; 94. Evaluate the following expression if int k=8, m=11,r=7. 86. 39 | P a g e Important Notes for Java W=k*(m++/3)+(k+(-r + r++)) 95. 96. Write the following statement using switch case construct. if(a==1) {b+=10; System.out.println(b); } else if(a==2) { b-=10; System.out.println(b); } else { b*=a; System.out.println(b); } Spot the error else predict the output of the following snippet. void test(int n) { int i=1; while(i<=n) { System.out.println(i); break; i++; }} If the value of n supplied is 5. 97. Predict the output System.out.println("Wisdom High".length()==("International".substring(2)).length()); System.out.println("Java applet".endsWith("applet".substring(0,4))); 98. 99. Write the output of the following System.out.println(Math.abs(Math.ceil(-6.7))); System.out.println(Math.sqrt(Math.max(5,Math.floor(9.9)))); Write the output of the following System.out.println("malayalam".substring(3,8).lastIndexOf('a')); System.out.println("computer".toUpperCase().replace("TE","te")); 100. Rewrite the following code using for loop. int a=5,b=25; while(true) { if(a>b) break; System.out.println(a+"\t"+b); a+=5; b-=5; } 40 | P a g e Important Notes for Java Write its output. 101. Predict the output of the given snippet. String x= Computer ; String y= Papaya ; System.out.println(x.indexOf(x.charAt(3)); 102. Consider the following code: class Check { public static void main( ) { int x=10,y=20; System.out.println(data(x,y)); } public int data(int a, int b) { return(a*b); } } Will it compile? YES or NO. Give reason. Also rectify the code if it will give error. 103. Study the following loop and answer the questions that follows inti,j,k; for(i=0;i<2;i++) { for(j=0;j<2;j++) { for(k=0;k<2;k++) System.out.println(i+ , +j+ , +k); } } How many times the print statements will get execute? Write its output. 104. Write a corresponding Java expression for the mathematical expression: z=(sin x + cos x)+ y3* t 41 | P a g e Important Notes for Java
|