Trending ▼   ResFinder  

ICSE Notes 2017 : Computer Applications (Hilton's School, Dehradun)

24 pages, 0 questions, 0 questions with responses, 0 total responses,    0    0
lawrence
 Dehradun 
+Fave Message
 Home > lawrence >   F Also featured on: School Page

Formatting page ...

JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 HIGH LEVEL LANGUAGE: These languages are machine independent and provides user-friendly environment to the users in developing their program to solve a problem using computer. These languages are not understood by the computer without the help of translator. LOW LEVEL LANGUAGE: These are machine language or Binary language which is understood by the computer. Programs written in High Level Language gets converted in Low level Language by the translator. COMPUTER PROGRAM: A computer program is a set of instructions given in a particular sequence to solve a given problem using computer. The computer follows your instructions exactly and in the process does something useful. COMPUTER PROGRAMMER: A person whose job is to develop or write computer programs to carry out a given task using computer. PROGRAMMING LANGUAGE: In order for a computer to recognize the instructions you give it, those instructions need to be written in a language the computer understands -- a programming language. There are many computer programming languages -Fortran, Cobol, Basic, Pascal, C, C++, Java, Perl -- just like there are many spoken languages. They all express approximately the same concepts in different ways. TRANSLATOR : It translates/converts a program written in a human-readable computer language (like Java) into a form(Machine Language) that a computer can understand and execute. In return it again translates machine codes into human-readable form so that user can understand it. The two types of Translators are:- 1. Compiler 2. Interpreter COMPILER : A compiler translates a computer program written in a human-readable computer language (like Java) into a form that a computer can execute. You have probably seen .EXE / .COM files on your computer. These EXE/COM files are the output of compilers. They contain executables -- machine-readable programs translated from human-readable programs. Difference between Compiler and Interpreter. COMPILER 1. It translates a whole computer program into machine language at once. 2. It gives total errors of a program. 3. Translation keeps proceeding even on occurrence of an error. INTEPRETER 1. It translates only one line of a program at a time. 2. It gives only the first error of a program. 3. Translation never proceeds till the first error is cleared. There are two principles of programming ( OOP and POP) POP (Procedure Oriented Programming) A method of breaking a problem(program) into number of procedures (Segments/Module/Function/Methods) is known as POP based programming. Eg. BASIC,COBOL etc. OOP (Object oriented Programming) A method of breaking a problem(program) into number of objects (Segments/Module/Function/Methods) is known as OOP based programming. Eg. Simula/Small Talk/Java etc. Distinguish between POP and OOP programming. PROCEDURE ORIENTED PROGRAMMING 1. Stress is given on functions rather than data. 2. Problem/program is divided into number of Procedures (Segments). 3. Data values are treated as global. OBJECT ORIENTED PROGRAMMING 1. Stress is given on data elements rather than data. 2. Problem/program is divided into number of Objects (Segments). 3. Data values are treated as local. 1 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 OBJECT: Object is a collection of number of entities. Objects take up space in the memory. Objects are instances of classes. When a program is executed , the objects interact by sending messages to one another. Each object contain data and code to manipulate the data. Objects can interact without having know details of each others data or code. CLASS: Class is a collection of objects of similar type. Objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. Eg: grapes bannans and orange are the member of class fruit. Example: Fruit orange; In the above statement object mango is created which belong to the class fruit. NOTE: Classes are User-Define / Composite/Derived Data-Type. DATA ABSTRACTION AND ENCAPSULATION: Combining data and functions into a single unit called class and the process is known as Encapsulation.Data encapsulation is important feature of a class. Class contains both data and functions. Data is not accessible from the outside world and only those function which are present in the class can access the data. The insulation of the data from direct access by the program is called data hiding or information hiding. Hiding the complexity of proram is called Abstraction and only essential features are represented.In short we can say that internal working is hidden. DYNAMIC BINDING: Refers to linking of function call with function defination is called binding and when it is take place at run time called dynamic binding. MESSAGE PASSING: The process by which one object can interact with other object is called message passing. INHERITANCE: it is the process by which object of one class aquire the properties or features of objects of another class. The concept of inheritance provide the idea of reusability means we can add additional features to an existing class without Modifying it. This is possible by driving a new class from the existing one. The new class will have the combined features of both the classes. Example: Robine is a part of the class flying bird which is again a part of the class bird. POLYMORPHISM: A greek term means ability to take more than one form. An operation may exhibite different behaviours in different instances. The behaviour depends upon the types of data used in the operation. What is Java? Java is a 3rd Generation Object Oriented programming Language, developed by James Gosling in the year 1995. It was initially Oak named after the Oak tree outside Gosling s house. It is case sensitive and has a unique two step translation process that includes both Compilation and Interpretation which makes Java Platform independent. What is Procedure Oriented Programming Language? POP is a Procedural Oriented Programming Language. In this, the stress is laid on function rather than data. Data may be kept floating throughout the Program. Eg. BASIC, COBOL , etc. Write any four Characteristics/Features of Procedure Oriented Programming Language. 1) Emphasis is laid on functions (Logical steps). 2) Functions share global data. 3) Data values can keep floating from one function to another. 4) Uses top down approach of programming. What is Object Oriented Programming Language? OOP is an Object Oriented Programming Language. It is a modular approach to programming in which equal stress is given to data as well as methods and it allows the data be applied within the stipulated program area. It also provides reusability features to develop productivity logic. Write any four Characteristics/Features of OOP 1. It gives equal stress on data and function. 2. It makes the program simple by dividing it into a number of objects. 3. The objects can be used as a bridge to have data flow from one function to another. 4. Data can be easily modified without any change in the function. 2 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Basic Principles of OOP 1) Class It is a blueprint that represents a set of objects which share common characteristics and behaviour. 2) Object It is an identifiable entity with some characteristics and behaviour. 3) Encapsulation Binding up of data members and member functions together into a single encoded unit called (class) is known as Encapsulation. 4) Data Abstraction Act of representing only essential features without including its background details is called Data Abstraction. 5) Polymorphism The ability of a method to behave in more than one form is called polymorphism. Function Overloading is a way to implement it, in which more than one function has the same name but different argument list. 6) Inheritance The ability of a class to derive the properties from another class is called Inheritance. The class that inherits properties is called the Derived / Sub / Daughter class and the class from which it is derived is called Base / Super / Parent class. The keyword used to implement Inheritance is extends . Data binding/Dynamic Binding It is the process to link to the function call with function signature at run-time i.e., during execution of a program. Data Hiding is the data which cannot be accessed directly outside, class premises although they are available in the same program Attribute:-The characteristics which make every object having its identity make them distinguished is called attribute. Behaviour The behaviour of any class or object is represented through various functions and methods. Message Passing When object need to interact with one another they do so by passing information to and from one another, this is called Message Passing Garbage Collection Heap is where the objects of a Java programs are stored. Different Types of Java Programs 1) Standalone Application An application program that is developed by programmers which consists of various methods and these methods being invoked from within a main ( ) method is called standalone application. 2) Internet Applets These are small java programs that are embedded in a web page and which requires a web browser to be run/executed. 3) Servlets They extend the functionality of web browser. Source Code The High level language code written by programmers which is not understandable by the computer is known as Source Code. It has an extension of *.java Byte Code is an intermediate code that consists of a set of pseudo machine language instructions that are understood by the JVM and are independent of the underlying hardware. It is called byte code because each chunk of code is of 8 BITS (1 byte = 8 Bits). The byte code files have an extension of *.class Object Code The interpreter of Java named JVM (which stands for Java Virtual Machine) this converts the intermediate Byte Code into machine specific executable codes which runs on the computer. API (Application Programming Interface) consists of libraries of pre compiled code that programmers can use in their application and programs for designing softwares. Java Packages Packages are collection of similar nature classes. A package can be created by using the keyword package and the keyword used to include a package in our program is import . Java contains an extensive library of pre-written classes grouped together into packages java.lang.* It is a default package containing String, Math, Integer, thread etc. java.io.* It is the basic Input Output package of Java java.util.* The java utility package java.applet.* The applet package 3 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 java.net.* The Networking package of Java java.awt.* It stands for Abstract Windows Toolkit, for designing Windows based applications. Basic Features of Java:1) Write once run anywhere(WORA) 2) Platform Independent 3) Offers many security features to make its program safe and secure 4) Built in graphics & supports multimedia 5) Light Weight code 6) Open Product i.e., freely available to all. Blue J - Blue-J is an Integrated Development Environment (IDE) for writing, editing, compiling, testing, executing and debugging the Java programming Codes. Java Tokens & Character Set It is a set of valid characters that a language can recognize. The character set of Java is UNICODE. This has been selected due its vastness of characters. It is 2 byte character code. The first 128 characters of Unicode are identical to the ASCII character set. Tokens are smallest individual units of a Java program. There are 5 different types of tokens in Java 1. Keywords 2. Identifiers 3. Literals 4. Operators 5. Separators Keywords are the reserved words which convey a special meaning to a language compiler. They can not be used for any other purpose like function name, variable name or object names which are also known as RESERVED words.. Identifiers are fundamental building blocks of a program. They are named memory locations or simply names given to variables, objects, classes, functions, arrays etc They are case sensitive. Literal are the fixed values that are assigned to variables which do not change its values during program execution. 1. Integer Literal ( i.Decimal ii.Octal iii.Hexadecimal ) 2. Real Literals i) Float ii) Double 3. Character Literals 4. Boolean Literal 5. Null Literal Operator are the entities or symbols that tell the compiler that what operation has to be performed with one, two or three number of operands within a given expression. Data types are the entities that tell the compiler that which variable will hold what kind of values. Primitive data types Also called as Basic Data type. They are pre defined or built in data types because they are already built in java. E.g. byte, short, int, long, float, double, char, boolean. Non Primitive Data Types: Directly or indirectly dependent on primitive data types. They store the data values with reference to the address or locations. So, they are called as Reference Data Types. E.g. array, classes interfaces etc TYPE CONVERSION / TYPE CASTING / INTEGRAL PROMOTION / DATA CASTING Implicit Data Type Conversion Such Type of conversion is performed by the compiler without programmer s intervention. In this type of conversion a datatype of lower precision gets converted to a datatype with higher precision. Explicit data type Conversion Such type of conversion is user defined conversion which forces an expression to be converted into specific type. Generally this is done to force a conversion from higher precision data type to lower. Operators in Java - Operator are the entities or symbols that tell the compiler that what operation has to be performed with one, two or three number of operands within a given expression. There are approximately a set of 37 different operators that Java uses. Operators can either operate on 1, 2 or 3 operands and accordingly named as : 1. Unary (works on 1 operand) e.g. + + and 2. Binary (works on 2 operands) e.g. +, , * , / , >, <, == etc 3. Ternary (works on 3 operands) e.g. ? : 4 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Operators can categorized as 1. Arithmetic Operators (+ , , * , / , %) 2. Relational Operators (> , < , >= , <= , == , !=) 3. Logical Operators (&&, || , !) 4. Conditional Operators (? : ) 5. Bitwise Operators (&, | , ~ , ^) 6. Shift Operators (>> , << ) 7. Special Operators (this , dot (.) , new, (type) , instanceOf ) Shortcut Operations in Java (Shorthands) Java implements shortcut methods to work with basic arithmetic operators like - +, , * , / and % Hence, a = a + 5; can be written as a + = 5 Unary Operators Increment (Prefix / Postfix) & Decrement (Prefix / Postfix) a = a + 1 can also be written as either a++ (Post Increment) or ++a (Pre Increment) a = a 1 can also be written as either a (Post Decrement) or a (Pre Decrement) The difference between Prefix and Postfix is Prefix Postfix 1.First Update by +1 or -1 1. Use in Arithmetic Expression 2. Then Use in Arithmetic Expression 2. Then Update by +1 or -1 after operator Relational Operators are used to find the relationship between two quantities, whether they are equal, un-equal, greater than less than etc Symbol Relationship > Greater than < Less than >= Greater than or equal to <= Less than or equal to == Equal to != Not equal to Logical Operators are used to join 2 or more relational operators and of 3 types 1. && (and) returns true when both or all the relations are true 2. || (or) returns true when any one of the relations are true 3. ! (not) inverts true to false and false to true Bitwise and Shift Operators Operator Name Description Example Result a&b and 1 if both bits are 1 and 0 in all other cases 3&5 1 a|b or 0 if both the bits are 0, rest all other cases 1 3|5 7 a^b xor 1 if two bits are different and 0 in all other cases 3^5 6 ~a not Inverts the bits, after transforming the entire number into full bit representation ~3 -4 n << p left shift Shifts the bits of n towards left by p positions thereby adding Zeros to the extreme LHS 3 << 2 12 n >> p right shift Shifts the bits of n towards right by p positions resulting in loss of bits from LHS 5 >> 2 1 In all the above examples the operands (values) must be converted to Binary and then implemented with respective operators except for Right and Left Shift operators where only the variable n is converted to binary and not p Don t confuse &&, which is the logical and, with &, which is the uncommon bitwise and. Although the bitwise and can also be used with boolean operands, this is extremely rare and is almost always a programming error. Conditional Operator / Conditional Assignment / Ternary Operator The only Ternary operator of Java is the Conditional Operator, ? : which can be used as an alternative to if else 5 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Special Operators a. [ ] this operator is used to assign the size for an array and to access any particular element within an array. b. ( ) the parenthesis operator is used to enclose the arguments to a function in the function prototype line and invoke a function by enclosing the list of arguments. c. Dot (.) the dot operator is used to access the instance/class members of a class through an object or class name. d. new the new operator is used to assign and allocate memory to new objects and arrays. e. instanceof this operator checks whether the first argument is an instance of the second argument or not. e.g. str instanceof String // will return true if str is a String variable Math class functions in Java (The Math class belongs to the default package of Java named java.lang) Sl Function Name Description 9 Math.min(a, b) Returns the smaller among a and b 10 Math.max(a, b) Returns the larger among a and b 11 Math.abs(a) Convert -ve magnitude to +ve magnitude. 12 Math.sqrt(x) Returns the square root of x 13 Math.pow(x, y) Returns x to the power of y 14 Math.exp(x) Returns e to the power of x where e=2.718 called Euler s Constant just like pi 17 Math.floor(x) Returns the integral value of x less than or equal to x but datatype returned is double, hence Math.floor(7.9) will give 7.0 18 Math.ceil(x) Returns the integral value of x greater than or equal to x but datatype returned is double, hence Math.ceil(7.9) will give 8.0 19 Math.rint(x) Returns the integral value of x by rounding off the fractional part to the nearest integer , but data type returned is double, hence Math.rint(7.9) will give 8.0 Returns the integral value of x by rounding off the fractional part to the nearest integer, 20 Math.round(x) but datatype returned is int, hence Math.round(7.9) will give 8 21 Math.random() Generates a double type random number between 0 to 1 22 Math.PI This returns the 16 digits precise value of PI(Note that it is not a function) Comment / Remark Lines in Java 1) // single line comment . After the two // characters Java ignores everything to the end of the line. 2) /* */ multiple line comment. After the /* characters, Java will ignore everything until it finds a */. 3) /** */ documentation comment. After the /** characters, Java will ignore everything until it finds a */. Exception handling Exception means Error or mistake in a java program. The process of handing errors in a Java program is known as exception handling. Exception refers to any contradictory or unusual situation which can be encountered during a program execution. In Java Exceptions (or Errors) has been categorized broadly under three categories : 1. Syntax Errors A Syntax error occurs when the programmer writes a grammatically incorrect code that does not support the rules of Java programming. It is detected by the compiler. Eg. missing semicolon, using keywords as identifier name, unmatched pair of { }, undefined functions, undeclared and un-initialized variables etc 2. Logical Errors A Logical error occurs when the logic of the program is incorrect and it produces unexpected result. It is not detected by the compiler. E. When wrong operators are applied. 3. Runtime Errors A Runtime error is shown when a syntactically and logically correct program with a set of inputs which is invalid for a given expression. Mostly it occurs due to Division by Zero or Negative Square root. Understanding try / catch / finally blocks and throws keywords Try block contains the code which might lead to run time errors. Catch block contains the code to deal with an exception that might arouse due to execution of a try block. Finally block contains the code that gets executed when no other block is able to handle the exception. Throws is a keyword which is used to inform that an error has occurred, it is specified in the line of function definition (prototype). NaN Not a number . When after any process the result is not in a form of particular Data-Type. Division by zero or overflow produces infinity. Subtracting two infinities produces a NaN. 6 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Infinity - Similarly no exceptions are generated for statements like Math.pow(0, 1) and such statements will result in Infinity as output Flow of Control in Java Programs if Statement - The purpose of the if statement is to make decisions, and execute different parts of your program depending on a condition provided. It produces Boolean value as true / false. switch case Statement - The switch keyword is followed by a parenthesized integer expression, which is followed by the cases, all enclosed in braces.. The switch statement executes the case corresponding to the value of the expression. Normally the code in a case clause ends with a break statement, which exits the switch statement and continues with the statement following the switch. If there is no corresponding case value, the default clause is executed. If no case matched and there is no default clause, execution continues after the end of the switch statement. Case - The case keyword is followed by a constant and a colon. This begins the statements that are executed when the switch expression has that case value. Default - If no case value matches the execution continues at the default clause. This is the equivalent of the else . It is written after the last case. Break - The break statement causes execution to exit to the statement after the end of the switch. Iteration through Loops - The purpose of loop or iterative statements is to repeat a block of Java statements several times depending upon the condition mentioned within the loop. There are two kinds of loops in Java. Fixed & Variable Iteration loop. Entry Controlled loop which is also known as Pre Tested Loop the condition of the loop is first checked and then the loop body is executed, which means if the condition is false the loop doesn t get executed even for once. E.g. a. for LOOP , while LOOP Exit Controlled loop the condition is checked at the end of the loop body, which means even if the condition is false the loop gets executed at least for once. E.g. a. do while LOOP I for statement - Many loops consist of three operations surrounding the body: (1) initialization of a variable (2) testing a condition (3) updating a value before the next iteration. Syntax: for (initialization ; condition/test expression; update) { body } Functions in Java - A function is a block or portion of code within a larger program which consists of some declarations and executable statements, which performs a specific task and is relatively independent of the remaining code. Function prototype - The first line of a function that consists of access specifier, modifier, return type, function name and list of parameters enclosed within a pair of parenthesis is called function prototype. Function signature - The function signature is a part of function prototype; it basically refers to the argument list i.e. number, order and type of arguments. Keywords public & private - In a function the access specifier indicate the scope of visibility of that particular function, this means whether the data members and member methods are accessible. Understanding the keyword static - A static data member is also known as a class variable, such variables have only one instance inside the class. How to access a function? - A function can be accessed or invoked from other functions by simply writing the name of the function along with the argument s or using Assign operator =. Actual Parameters / Arguments - The actual parameters are those that appear at the point of function invocation or function call are called Actual parameters. Formal Parameters / Arguments - The formal parameters are those that appear at the point of function declaration or function signature are called Formal parameters. 7 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 return statement - A function terminates when it encounter the return keyword and it returns the control to its caller. Pure functions - A pure function returns value to is caller and do not modifies the state of its objects or arguments of a calling function. They are also known as Accessor methods. Impure functions - An impure function may not return any value and modifies the state of its objects or arguments. They are also known as Modifier methods. Function Overloading - A class having more than one function name with same name but with different function signature. i.e. number of arguments, order of arguments, type of arguments. Constructors in Java - A Constructor is a member method of a class which has same name as that of a class; has no return type and it is used to initialize the instance variables of a class. It gets invoked automatically when the class is executed. Types of Constructorsa) Default Constructors b) Parameterized Constructors a) Default Constructors - A constructor that accepts no parameters are called Default/non parameterized constructors. b) A parameterized constructor accepts parameters or values in its argument list which initialize the various instance data members of the class. Wrapper Classes :- Java allows you to include the primitive data-types in the family of objects by using wrapper classes. Wrapper classes wrap the primitive data-types into respective objects. Class_name.method_name (arguments) e.g. Boolean.toString(b); Boolean Wrapper class Function Description booleanValue( ) Convert Boolean object to boolean primitive datatype. valueOf( ) Convert String to Boolean object. toString( ) Convert Boolean object to String. Byte Wrapper class Function Description parseByte( ) Converts String to byte primitive datatype. valueOf( ) Converts String to Byte object. toString( ) Converts byte primitive to String object. Short Wrapper class Function parseShort( ) valueOf( ) toString( ) Description Converts String to short primitive datatype. Converts String to Short object. Converts short primitive to String object. Integer Wrapper class Function parseInt( ) valueOf( ) toString( ) Description Converts String to int primitive datatype. Converts String to Integer object. Converts int primitive to String object. Long Wrapper class Function parseLong( ) valueOf( ) toString( ) Description Converts String to long primitive datatype. Converts String to Long object. Converts long primitive to String object. 8 JAVA Programming Theory for ICSE Exam-2017 Float Wrapper class Function parseFloat( ) valueOf( ) toString( ) Description Converts String to float primitive datatype. Converts String to Integer object. Converts int primitive to String object. Double Wrapper class Function parseDouble( ) valueOf( ) toString( ) Description Converts String to double primitive datatype. Converts String to Double object. Converts double primitive to String object. Prepared By: Ashley Tindale 8979764707 Character Wrapper class Function Description isLetter( ) Checks whether the specified character is a Letter or not. isDigit( ) Checks whether the specified character is a Digit or not. isWhiteSpace( ) Checks whether the specified character is a blank or not. isUpperCase( ) Checks whether the specified character is in uppercase or not. isLowerCase( ) Checks whether the specified character is in lowercase or not. toUpperCase( ) Converts the specified character to Uppercase. toLowerCase( ) Converts the specified character to Lowercase. toString( ) Returns a String object representing the specified character as a single character string. e.g. char ch = A ; System.out.println(Character.isLetter(ch)); // returns true System.out.println(Character.toLowerCase(ch)); // returns a String Handling in Java - A String is a collection of characters, in Java String is not a primitive data-type instead is implemented as a class. In Java a String is an immutable object which means it can not be modified. Strings can be created in two ways 1) As a String Literal 2) As a String object A String Literal can be created as A String Object can be created as String class functions Sl String Functions 1 length( ) 2 charAt(k) String str = Welcome ; String str = new String ( Welcome ); Return Int char 3 toUpperCase( ) String 4 toLowerCase( ) String 5 6 7 8 9 10 11 12 13 14 15 startsWith(s) startsWith(s, k) endsWith(s) endsWith(s) indexOf(s) indexOf(s, k) lastIndexOf(s) substring(k, n) substring(k) concat( ) trim( ) boolean boolean boolean boolean Int Int Int String String String String Description Returns length of a string Returns a character at a position k within the string. Returns a String which has all the letters in Capitals (uppercase) Returns a String which has all the letters in Small Letters (lowercase) Returns true if string starts with a string s Returns true if string starts with a string s at index k Returns true if string ends with a string s Returns true if string ends with a string s starting at an index k Returns an index of the first occurrence of String s in string Returns an index of String s starting an index k in string Returns an index of the last occurrence of String s in string Returns a substring from index k to index n-1 of string Returns a substring from index k to the end of string Joins two strings Returns a String which has all the spaces removed from the 9 JAVA Programming Theory for ICSE Exam-2017 16 17 18 19 equals(s) equalsIgnoreCase(s) compareTo(s) compareToIgnoreCase(t) boolean boolean boolean boolean Prepared By: Ashley Tindale 8979764707 beginning and end without altering any intermediate spaces. Returns true if the two strings have equal values Same as above ignoring case Compares two strings Same as above ignoring case Single and Double Dimensional Arrays in Java Definition of One Dimensional Array - One dimensional array is a list of variables of same datatype that are accessed by a common name. An individual variable in the array is called an array element. The locations in which they are stored is called array index or array subscript hence arrays are also sometimes referred as Subscripted variables. Syntax: datatype array_name[ ] = new datatype[size]; Basic Application/Operations of Arrays - Arrays are broadly used in storing huge list of similar data as they are easy to implement under a single name. And are used for 1. Searching 2.Sorting o Linear Search o Bubble Sort o Binary Search o Exchange Selection Sort o Quick Sort o Merge Sort 3. Merging o Alternate Merge o End to end Merge o Similar & Dissimilar sized arrays 4. Insertion / Deletion 5.Transpose o On the basis of index o Reversing the contents o Search and Insert/Delete of an Array o Without/with Shift Q. The two types of Java programs/applications are? Ans: The two types of Java Applications are 'Internet Applets' and 'Stand alone application'. Q. State the differences between Syntax errors and Logical errors. Ans: The compiler can only translate a program if the program is syntactically correct; otherwise the compilation fails and you will not be able to run your program. Syntax refers to the structure of your program and the rules about that structure.The second type of error is a run-time error, so-called because the error does not appear until you run the program. In Java, run-time errors occur when the interpreter is running the byte code and something goes wrong. Q. Differentiate between Compiler and Interpreter. Ans: Compiler convert source code to machine language whole at a time. Interpreter converts program from high level language to machine level language line by line or statement by statement. Q. Java uses compiler as well as interpreter, explain. Ans: Java compiler converts Java source code to byte code. This byte code is further converted into machine code to make it applicable for the specific platform by using interpreter. Q. Differentiate between Source code and Byte code. Ans: Source code is the program developed in Java Language, which is input to a computer through the keyboard. Compiler converts source code to byte code for interpretation. Q. Differentiate between Testing and Debugging. Ans: Testing is the process of checking program logic manually to ensure whether it contains any error or not. Debugging is the process of removing errors from a program. Q. Why is Java often termed as a platform? Ans: Platform is the environment in which programs execute. Instead of interacting with the Operating System directly, Java programs runs on a virtual machine provided by Java, therefore Java is often referred to as a platform also. Q. What is a bytecode? Ans: Bytecode is a set of pseudo mechanic language instructions that are understood by the JVM (Java Virtual Machine) and are independent of the underlying hardware. 10 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. What do you understand by JVM? Ans: JVM or Java Virtual Machine is an abstract machine designed to be implemented on top of existing processors. It hides the underlying OS from Java application. Programs written in Java are compiled into Java byte-code, which is then interpreted by a special java Interpreter for a specific platform. Actually this Java interpreter is known as Java Virtual Machine (JVM). Q. What is JDK (Java Development Kit)? Ans: The Java development kit comes with a collection of tools that are used for developing and running java programs. Q. What are Java APIs? Ans: The Java APIs (Application Program Interface) consist of libraries of pre-compiled code that programmers can use in their application. Q. What do you mean by BlueJ? Ans: BlueJ is a Java development environment. It is an IDE (Integrated Development Environment), which includes an editor a debugger and a viewer. Q. What are iteration statements? Name the iteration statements provided by Java? Ans: Iteration statements are statements that allows a set of instructions to be executed repeatedly till some condition is satisfied. The iteration statements provided by Java are: for loop, while loop, do-while loop. Q. What is the difference between entry controlled and exit controlled loop? or What is the difference between while and do-while loop? Ans: while loop is known as entry controlled loop and do-while loop is known as exit-controlled loop. The differences between these two loops are: (1) In while loop the test expression is evaluated at the beginning where as in do-while loop test expression is evaluated at the bottom, after the body of the loop. (2) In while loop if the test expression is false loop does not continued but in dowhile what ever the test expression the loop execute at least once. Q. Explain the difference between break and continue with an example. Ans: Both statements are used as a jumped statement. But there is a difference between Break and Continue statement. The break statement terminate the loop, but the continue statement skip the rest of the loop statement and continued the next iteration of the loop.e.g. of Break Statementint i=0;while(i<=10){ i++; if(i==5) break; System.out.println(i);}e.g. of Continue Statementint i=0;while(i<=10){ i++; if(i==5) continue; System.out.println(i);} Q. Explain the term for loop with an example. Ans: In Java the 'for' statement is the most common iterative statement. the general syntax of the for loop is,for(initialization; testexpression; increment){ body of the loop}This loop is executed at initial value, condition and increment. Three statement separated by semi colons are placed with in the parenthesis. for example:for(int i=1;i<=10;i++){ System.out.println(i);} Q. State one similarity and one difference between while and do-while loop. Ans: Similarity: In both loops there is a chances to forget the increment statement inside the loop. Difference: In while loop the test expression is evaluated at the beginning where as in do-while loop test expression is evaluated at the bottom, after the body of the loop. Q. What do you meant by an infinite loop? Or What do you mean by an endless loop? Ans: Infinite loop is an endless loop whose number of iterations are not fixed.A loop which never stops. Q. What do you mean by delay loop? Ans: A null loop is also called delay loop which does not repeat the execution of any statement but keeps the control engaged until the iterations are completed. ( Class as a User Defined Types) Q. What is data type? Ans: Data types are means to identify the type of data and associated operations of handling it. 11 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. What is composite (user define) data type? Explain with an example? Ans: A composite datatype is that datatype that are based on fundamental or primitive datatypes. A 'class' is an example of composite datatypes.class Date{ int dd, mm, yy; public Date() { dd=1; mm=1; yy=2005; }} Q. What is user define datatype? Ans: A user defined datatype is a data type that is not a part of the language and is created by a programmer. Q. Can you refer to a class as a user defined (composite) data type? Ans: Yes, we can refer to a class not having a main() method as user-defined data type. Q. What is the difference between primitive data types and composite data types? Ans: (i) primitive data types are built-in data types. Java provides these data types. User-defined data types are created by users. (ii) The size of primitive data types are fixed. The size of user-defined data types are variable. (iii) Primitive data types are available in all parts of Java programs. The availability of user-defined data types depends upon their scope. Q. How are private member different from public member of a class. Ans: Private members of a class are accessible in the member function of the class only, where as public members are accessible globally. Q. Mention any three attributes required for class declaration. Ans: The two attributes for class declaration are: 1. Access Specifier 2. Modifier 3. Class Name Q. What are Functions? Why do we use functions while programs handling? Ans: A named unit of a group of programs statements. This unit can be invoked from other parts of the program. Q. Define Function prototype? Ans: The function prototype is the first line of the function definition that tells the program about the type of the value returned by the function and the number and types of arguments. Q. What is the use of void before function name? Ans: void data type specifies an empty set of values and it is used as the return type for functions that do not return a value. Thus a function that does not return a value is declared as follows. void <functions name> (parameter list) Q. Explain Functions/Methods Definitions with syntax? Ans: A function must be defined before it is used anywhere in the program.[access specifier][modifier]return-type function-name (parameter list){ body of the function}[access specifier] can be either Public, Protected or Private. [modifier] can be one of final, native, synchronize, transient, volatile. return-type specifies the type of value that the return statement of the function returns. It may be any valid Java data type. parameter list is comma separated list of variables of a function. Q. Why main() function so special? Ans: The main() function is invoked in the system by default. hence as soon as the command for execution of the program is used, control directly reaches the main() function. Q. Explain the function prototype and the signature? Ans: The function prototype is the first line of the function definitions, that tells the program about the type of the value returned by the function and the number and type of the arguments. Function signature basically refers to the number and types of the arguments, it is the part of the prototype. Q. Explain the function of a return statement? Ans: The return statement is useful in two ways. First an immediately exit from the function is caused as soon as a return statement is encountered and the control back to the main caller. Second use of return statement is that it is used a value to the calling code. Q. Write advantages of using functions in programs. Ans: (i) functions lessen the complexity of programs (ii) functions hide the implementation details (iii) functions enhance reusability of code 12 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. Difference between Actual Argument and Formal Argument? Ans: The parameter that appears in function call statement are called actual argument and The parameter that appears in function definition are called formal parameter. Q. What are static members? Ans: The members that are declared static is called static members. These members are associated with the class itself rather then individual objects, the static members and static methods are often referred to as class variables and methods. Q. What is the use of static in main() methods? Ans: (i) They can only call other static methods. (ii) They can only access static data. (iii) They can not refer to this or super in any way. Q. What is call by value? Ans: (i) In call by value, the called functions creates its own work copy for the passed parameters and copies the passed values in it. Any changes that take place remain in the work copy and the original data remains intact. Q. Explain the term "passed by reference"? Ans: In passed by reference, the called function receives the reference to the passed parameters and through this reference, it access the original data. Any changes that take place are reflected in the original data. Q. Differentiate between call by value and call by reference? Ans: In call by value, the called functions creates its own work copy for the passed parameters and copies the passed values in it. Any changes that take place remain in the work copy and the original data remains intact. In call by reference, the called function receives the reference to the passed parameters and through this reference, it access the original data. Any changes that take place are reflected in the original data. Q. Define an impure functions? Ans: Impure Function change the state of the object arguments they have received and then return. The following functions is the example of an impure function: public static Time increment(Time obj, double secs){ time.seconds+=secs; return(Time);} Q. What is the difference between pure and impure functions? Ans: Pure Function: These functions takes objects as an arguments but does not modify the state of the objects. The result of the pure function is the return value. Impure Function: These functions change the state of the object arguments they have received. Q. How are following passed in Java? Ans: (i) By value, (ii) By reference. 05] (i) primitive types (ii) reference types Q. What does function overloading mean? What is its significance? Ans: A Function name having several definitions in the same scope that are differentiable by the number or type of their arguments, is said to be an overloaded function. Function overloading not only implements polymorphism but also reduce the number of comparisons in a program and there by makes the programs run faster. Q. Define the concept of function overloading with the help of an example. Ans:- A function name having several definitions that are differentiable by the numbers or types of their arguments is known as function overloading. For example following code overloads a function area to computer areas of circle rectangle and triangle.float area (float radius) //circle{ return (3.14 * radius * radius);}float area (float length, float breadth) //rectangle{ return (length*breadth);}float area (float side1, float side2, float side3) //area of triangle{ float s = (side1 + side2 + side3)/2; float ar = Math.sqrt(s * (s- side1)*(s-side2) *(s-side3)); return (ar);} Q. What is this keyword? What is its significance? Ans: The this keyword is used to refer to currently calling objects. The member functions of every objects have access to a sort of magic keyword name this, which points to the object itself. Thus any member function can find out the address of the object of which it is a member. The this keyword represents an object that invokes a member function. It stores the address of the object that invoking a member function and it is an implicit argument to the member function being invoked. The this keyword is useful in returning the object of which the function is a member. 13 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. What do you mean by recursive function? Ans: When a method is called inside its own definition the process is known as functions recursion and this function called recursive function. Q. What is the difference between Methods and Functions? Ans: The major difference between methods and functions is that methods called by the reference variables called objects where as the functions do not having any reference variables. ( Question Based on Constructors ) Q. What is constructor? Ans: A constructor is a Member function that automatically called, when the object is created of that class. It has the same name as that of the class name and its primary job is to initialise the object to a legal value for the class. Q. Why do we need a constructor as a class member? Ans: Constructor is used create an instance of of a class, This can be also called creating an object.0 Q. Why does a constructor should be define as public? Ans: A constructor should be define in public section of a class, so that its objects can be created in any function. Q. Explain default constructor? Ans: The constructor that accepts no parameter is called the default constructor. If we do not explicitly define a constructor for a class., then java creates a default constructor for the class. The default constructor is often sufficient for simple class but not for sophisticated classes.Example: class ant { int i; public static void main() ant nc=new ant(); }the line new ant() creates an object and calls the default constructor, without it we have no method to call to build our objects. once you create a constructor with argument the default constructor becomes hidden. Q. Explain the Parameterised constructor? Ans: If we want to initialise objects with our desired value, we can use parameters with constructor and initialise the data members based on the arguments passed to it . Constructor that can take arguments are called Parameterised constructor.Example: public class result { int per; int tot; public result (int percentage) { per=percentage; tot=0; } } Q. State the difference between Constructor and Method. Ans: The function has a return type like int. but the constructor has no return type. The function must be called in programs where as constructor automatically called when the object of that class is created. Q. Define Copy constructors. Ans: A copy constructors initializes the instant variables of an object by copying the initial value of the instant variables from another objects. e.g.class xyz{ int a,b; xyz(int x,int z) { a=x; b=y; } xyz(xyz p) { a=p.x; b=p.y; }} ( Class as the Basis of all Computation ) Q. What are keywords? can keywords be used as a identifiers? Ans: Keywords are the words that convey a special meaning to the language compiler. No, keywords can never be used as identifiers. Q. What is an identifier? What is the identifier formatting rule of Java? OR What are the rules for naming a variable? Ans: Identifiers are names given to different parts of a program e.g. variables, functions, classes etc. The identifiers in Java.(i) Can contains alphabets, digits, dollar sign and underscore.(ii) Must not start with a digit.(iii) Can not be a Java keywords.(iv) Can have any length and are case-sensitive. Q. Why keyword is different from identifiers? Ans: Keywords are predefine sets of words that have a special meaning for the Java compiler. Identifiers on the other hand are created by Java programmers in order to give names to variables, function, classes etc. Q. State the difference between Token and Identifier. 14 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Ans: The smallest individual unit of a program is known as Token. The following Tokens are available in Java: Keywords, Identifiers, Literals, Punctuations, Operators.Identifiers are names given to different parts of a program e.g. variables, functions, classes etc. The identifiers in Java. Q. What are literals? How many types of integer literals are available in Java? Ans: A literal is sequence of characters used in a program to represent a constant value. For example 'A' is a literal that represents the value A of type char, and 17L is a literal that represents the number 17 as value of type long. Different types of literals available in Java, they are: Integer literal, Float literal, Boolean literal, Character literal, String literal and null literal. Q. What is an integer constant? Write integer forming rule of Java. Ans: Integer constants are whole numbers without any decimal part. The rule for forming an integer constants is: An integer constant must have at least one digit and cannot contain a decimal point. It may contains + or - sign. A number with no sign is interpreted to be positive. Q. What do you mean by Escape sequence and name few escape sequences in Java? Ans: Java have certain nongraphic characters (nongraphic characters are those characters that can not be typed directly from keyboard e.g. backspace, tab, carriage return etc.). Those nongraphic character can be represented by escape sequence. An escape sequence is represented by backslash followed by one or more character. The few escape sequence characters are: \n for new line, \t for Horizontal Tab, \v for Vertical Tab, \b for Backspace, \" for Double Quotes etc. Q. How many integer constants are allowed in Java? How are they written? Ans: Java allows three types of integer constants: Octal (base 8), Decimal (base 10), and Hexadecimal (base 16). An Octal integer must be started with a zero '0', a Hexadecimal integer starts with a '0X', all others are treated as decimal integer constant. Q. What is meant by a floating constant in Java? How many ways can a floating constant be represented into? Ans: Floating constants are real numbers. A floating constant can either be a fractional or in exponent form. Q. Differentiate between Integer and Floating type constants. Ans: Integer constants are the whole numbers (without decimal points). e.g. 1231. Floating point constants are fractional numbers (number with decimal points). e.g. 14.2356 Q. What is a type or 'Data Type'? How this term is related to programming? Ans: A type or datatype represents a set of possible values. When we specify that a variable has certain type, we are saying what values the expression can have. For example to say that a variable is of type int says that integer values in a certain range can be stored in that variable. Q. What is primitive data type? Name its different types. Ans: Primitive data types are those that are not composed of other data types. Numeric Integral, Fractional, character and boolean are different primitive data types. Q. State the two kind of data types? Ans: The two types of data types are: Primitive and non-primitive/composite/user define data types. The primitive data types are: byte, short, int, long, float, double, char and Boolean. The non-primitive/reference data types are: class, array and interface. Q. Write down the names of three primitive and three non-primitive/reference data types in Java/BlueJ. Ans: The primitive data types are: byte, short, int, long, float, double, char and Boolean. The non-primitive/reference data types are: class, array and interface. Q. How many bytes occupied by the following data types: byte, short, int, long, float, double, char, boolean. Ans: char-2 byte, byte-1 byte, short-2 bytes, int-4 bytes, long-8 bytes, float-4 bytes, double-8 bytes, boolean-Java reserve 8 bits but only use 1 bit. Q. What is the largest and smallest value for floating point primitive data types float? Ans: The smallest value is -3.4E+38 and largest values is 3.4E+38 of floating point data type. 15 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. What are Tokens? Ans: The smallest individual unit of a program which is recognized by the compiler is known as Token. The following Tokens are available in Java:- Keywords, Identifiers, Literals, Punctuations, Operators,Separators. Q. What do you mean by variables ? Ans: A variable is a named memory location, which holds a data value of a particular data types. E.g. double p; Q. What are Operator? Ans: Operators are special symbols that represent operations that can be carried out on variables, constants or expressions. Q. What do you mean by operator and write the name of all operators given in your textbook. Ans: The operations are represented by operators and the object of the operations are referred to as operands. The types of Operators available in Java are: 1. Arithmetic 2. Increment/Decrement 3. Relational 4. Logical 5. Shift 6. Bitwise 7. Assignment 8. Conditional 9. [] operator 10. new operator 11. (type) cast Operator 12. () operator. 13. dot operator. Q. What are Arithmetic operators? Ans: Arithmetical operators are used for various mathematical calculations. The result of an arithmetical expression is a numerical values. Arithmetical operators are of following types: Unary and Binary operators. Q. What is increment operator? What are postfix and prefix increment operators? Ans: The '++' operator is called increment operator. The increment operators add 1 to its operand. These are two types (i) Prefix and (ii) Postfix The prefix version comes before the operand for e.g. ++a, where as postfix comes after the operand e.g. a++ Q. What do you mean by Relational Operators. Ans: Relational operators are used to determine the relationship between different operands. These are used in work of compression also. The relational expression (condition) returns 0 if the relation is false and return 1 if the relation is true. < (less then), > (greater then), <= (less then equals to), >= (greater then equals to), == (equals to), != (not equals to). Q. What are Logical Operators? Ans: The logical operators combine the result of or more then two expressions. The mode of connecting relationship in these expressions refers as logical and the expressions are called logical expression. The logical expression returns 1 if the result is true otherwise 0 returns. The logical operators provided by Java are && Logical AND, || Logical OR, ! Logical NOT. Q. What do you mean by Assignment Statement or Assignment Operator? Ans: Assignment operator is represent by symbol '='. It takes the value on the right and stores it in the variable on the left side. for example x = y + 30 Q. What do you mean by Shift operators? Ans: A Shift operators performs bit manipulation on data by shifting the bits of its first operand right to left. Q. What do you mean by Bitwise operators? Ans: The Bitwise operations are performed by Bitwise operator. The Bitwise operations calculate each bit of their result by comparing the corresponding bits of the two operands.(a) The AND operator &(b) The OR operator |(c) The XOR operator ^(d) The compliment operator ~ Q. What is the purpose of new operator? Ans: We can use new operator to create a new objects or new array. Ex. myClass obj = new myClass();int arr[] = new int[5]; Q. What do you mean by Precedence of an Operator ? Ans: Precedence is the order in which a program evaluates the operations in a formula or expression. Q. What are Operands? Ans: An operator acts on different data items/entities called operands. 16 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. What do you mean by Constant / Literal ? Ans: The memory variables / locations whose values can not be changed within the program is called constant. Q. What do you mean by Type Conversion ? What is the difference between Implicit and Explicit type conversion ? Ans: The process of converting one predefined type into another is called Type Conversion. A implicit type conversion is a conversion performed by the compiler automatically. Where as an explicit type conversion is user defined that forces an expression to be of specific type. Q. What is coercion? How it is implemented? Ans: Implicit type conversion of an expression is termed as coercion. A implicit type conversion is a conversion performed by the compiler. The Java compiler converts all operands up to the type of the largest operand. This is default type conversion. Q. Explain the methods print() and println()? Ans: A computer program is written to manipulate a given set of data and to display or print the results. Java supports two output methods that can be used to send the results to the screen. print() method println() method.The print() method sends information into a buffer. This buffer is not flushed until a new line (or end-of-line) character is sent. As a result print() method prints output on one line.The println() method by contrast takes the information provided and displays it on a line followed by a line feed. Q. Mention two different styles of expressing a comment in a program. Ans: The two ways of inserting a comments in a program are: // single line comments & /* multiple line comments*/ Q. What is a compound Statement? Give an Example. Ans: It is a block of code containing more then one executable statement. In Java the { } is called block and the statements written under {} is called compound statements or block statement. The { } opening and closing braces indicates the start and end of a compound statement. Q. What are iteration/loop statements? Name the iteration statements provided by Java? Ans: Iteration statements are statements that allows a set of instructions to be executed repeatedly till some condition is satisfied. The iteration statements provided by Java are: for loop, while loop, do-while loop. Q. What is the difference between entry controlled and exit controlled loop? ( or difference between while and do-while loop) Ans: while loop is known as entry controlled loop and do-while loop is known as exit-controlled loop. The differences between these two loops are: (1) In while loop the test expression is evaluated at the beginning where as in do-while loop test expression is evaluated at the bottom, after the body of the loop. (2) In while loop if the test expression is false loop does not continued but in dowhile what ever the test expression the loop execute at least once. Q. Explain the difference between break and continue with an example. Ans: Both statements are used as a jumped statement. But there is a difference between Break and Continue statement. The break statement terminate the loop, but the continue statement skip the rest of the loop statement and continued the next iteration of the loop.e.g. of Break Statementint i=0;while(i<=10){ i++; if(i==5) break; System.out.println(i);}e.g. of Continue Statementint i=0;while(i<=10){ i++; if(i==5) continue; System.out.println(i);} Q. Explain the term for loop with an example. Ans: In Java the 'for' statement is the most common iterative statement. the general syntax of the for loop is,for(initialization; testexpression; increment){ body of the loop}This loop is executed at initial value, condition and increment. Three statement separated by semi colons are placed with in the parenthesis. for example:for(int i=1;i<=10;i++){ System.out.println(i);} Q. What do you meant by an infinite or endless loop? Give an example. Ans: Infinite loop is an endless loop whose number of iterations are not fixed.eg: for(;;) System.out.println("java"); Q. Differentiate Null loop and Infinite loop. Ans: A Null loop does not contains any statement to repeat where as infinite loop repeats execution of the statements for endless iterations.e.g. of null loops for(int i=1;i<=10;i++);e.g. for infinite loop for(int i=10;i>=1;i++) 17 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Q. What do you mean by delay loop? Ans: A null loop is also called delay loop which does not repeat the execution of any statement but keeps the control engaged until the iterations are completed. Q1. What is the difference between an Inner Class and a Sub-Class? Ans: An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class. A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class. Q2. What are the various access specifiers for Java classes? Ans: In Java, access specifiers are the keywords used before a class name which defines the access scope. The types of access specifiers for classes are: 1. Public : Class,Method,Field is accessible from anywhere. 2. Protected:Method,Field can be accessed from the same class to which they belong or from the sub-classes,and from the class of same package,but not from outside. 3. Default: Method,Field,class can be accessed only from the same package and not from outside of it s native package. 4. Private: Method,Field can be accessed from the same class to which they belong. Q3. What's the purpose of Static methods and static variables? Ans: When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects. Q4. What is data Encapsulation and what's its significance? Ans: Encapsulation is a concept in Object Oriented Programming for combining properties and methods in a single unit. Q. What is the difference between double and float variables in Java? Ans: In java, float takes 4 bytes in memory while Double takes 8 bytes in memory. Float is single precision floating point decimal number while Double is double precision decimal number. Q. What is Final Keyword in Java? Give an example. Ans: In java, a constant is declared using the keyword Final. Value can be assigned only once and after assignment, value of a constant can t be changed. In below example, a constant with the name const_val is declared and assigned avalue: Private Final int const_val=100 When a method is declared as final,it can NOT be overridden by the subclasses.This method are faster than any other method,because they are resolved at complied time. When a class is declares as final,it cannot be subclassed. Example String,Integer and other wrapper classes. Q. What is Ternary operator? Give an example. Ans: Ternary operator , also called conditional operator is used to decide which value to assign to a variable based on a Boolean value evaluation. It is specified by ? : (Symbol) Local variables: Variable whose existence is known only to the main program or functions are called local variables. Local variables are declared with in the main program or a function. Global variables: Variables whose existence is known to the both main() as well as other functions are called global variables. Global variables are declared outside the main() and other functions. The following Program illustrates the concept of both local as well as global variables. ARRAY - Array is a group of Homogeneous data type elements, that consumes a continous Memory Area. Array is used for Multiple inputs in a single variable. An Array is a Data structure which stores a group of elements of the same kind. Array can also be defined as an ordered list of Homogenous data elements. 18 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Difference Between Data Hiding and Encapsulation Data Hiding means protecting the members of a class from an illegal or unauthorized access. Data Hiding focus more on data security. Encapsulation means wrapping the implementation of data member and methods inside a class. When implementation of all the data member and methods inside a class are encapsulated, the method name can only describe what action it can perform on an object of that class. Encapsulation focuses more on hiding the complexity of the system. BASIS FOR COMPARISON DATA HIDING ENCAPSULATION Basic Data hiding concern about data security along with hiding complexity. Encapsulation concerns about wrapping data to hide the complexity of a system. Focus Data Hiding focuses on restricting or permitting the use of data inside the capsule. Encapsulation focuses on enveloping or wrapping the complex data. Access Specifier The data under data hiding is always private and inaccessible. The data under encapsulation may be private or public. Process Data hiding is a process as well as technique. Encapsulation is a sub-process in data hiding. Difference Between Inheritance and Polymorphism Inheritance allows, code reusability and the polymorphism is, the occurrence of one function with different form. The basic difference between inheritance and polymorphism is that inheritance allows the already existing code to be reused again in a program, and polymorphism provides a mechanism to dynamically decide what form of a function to be invoked. BASIS FOR COMPARISON INHERITANCE POLYMORPHISM Basic Inheritance is creating a new class using the properties of the already existing class. Polymorphism is basically a common interface for multiple form. Implementation Inheritance is basically implemented on classes. Polymorphism is basically implemented on function/methods. Use To support the concept of reusability in OOP and reduces the length of code. Allows object to decide which form of the function to be invoked when, at compile time(overloading) as well as run time(overriding). Forms Inheritance may be a single inheritance, multiple inheritance, multilevel inheritance, hierarchical inheritance and hybrid inheritance. Polymorphism may be a compile time polymorphism (overloading) or run-time polymorphism (overriding). Example The class 'table' can inherit the feature of the class 'furniture', as a 'table' is a 'furniture'. The class 'study_table' can also have function 'set_color()' and a class 'Dining_table' can also have function 'set_color()' so, which form of the set_color() function to invoke can be decided at both, compile time and run time. 19 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Definition of Inheritance: Inheritance is one of the crucial features of OOP, which strongly support reusability . Reusability could be described as creating a new class by reusing the properties of the existing class. In inheritance, there is a base class, which is inherited by the derived class. When a class inherits any other class, the member(s) of the base class becomes the member(s) of a derived class. Definition of Polymorphism: The term polymorphism simply means one function, multiple forms . Polymorphism is achieved at both compile time and run time. The compile time polymorphism is achieved through overloading whereas, the run time polymorphism is achieved through overriding . The polymorphism allows the object to decide which form of the function to be invoked when at both, compile time and run time. Let s discuss the first concept of overloading. In overloading, we define a function in class more than one time with different, data type and the number of parameters whereas the function to be overloaded must have the same return type. Most of the times the functions to the overloaded are constructors of the class. Difference Between while and do-while Loop Iteration statements allow the set of instructions to execute repeatedly till the condition doesn t turn out false. The Iteration statements in C++ and Java are, for loop, while loop and do while loop. These statements are commonly called loops. Here, the main difference between a while loop and do while loop is that while loop check condition before iteration of the loop, whereas dowhile loop, checks the condition after the execution of the statements inside the loop. In this article, we are going to discuss the differences between while loop and do-while loop. BASIS FOR COMPARISON WHILE DO-WHILE General Form while ( condition) { statements; //body of loop } do{ . statements; // body of loop. . } while( Condition ); Controlling Condition In 'while' loop the controlling condition appears at the start of the loop. In 'do-while' loop the controlling condition appears at the end of the loop. Iterations The iterations do not occur if, the condition at the first iteration, appears false. The iteration occurs at least once even if the condition is false at the first iteration. Definition of while Loop The while loop first verifies the condition, and if the condition is true then, it iterates the loop till the condition turns out false. The condition in while loop can be any boolean expression. If the condition becomes true, then loop iterates itself, and if the condition becomes false, then the control passes to the next line of the code immediately followed by the loop. The statements or the body of the loop can either be an empty statement or a single statement or a block of statements. Definition of do-while Loop As in while loop, if the controlling condition becomes false in the first iteration only, then the body of the while loop is not executed at all. But the do-while loop is somewhat different from while loop. The do-while loop executes the body of the loop at least once even if the condition is false at the first attempt. In a do-while loop, the body of loop occurs before the controlling condition, and the conditional statement is at the bottom of the loop. As in while loop, here also, the body of the loop can be empty which allow null statements or, there can be only a single statement or, a block of statements. The condition here is also a boolean expression, which is true for all non-zero value. In a do-while loop, the control first reaches to the statement in the body of a do-while loop. The statements in the body get executed first and then the control reaches to the condition part of the loop. The condition is verified and, if it is true, the loop is iterated again, and if the condition is false, then the control resumes to the next line immediate after the loop. Difference Between Identifier and Variable The word identifier clearly defines itself, an identifier is a name given to an entity, which distinctly identifies an entity in a program at the time of its execution. Variable is also an identifier, its name uniquely identifies itself in a program. Here, the fundamental difference between an identifier and variable is that an identifier is a name given to entity in a program whereas, a variable is a name given to memory location , that is used to hold value, which may get modified during program execution. 20 JAVA Programming Theory for ICSE Exam-2017 BASIS FOR COMPARISON Prepared By: Ashley Tindale 8979764707 IDENTIFIER VARIABLE Use Identifier is used to name a variable, function, class, structure, union etc. Variable is used to name a memory location, which holds a value. Use/Purpose Created to give a unique name to an entity. Allots a unique name to a particular memory location. Range All identifiers are not variable. All variables names are identifier. Example int a; or int a(){ // } int a; or float a; // Definition of Identifier The name we use to call a particular entity in a program, which is not a keyword is called identifier . Identifier particularly names a variable, function, structure, enum, class etc . An identifier distinctly identifies an entity in a program while its execution. Two identifiers cannot have the same name in a program. Let s understand it with an example. float area; Here float is a keyword , and area is an identifier . Definition of Variable Variable is a name given to a distinct memory location . This named memory location contains a value which may be modified while program gets executed. In C, variable must be declared at the beginning of a program whereas, in C++, a variable could be declared anywhere in a program. Variables can be local , global or reference . Local variables are declared inside a function; global variables are declared outside a function. Reference variables are those which provide an alternate name for the previously defined variable. Difference Between Packages and Interfaces in Java Packages and Interfaces both acts as a container. The content in packages and interfaces can be used by the classes by importing and implementing it correspondingly. The basic difference between packages and interfaces is that a package contains a group of classes and interfaces whereas, an interface contains methods and fields. Let s study some other differences with the help of comparison chart. Packages Vs Interfaces in Java BASIS FOR COMPARISON PACKAGES INTERFACES Basic Packages is a group of classes and/or interfaces together. Interfaces is a group of abstract methods and constant fields. Keyword Packages are created using "Package" keyword. Interface are created using "Interface" keyword. Syntax package package_name; public class class_name{ . (body of class) } interface interface_name{ variable declaration; method declaration; } Access A package can be imported An interface can be extended by another interface and implemented by the class. Access keyword Packages can be imported using "import" keyword. Interfaces can be implemented using "implement" keyword. 21 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Definition of Packages Packages are collection or groups of the variety of classes and interfaces. The classes in packages are related to each other in some scope or by inheritance. You can also create your package and use it for your program. Definition of Interface Interface is a kind of a class, but, differs in a sense that the methods declared in the interface are abstract that means the methods are only declared but not defined. The fields in the interface are always public, static, final. The fields must be initialized at the time of declaration. The methods declared by the interface are defined by the class which implements that interface according to its requirement. As the methods in the interface do not perform any function, so there is no use of creating any object of the interface. Hence, no object can be created for the interface. OBJECT: Object is a collection of number of entities. Objects take up space in the memory. Objects are instances of classes. When a program is executed , the objects interact by sending messages to one another. Each object contain data and code to manipulate the data. Objects can interact without having know details of each others data or code. CLASS: Class is a collection of objects of similar type. Objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. Eg: grapes bannans and orange are the member of class fruit. DATA ABSTRACTION AND ENCAPSULATION: Combining data and functions into a single unit called class and the process is known as Encapsulation.Data encapsulation is important feature of a class. Class contains both data and functions. Data is not accessible from the outside world and only those function which are present in the class can access the data. The insulation of the data from direct access by the program is called data hiding or information hiding. Hiding the complexity of proram is called Abstraction and only essential features are represented.In short we can say that internal working is hidden. DYNAMIC BINDING: Refers to linking of function call with function defination is called binding and when it is take place at run time called dynamic binding. MESSAGE PASSING: The process by which one object can interact with other object is called message passing. INHERITANCE: it is the process by which object of one class aquire the properties or features of objects of another class. The concept of inheritance provide the idea of reusability means we can add additional features to an existing class without Modifying it. This is possible by driving a new class from the existing one. The new class will have the combined features of both the classes. Example: Robine is a part of the class flying bird which is again a part of the class bird. POLYMORPHISM: A greek term means ability to take more than one form. An operation may exhibite different behaviours in different instances. The behaviour depends upon the types of data used in the operation. Explanation of Local and Global Variables with Example Local variables: Variable whose existence is known only to the main program or functions are called local variables. Local variables are declared with in the main program or a function. Global variables: Variables whose existence is known to the both main() as well as other functions are called global variables. Global variables are declared outside the main() and other functions. The following Program illustrates the concept of both local as well as global variables. ( Functions / Methods ) Function is a set of instructions to carry out a particular task. The Function after processing returns a single value. In other word, we say a Function is a group of statements that can perform any particular task. Types of functions: There are two types of Functions:1. Standard Functions (Pre-defined Functions) 2. User-defined Functions 22 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 Single Dimensional Array: It is a linear list of fixed number of data items of the same type. All these data items are accessed using the same name using a single subscript. It is similar to a row or column matrix. It is also called as a single-dimensional Array or one subscripted variable. Definition: * Array is a group of Homogeneous data type elements, that consumes a continous Memory Area. * Array is used for Multiple inputs in a single variable. * An Array is a Data structure which stores a group of elements of the same kind. * Array can also be defined as an ordered list of Homogenous data elements. Basic Intro About ASCII Values: ( Total ASCII characters are 256, numbered from 0 to 255 ) char is a keyword used to indicate the Character Type Data. The Data may be a Character constant or String Constant. 1. A Character Constant may be defined as any single Character enclosed with in a pair of apostrophes. Examples : 'a' , 'd' , 'g' etc. 2. A string constant is defined as a sequence of characters placed between double quotes. Examples : "Computer" , "system" , "hello" etc. The string constant is terminated by a null character (\0). Difference between Abstraction and Encapsulation :Abstraction 1. Abstraction solves the problem in the design level. Encapsulation 1. Encapsulation solves the problem in the implementation level. 2. Abstraction is used for hiding the unwanted data and 2. Encapsulation means hiding the code and data into giving relevant data. a single unit to protect the data from outside world. 3. Abstraction lets you focus on what the object does instead of how it does it 3. Encapsulation means hiding the internal details or mechanics of how an object does something. 4. Abstraction- Outer layout, used in terms of design. For Example:Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number. 4. Encapsulation- Inner layout, used in terms of implementation. For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits. Constructor :- In simple terms, Constructor is a special kind of method with class name as method name and gets executed when its (class) object is created or executed. A special method of the class that will be automatically invoked when an instance of the class is created is called as constructor. Constructors can be classified into 5 types :- a) Default Constructor b) Parameterized Constructor c) Copy Constructor d) Static Constructor e) Private Constructor Default Constructor : A constructor without any parameters is called as default constructor. Parameterized Constructor : A constructor with at least one parameter is called as parameterized constructor. Copy Constructor : A parameterized constructor that contains a parameter of same class type is called as copy constructor. Static Constructor : You can create a constructor as static and when a constructor is created as static, it will be invoked only once for any number of instances of the class and it is during the creation of first instance of the class or the first reference to a static member in the class. Static constructor is used to initialize static 23 JAVA Programming Theory for ICSE Exam-2017 Prepared By: Ashley Tindale 8979764707 fields of the class and to write the code that needs to be executed only once. Private Constructor : You can also create a constructor as private. When a class contains at least one private constructor, then it is not possible to create an instance for the class. Private constructor is used to restrict the class from being instantiated when it contains every member as static. Type Casting In Java Type casting in java or simply casting is used to convert data from one data type to another data type. Please note that by using casting, data can not be modified but only type of data can be modified. There are two types of casting, 1) Primitive Casting. 2) Derived Casting 1) Primitive Casting. Primitive Casting is used to convert data from one primitive data type to another primitive data type. Consider primitive data types in java which represent the numbers. These are data types with no decimal places. 1) byte 2) short 3) int 4) long and these are data types with decimal places. 5) float 6) double When you put them in the increasing order of their memory size, you get - byte < short < int < long < float < double. Please remember this order we will be using this order in below examples. byte is the smallest data type and double is the biggest data type in terms of memory size. Operator Overloading : For example, Operator + can be used to add two numbers and also can be used to concatenate two strings. It is called operator overloading. + is the only operator in java which is used for operator overloading. Constructor Overloading : We can include multiple constructors in a class. This is called constructor overloading. Through constructor overloading, we can create objects to the class in multiple ways. This shows the polymorphism. Method Overloading : We can have different forms of same method in the same class. This is called method overloading. Through method overloading we can perform different tasks through different forms of the same method. This shows the polymorphism. Access modifiers are used to control the visibility of a class or a method or a variable or a constructor. There are 4 different access modifiers are available in java. They are private, default (or no access modifier), public and protected. private : private members of a class, whether it is a field or a method or a constructor, can not be accessed outside the class in which they are defined. private members are also not inherited to sub class. default : default members or members with no access modifier are visible within the package. And they are inherited to only sub classes which reside in the same package. That means they are not inherited and visible outside the package. public : public members are visible everywhere and they are inherited to any sub class. protected : protected members have half the characteristics of public members and half the characteristics of default members. i. e protected members are visible within package like default members and they can be inherited to any sub class just like public members. 24

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 

© 2010 - 2025 ResPaper. Terms of ServiceContact Us Advertise with us

 

lawrence chat