CLASSES -AS BASIC OF ALL COMPUTATION
2.1 CHARACTER SET OF JAVA: - java uses Unicode character set. It occupies 2 byte to store a character. Unicode can represent 65536 characters. It can recognize character of most of the language used in the world.
2.2 TOKEN: - Each individual character used in a Java Statement is known as Token
TYPES OF TOKEN: - The various type of token available in java is i. Literals ii. Identifier iii. Keywords. iv puncturators v. operator
2.3 KEYWORD: - They are the reserve word by the language which conveys special meaning to the programming language.
Imp- The keyword const and goto are reserved even though they are not currently used.
Imp- true and false might appear to be keyword but they are Boolean literals. null is not a keyword it is null literals.
2.4 LITERALS(CONSTANTS):- there are 6 types of literals in java. i. Integer literals ii. Real literals iii. Character literals iv String Literals v. Boolean literals vi Null literals.
2.5 INTEGER LITERALS; - an integer literal are whole numbers have at least one digit and must not contain and decimal point. It may contain either + or – sigh. Commas cannot appear in an integer literal.
2.6 FLOATING LITERAL: - floating literals are number having fractional parts. These may be written in one of the two forms fractional form or the exponent forms.
2.6.1 FRACTIONAL FORM; - a real literal in fractional form must have at least one digit before a decimal point and one digit after decimal point. It may also have either + or – sigh preceding it.
2.6.2 EXPONANT FORM: - a real literal in exponent form has two parts; - a mantissa and an exponent. The mantissa must be either an integer or a proper real number. The mantissa is followed by a letter E or e and the exponent. The exponent must be an integer.
2.7 BOOLEAN LITERALS: - the Boolean type has two values represented by the literal trueand false.
2.8 CHARACTER LITERALS; - A character literals in java must contain one character and must be enclosed in single quotation marks.
2.9 NON GRAPHIC CHARACTER;- are those character which can not be directly type from the keyboard. e.g backspace, tabs, carriage return etc.
2.10 ESCAPE SEQUENCE; - non graphic character can be represented by using escape sequence. An escape sequence is represented by a backslash (\) followed by one or more characters. E.g. \b backspace, \a alert bell, \n new line, \t horizontal tab, \\ backslash, \? question mark, \’ single quote, \” double quote.
2.11 STRING LITERALs :-is a sequence of zero of more character surrounded by double quotes. Each character may be represented by and escape sequence.
2.12 VARIBLES: - A variable is a named memory location, which contains a value. The value of variable can be changed depending upon the circumstances and problem in the program.
2.15 IDENTIFIERS: - Identifiers are the name given to different parts of the programs e.g. function names, variable names, class or object names etc.
2.14 RULES OF NAMING IDENTIFIERS
An identifier name can be of any length containing alphabet, digit and underscore. It can not start with a digit. It can not be a keyword.
Identifier name should be meaning full which it easily depicts the logic.
2.15 DATA TYPE- Data types are means to identify the type of data and associated operation of handling it.
DATA TYPE IN JAVA:-there are two type of data type. A: - Primitive type B: - Non –primitive (Reference) type.
2.16 PRIMITIVE DATE TYPE: - The type of data which are independent of any other type, are known as Primitive data types. These types are known as fundamental or basic data type. They are pre-defined or built in data type. E.g. byte, short, int, long, char, float, double Boolean.
2.17 REFRENCE DATA TYPE; - they are composed of primitive data type e.g. array, string, class, interface etc.
2.18 INTEGER TYPE: - A variable declared integer type contains a whole number.
Data type
|
Size
|
Range
|
Default
|
Byte
|
1 byte
|
-128 to 127
|
0
|
Short
|
2 byte
|
-32768 to 32767
|
0
|
Int
|
4 byte
|
-231 to 231-1
|
0
|
Long
|
8 byte
|
-263 to 263-1
|
0L
|
2.19 FLOATING TYPE: - a variable to be floating type if we want to store real numbers in it.
Data type
|
Size
|
Range
|
Default
|
Float
|
4 byte
|
3.4 x10-38 to 3.4 x1038
|
0.0F
|
Double
|
8 byte
|
1.7 x 10-308 to 1.7 x 10308
|
0.0
|
Note; - By default java treats fractional numbers as of double data type.
2.20 CHARACTER TYPE :- A character type variable contains a single character. It occupies 2 bytes. It can store 65536 characters. It default value is ‘\u0000’.
2.21 BOOLEAN TYPE: - it is special type in which a variable contains a constant as true of false these are nonfigurative constant. It occupies 1 byte in memory
2.23 PUNCTUATORS:-are the punctuation sign used as special character in java. Some punctuators are : ; , etc
2.24 SEPARATORS;- are special character used in java to separate the character or varibles e.g ( ),{}, [] etc
2.25. TYPE CONVERSION(TYPE CASTING) in a mixed expression the result can be obtained in any one from of its data types. Hence, it is needed to convert the various data type into the single type. Such conversion is termed as type casting.
2.25.1 IMPLICT TYPE CASTING- the data type of the result get converted automatically into its higher type without intervention of the user. This system of type conversion is known as implicit type conversion.
2.25.2 EXPLICIT TYPE CONVERSION:- is another way of type conversion in which the data type gets converted to another type of depending upon choice. This means the user forces the system to get back into the desired data type.
e.g. int a,b;
float x=(float) (a+b);
2.26 VARIBLE SCOPE:- generally refers to the program region with in which a variable is accessible.
2.27 final KEYWORD. This keyword is used while declaring a variable. These variables are
initialised during the declaration and their values cannot be modified further in the program. This way keyword final makes the variable as constants.
Example:- final double pi=3.14;
2.28 OPERATOR;-are the symbol which tell the computer which operation to take place
Operand: - are the data items on which operation takes place.
TYPE OF OPERATOR;-
· Arithmetical Operator
· Relational Operator
· Logical Operator
· Assignment operator
2.29 ARITHMATICAL OPERATOR: - the operators which are applied to perform arithmetical calculation in a program are known as arithmetical operator. Some basic calculation like addition, subtraction, multiplication and division and modulus often needed during programming.
Type of arithmetical operator; - unary and binary
Unary operator :- uses only one operand.
Binary operator :- uses two operand
Type of unary operator i.) unary + ii.) unary –
iii) unary increment and unary decrement operator
2.30 INCREMENT/DECREMENT OPERATOR: - they are used to increment/decrement the value of a integer variable by 1
x++, ++x will increment value of x by 1
x--, --x will decrement value of x by 1
2.30.1 POSTFIX:- evaluates to the value of the operand after the increment /decrement operation
e.g if x=5 initially then y=x++; will store 5 into y and x will become 6.
if x=5 initially then y=x--; will store 5 into y and x will become 4.
2.30.2 PREFIX:- evaluates to the value of the operand before the increment /decrement operation
e.g if x=5 initially then y=++x; will store 6 into y and x will become 6.
if x=5 initially then y=--x; will store 4 into y and x will become 4.
2.31 RELATIONAL OPERATOR:- are used to show relationship among the operands. Relational operators compare the values of the varibles and results in terms of true or false. Eg:- > ,<, >=,<=,!=, ==
2.32 LOGICAL OPERATOR:- are used to combine two or more conditions. &&, ||, !
&&(AND) evaluates the condition as true when all conditions combined with it is true.
||(OR) evaluates the condition as true when any on of the conditions combined with it is true.
! (NOT ) is used to invert the result of the condition
2.33 TURNARY OPERATOR;- deal with three operands. It also called condition assignment statement because the value assigned to a variable depends upon a logical expression.
Syntax: variable= (test expression) ? expression 1: expression 2;
Ex. z=(x>y)?x:y;
Here value of z will be x if condition is true otherwise z will be y.
Ex. Boolean flag=age>18? true:false
Here value of variable flag will be true if age is greater than 18 otherwise flag will become false.
2.34 OPERATOR PRECEDENCE: determines the order in which expressions are evaluated. It is a set of rules that establishes which operators get evaluated first and how operators with in the same precedence level associate.
2.35 OPERATOR ASSOCIATIVITY: - rules determine the grouping of operands and operator in and expression with more than one operator of the same precedence.
2.36 EXPRESSION; - in java is any valid combination of any valid combination of operators, constants and variable.
2.36.1 PURE EXPRESSION: - all the operands are of same data type.
2.36.2 MIXED EXPRESSION: - the operands are of mixed or different data type.
2.36.3 INTEGER EXPRESSION: - are formed by connection integer constants or integer variable using integer arithmetic operator.
2.36.4 REAL EXPRESSION; - are formed by connection real constants or real variable using arithmetic operator (except %)
2.37 INSTANCE VARIBALE: - the variable which are declared inside a class and treated as data members of the same class called instance variable. Individual copy of instance variable is created for each object.
2.38 print() and println():- the print and println methods send information to standard output because they are part of System.out.
DIFFERENCE BETWEEN print() and println():-print(0 displays the given data/information but do not change line after display where as println() displays the given data/information and changes line after displaying it.
Name two specific purpose of + operator.
The + operator is used for arithmetic addition and string concatenation.
e.g. System.out.print(“Computer “);
System.out.println(“Application”);
System.out.println(“Class X”);
Output:- computer Application
Class X
2.39. DIFFERENCE BETWEEN OPERATOR AND EXPRESSION. An operator is a symbol that performs a specific operation on the operands. An operator can be unary operator and binary operator depending on number of operands it operates upon.
e.g +,-,*,/, % are binary operator.
An expression is formed by the combination of operator of operators with operands. E.g a+b/2 * c is and arithmetic expression. [2005]
2.40 DIFERENCE BETWEEN = AND ==:- The ‘=’(assignment operator) is to assign the value of the variables, whereas ‘==’ (relational operator) is to compare two values. For example.
int x=95; //assignment
int y=102; //assignment
if(x==y) //condition check
2.41 Difference between unary and binary operator
Unary Operator
|
Binary Operator
|
i. Operators that act on on operand are reffered to as unary operator.
ii. ++,--, unary + or unary – are unary operator
|
i. Operator which require two operands for their functing are calles binary operator.
ii. Arithmatic operator, Relational operator are Binary operator.
|
2.42 Difference between Primitive data type and Refrence Data Type.
Primitive Data Type
|
Refrence Data Type
|
i. These are the basic of fundamental data type supported by java.
ii. The primitive data type variables store the actual value and their operations deal with rvalue.
iii. example int, char , float, double
iv. use of new operator is not necessary
|
1. These data types are constructed from primitive data types.
ii. The reference data type variables store the addresses or the references of the memory location of the actual data. These deal with the lvalue.
iii. Examples:- class, array, refrences.
iv. Use of new operator is must.
|
2.43 Similarity and Difference between java character set (Unicode) and ASCII code.
Similarity:- The first 128 characters in the Unicode character set are same as ASCII character set. i.e. they represent the same characters.
Difference:-
Unicode
|
ASCII code
|
i. It is a 2 byte character code set
ii. It can represent 65536 characters.
|
i. it is a 1 bypte character code set.
ii. It can represent only 128 characters.
|
2.44 Difference between Implicit and Explicit type conversion.
Implicit type conversion
|
Explicit type conversion
|
1. This type of conversion is performaed by compiler user intervension not required.
2. No keyword is requied to perform this conversion.
int x=12;
double d=x;
|
1. This type of conversion is forces by the user.
Ex. double x=12.5;
int i=(int)x;
|
2.45 Difference between rvalue and lvalue.
rvalue is called real value. It referes to data item stored in the variable. Rvalues is calles location value it refers to the memory address where variable is allocated.
important point
1. Differentiate between operator and expression. [2005]
an operator is a symbol which specifies that which operation to take place on operand. where as expression is formed using valid combination of operator and operand.
e.g +,-,++,--,>,< are operator where is x=y+z is an expression
2. if m=5 and n=2 output the values of m and n after exceution in (i) and (ii) : [2005]
i)m-=n
(ii) m=m+m/n
if m=5 and n=2 then
(i) m-=n -> m=m-n -> m=5-2=3
(ii) m=m+m/n -> 5+5/2=7
3.) What is a compound statement? Give an Example. [2005]
Compound statement is a set of two of more programming statements. it is also called a block.
A compound statement is seen in an if- construct, while loop, do while loop, for loop and switch
A compound statement is seen in an if- construct, while loop, do while loop, for loop and switch
construct.
e.g. if(x>y)
{
t=x;
x=y;
y=x;
}
e.g. int num[]={1,2,3,4,5};
4. what will be the output of the following. if x=5 initially? [2005]
(i) 5*++x
(ii) 5*x++
(i)5*6=30
(ii)5*5=25
5. What is the output of the following? [2005]
char ='A';
short m=26;
int n=c+n;
System.out.println(n)
ASCII code of A is 65 so
n=65+26=91
6. What is the purpose of the new operator? [2006]
new:- The new operator is used to create an object of a class and associate the object with a variable that names it.
Question 2
7.State the two kinds of data types. [2006]
Two kinds of data types are i. Primitive data type e.g. int, char, float.
ii. Refrence data type e.g. object and array s.
i. 8.
9.What will be the output for the following program segment? [2006]
int a=0,b=30,c=40;
a= --b + c++ +b ;
System.out.println(a);
Output :- a=98
//Write a program to input a time in seconds and convert it into hrs, minutes and seconds.
import java.util.*;
class convert
{
public static void main(String args[]) Throws Exception
{
Scanner Sn=new Scanner(System.in));
int hr,min,sec, s;
System.out.println(“enter time in seconds”);
s=Sn.nextInt();
hr=s/3600;
s=s%3600;
min=s/60;
sec=s%60;
System.out.println(hr+” Hrs “+min+” minutes “+sec+” seconds”);
}
}
Specify output of given if a=5 and b=3 initially
C=++a+ --b + ++a +--b
System.out.println(a+” “+b+” “+c);
Output:- 7 1 16
Specify output of given if a=5 and b=3 initially
C=a++ + --b + a++ + --b
System.out.println(a+” “+b+” “+c);
Output:- 7 1 14
CONCEPT OF OBJECT – INTRODUCING CLASSES- INTRODUCTION JAVA
1.1 OBJECT ORIENTED PROGRAMMING
An object oriented programming (OOPS) is a modular approach, which allows data to be applied within stipulated program area. It also provides the reusability feature to develop productive logic, which means to give more emphasis on data.
1.2 FEATURES OF OBJECT ORIENTED PROGRAMMING
i. It gives stress on the data items rather than functions.
ii. It makes the complete program / problem simpler by dividing it into number of objects.
iii. The object can be used as a bridge to have data flow from one function to another.
iv. We can easily modify the data without any change in the function.
1.3 BASIC ELEMENTS OF OOP (PRINCIPALS OF OOP
- Object 2. Classes 3. Data Abstraction 4. Encapsulation 5. Data hiding 6. Inheritance 7. Polymorphism
1.4 OBJECT :- Object is a unique entity, which contains data and function(Characteristics and behaviour) together in an object oriented programming OOPs Language.
i. It is visible.
ii. It can be defined and described easily .
1.5 CLASSES:- Class is a set of different objects. Each object of the class possesses same attributes and behaviour defined within the same class. Hence class is also termed as object factory.
1.6 ENCAPSULATON:- The system of wrapping data and function into single unit( called class) in known as encapsulation.
1.7 DATA HIDING:- Such insulation of data , which can not be accessed directly outside class premises although they are available in the same program, is known as data hiding.
1.8 DATA ABSTRACTION:- Abstraction refers to the act of representing essential features without including background details.
1.9 INHERITANCE:- Inheritance is the process by which object of one class can link & share some common properties of object from another class.
* Process of acquiring properties of an existing class is called inheritance.
1.10 USE OF INHERITANCE:- (i) No need to repeat the code ii) reusability of the class.
(ii) It in transitive in nature.
1.11 REUSABLITY:-It is the process of adding some additional features to a class without modifying its contents.
1.12 POLYMORPHISM; - Allows two or more class to respond to the same message in different ways, this means we can use the same name for a method in two different class or same class. It also means that the user can send the same message to two different classes and still get the correct response.
* The process of representing one thing in many forms is called polymorphism.
1.13. What is a state and behaviour of an object? Explain with examples.
Object share two characteristics: they all have state and behaviour. For example, your dog has state (name, colour, and breed) and behaviour (barking, fetching and wagging tail.)
Real world object have state and behaviour. Software objects state is implemented through member data and behaviour is implemented through member function /methods.
1.14 Why is data considered safe when encapsulated?
This keeps the code and the data, safe from outside interference and misuse. It prevents the data from being accessed by any other code defined outside the wrapper.
1.15 How do object encapsulate state and behaviour?
State and behaviour of object are interweaved. They are said to encapsulate state and behaviour. e.g. a car object has characteristics like number of wheels seats etc. its state is represented as halted, moving or stationary and its behaviour is, it can move, stop, blow horn etc,. Now all these things are wrapped up together in the form of car. Thus we can say the object encapsulates their state and behaviour as their state and behaviour are interlinked, they cannot exist separately.
1.16 RUNTIME ERROR:- It occurs due to wrong logic of the program. It occurs at the time of execution.
1.17 SYNTAX ERROR; - It occurs when the syntax of the program is not correct .It occurs at the time of compilation.
1.18 JAVA – A high level programming language developed by Sun Microsystems. It was invented by James Gosling and others in 1994.Java were originally called OAK and were developed as a part of Green Project at the sun company. It was designed for handheld devices and set-top boxes.
1.19 FEATURES OF JAVA;-
- Java is an object oriented programming language.
- It can access data from a local system as well as from a network.
- Java program is written within a class. The variable and function are declared and defined within the class.
- There are two types of java program- Applets and Application programs. Applets are the programs which run on web-browser. Application programs are the general programs like any other programming language.
- Java is a case sensitive language. It distinguishes the upper case and lower case letters.
1.20 BYTE CODE AND JVM
- Java is a high level language and the program written in HLL is compiled and then converted to an intermediate language called byte code.
- When this Byte code is to run on any other system, an interpreter known as Java Virtual Machine is needed which translates the byte code to machine language. JVM acts as a virtual processor which processes the byte code to machine code instructions for various platforms. That is why it is called Java Virtual Machine.
1.21 Why is java architecture neutral?
Java architecture is neutral because java byte code is not associated with any particular hardware platform. It can be executed on any machine with a java interpreter.
1.22 Difference between .java & .class
Java source code (files with a .java extension) are compiled into a format called byte code (files with a .class extension), which can then be executed by a java interpreter.
Where does java run?
Java virtual machine can run on: Windows 95, Windows NT, Solaries 2.3(or higher), PowerMacs, and java station, set top Box etc
1.23 COMMENTS IN JAVA; - A comment can be expressed in a program by following two styles:
i) // for single line comment.
E.g. // this is a remark
ii) /*… */: for multiple line comments. As it have beginning marks and ending marks.
e.g. /* this comment can proceed in different lines*/ [2005]
important question
1. Name any two OOP'S Principles. [2005]
Encapsulation and Abstraction
2.Define encapsulation. [2006]
ENCAPSULATON:- The system of wrapping data and function into single unit( called class) in known as encapsulation. It mean that wrapping up of data and methods together as a single unit.
3.Explain the term object using an example.[2006
OBJECT :- Object is a unique entity, which contains data and function(Characteristics and behaviour) together in an object oriented programming OOPs Language.
i. It is visible.
ii. It can be defined and described easily
4. Define a variable. [2006]
VARIBLES: - A variable is a named memory location, which contains a value. The value of variable can be changed depending upon the circumstances and problem in the program.
int a=5;
here ‘a’ is a variable of integer type and hold the value 5
5. Mention any two attributes required for class declaration. [2008]
Ans 1.Characteristic and behavior.
2..Member data and Member function
No comments:
Post a Comment
any problem in any program comment:-