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

Computer (1)

The document provides an overview of fundamental concepts in object-oriented programming (OOP) and Java, including definitions of objects, classes, encapsulation, inheritance, and various data types. It explains the differences between high-level, machine, and assembly languages, as well as the features and execution of Java programs. Additionally, it covers Java-specific components such as the Java Virtual Machine, the Scanner class, and various operators and expressions.

Uploaded by

razorminty7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Computer (1)

The document provides an overview of fundamental concepts in object-oriented programming (OOP) and Java, including definitions of objects, classes, encapsulation, inheritance, and various data types. It explains the differences between high-level, machine, and assembly languages, as well as the features and execution of Java programs. Additionally, it covers Java-specific components such as the Java Virtual Machine, the Scanner class, and various operators and expressions.

Uploaded by

razorminty7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

ELEMENTARY CONCEPTS OF OBJECTS AND CLASSES

Question and Answers

1. What is an object? Give two examples.​


A. An object is an identified entity with some characteristics and
behaviour.
Ex:- Pen, car… etc.

2. What is a class?
A. A class can be termed as a group of objects that share common
properties.A class can contain data and method.

3. What are Encapsulation, Inheritance, Polymorphism and


Abstraction?
A. Encapsulation:-

Encapsulation is the mechanism that binds data and function


together.

Inheritance:-

Inheritance is the process by which one class ac​quires the
property of another class.​

Polymorphism:-

It is the ability of representing a thing in more than one form.

Abstraction:-

It is the act of representing essential features of an object without


knowing the background details.

4. Define High Level Language.​


A. The instructions written using English like keywords, variables,
constants, operators …. Etc. is known as a high level language. The
high-level language is very easily understandable by the program
but not directly understood by the computer system.
5. Define Machine Language.​
A. The program writing using Binary codes - 0 & 1 is known as
Machine Language. The program written in Machine Language is
directly understood by the computer system.​

6. Define Assembly Language.​


A. The program written using symbolic names like ADD, SUB, MUL,
DIV… etc and operands is known as Assembly Language.

7. Define Modularity.​
A. The property of dividing a long process into smaller groups called
modules, where each module requires a set of instructions to
perform a task is known as Modularity.

8.What is the difference between Interpreter and Compiler?


A.
Interpreter Compiler

This program converts This program converts


instructions of high level instructions of high level
language into machine language language into machine language
step-by-step or line-by–line. at once i.e. by taking the whole
program into account.

9. Define Procedure Oriented Programming Language.​


A. A list of instructions written for performing a task where each
statement instructs the computer to do some tasks.​

10. What do you mean by Object Oriented Programming?​
A. The programming concept which is implemented using an object is
known as object oriented programming.

11. What do you mean by message?


A. A message is a set of information which is sent to another object
and also received by the object.

12. Name any three applications of OOP.​


A. Three applications of OOP are :-
●​ Real-time System
●​ Parallel Programming
●​ Object-Oriented Database

13. Name the concept which implements super and sub-class


concepts.​
A. Inheritance.​

14.Name any four OOP principles.
A. Principles of OOP are:-​

i.) Class ​
ii.) Object​
iii.) Encapsulation​
iv.) Inheritance​
v.) Polymorphism​
vi.) Abstraction

************************
INTRODUCTION TO JAVA

Introduction:-

It is a very popular programming language of 3rd generation, it can
perform various tasks as other programming languages including
Internet and Intranet applications. This language also helps to
manage networks.​

Java History:-

Java is a general purpose object oriented programming language as


well as a platform to perform various tasks related to programming
and world wide web applications (WWW).

Features of Java:-

●​ Object-Oriented
●​ Platform Independent
●​ Distributed
●​ Multi-threads
●​ Security
●​ High Performance
●​ Portable
●​ Compiler & Interpreter
●​ Simple Programming Language​

Question and Answers

1. What is BlueJ?​
A. It is a Java development environment also known as an IDE
(Integrated Development Environment) which is a combination of
editor, debugger and viewer.​

2. What do you mean by byte code?
A. It is a platform independent code. When a Java program is
compiled, the Java compiler converts the Java source code into
program independent code that a Java Virtual Machine can easily
understand and execute.
3. What do you mean by Java Virtual Machine?​
A. The program written in Java language is first converted into byte
code and then those codes are interpreted by using Java
interpreter for a particular platform to run. SO the Java Interpreter
is known as Java Virtual Machine.

4. What do you mean by source code?​


A. The program written in any programming language to solve a
problem is known as source code.​

5. What is a compilation unit?​
A. Java source code file is known as compilation unit.

6. What is an applet
A. Applet is a dynamic and interactive program that runs a web
page displayed by a Java capable browser.

7. What is unicode?
A. It is a two-byte character code set used for internal
representation of characters and strings, it uses 16-bits to
represent each other.

8.What is the use of bin and lib in JDK.​


A. Bin contains all tools such as Java compiler, applet, viewer, AWT
(Abstract WIndows Toolkit) tools …etc, whereas lib contains API and
all packages.

9.What is a Java API?​


A. The libraries of precompiled code that can be used in a Java
program is known as Java API (Application Program Interface).​

10. What is the importance of the main method?​
A. A main method controls the execution of all the statements and
functions to produce the required output.

11. What are the two parts in executing a Java program and their
purpose?​
A. The two parts in executing a Java program are:-​

●​ Java Compiler
●​ Java Interpreter

The Java compiler is used for compilation and the Java Interpreter
is used for execution of the application.

12. What is the difference between application and applet?


A.
Application Applet

Application must be run on a Applet must be run on a web


local machine. browser.

************************
VALUES AND DATATYPES

Definitions

1. Tokens:- The smallest individual unit in a program is known as


Java token.

2. Identifier:- Those quantities which change their values during the


program execution are called Identifiers.

3. Literals:- Those quantities which do not change their values


during the program execution are called Literals.

4. Operator:- The symbols used to perform various operations on


operands are operators.​

5. Keyword:- Those words which convey specific meaning to the
Java compiler and perform some specific task are known as
Keyword.​

6. Separators/Punctuators:- Theft are specific symbols used in a
Java program.​

7. Data types:- To identify the type of data involved in an operation
is known as Data type. The data types are divided into two
categories:-​

i.) Primitive data type​
ii.) Non-Primitive data type.

8. Primitive data type:- Those datatypes which automatically loads


in the memory as soon as the Java program runs are known as
Primitive Data Types. The eight Primitive data types supported by
Java are Short, Byte, Int, Long, Float, Double, Char and Boolean.​

9.Non-Primitive data type:- The data types formed with the help of
Primitive data type is known as Non-Primitive data type. In other
words they are a group of Primitive data types.​
Ex:- Class, Arrays and Interface.

10.Integer:- Any whole number positive or negative without any


decimal point is known as Integer.​

11.Float:- Any number positive or negative with a decimal point is
known as Float.​

12.Double:- Any number positive or negative with a decimal point is
known as Double.​

13.Character:- Any single character enclosed within single quotes is
known as Character.​

14.String:- One or more characters enclosed within double quotes is
known as String.​

15.Boolean:- IT is always a Boolean type, it may be true or false.

16.Operator:- An operator is a special symbol used to perform


various mathematical and logical operations on operands. Java
operators are divided in the following categories:-

i.) Arithmetic operators


ii.) Relational operators
iii.) Logical operators​
iv.) Conditional operators
v.) Assignment operators
vi.) Bitwise operator
vii.) Increment and Decrement operator
viii.) Dot operator

17. Arithmetic operator:- Those operators are used to perform


arithmetic operations. Arithmetic operators are +, - , *, /, %.

Types of Arithmetic operators are:-

i.) Unary operator​


ii.)Binary operator
iii.) Ternary operator

19.Unary operator:- These operators that act on one operand are


known as Unary operators.
Ex:- ++, –.​

20.Binary operator:- These operators which work on two operands
are known as Binary operators.​
Ex:- a+b.

21.Ternary operator:- These operators which work on three


operands are known as Ternary operators.​
Ex:- a+b+c.​

22.Relational operator:- These operators are used to perform
relational operations. The relational operators are >, <, =>, <=, ==, !=.​

23.Logical operator:- These operators are used to perform logical
operations. The logical operators are:-​

i.) Logical AND (&&)​
ii.) Logical OR (II)​
iii.) Logical NOT (!)​

24.Conditional operators:- The relational operations performed
using the two symbols ?, : are known as conditional operators.

25.Assignment operator:- The operator which assign the actual


value to a variable is known as assignment operator.​
Ex:- a=10, here ‘=’ is the assignment operator.

26.Increment operator:- The operator which increases the value of


a variable by 1.
Ex:- a++.​

27.Decrement operator:- The operator which decreases the value
of a variable by 1.​
Ex:- a–.​

28.Dot operator:- This operator is used to access instance
variables and functions of a class with the help of objects of the
class.
29.Bitwise operator:- These operators are used to test the bits and
as well as to shift them.

30.Expression:- A valid combination of variables, constants, and


operators is known as an expression.

Types of Expressions:-

i.) Arithmetical Expression


ii.) Relational Expression
iii.) Logical Expression

31.Arithmetical Expression:- An arithmetical expression is a valid


combination of variables/constants and only arithmetic operators.

32.Relational Expression: A relational expression is a valid


combination of variables, constants and only relational operators.

33 Logical Expression: A logical expression is a valid combination


of two or more relational expressions and only logical operators.

34.Type Casting: It is a process of converting one type of data to


another type of data. It is known as Type Casting or Type
Conversion.

35.Print Method: This method is used to display the value of a


variable or a message or a quote.

36.PrintLN Method: This method is used to display the value of a


variable or message or quote as the output, and then the control
automatically shifts to the next line.

37.Instance Variables: The variables declared within the class and


on which some operations are performed are known as instance
variables.

38.Static Variable or Class Variable: A variable declared once for a


class is known as a static variable or class variable.
39.Scanner Class: The class that allows input of primitive data
types like int, float, double, char, string, and long.

Question and Answers

1.​ What is meant by variable?​


A..Variables are location in memory that can hold value which
may change

2. What are the default values of Primitive data types?​


A.

Data type Default values

int 0

float 0.0f

double 0.0d

long 0L

short 0

char null

string null

boolean false

3. What is the difference between Operator and Expression?​


A.

Operator Expression

Operator is a special symbol A valid combination of variables,


used to perform various constants and operators is
mathematical and logical known as Expression.
operations on operands.
4. Define Compound statement. Give one example.​
A. Two or more statements enclosed within the curly braces ({}) are
known as compound statements.

Ex:- ​

{​
int a=10,b=20;i​
int c = a+b;​
}

5. What is the purpose of the new operator?​


A. The new operator creates a single instance of a class and
returns a reference tool of that object.

6. What is the use of keyword parse?​


A. It is used to convert String data types into Primitive data types.​

7. Name the package that converts scanner class.​
A Java.util.*;

8. Write a valid example to create an object of scanner class.​


A. Scanner sc = new Scanner(System.in);

9.What is the difference between next and nextline method?​


A.​

next() nextLine()

It reads or input the string as It reads or input a string with or


one word i.e. without any space. without space including other
characters.

10. What do you mean by package?​


A. A package is a group of related classes and interfaces.

11. State the package that contains the Scanner and


BufferedReader classes.​
A. Scanner is in java.util.*; and BufferedReader is in java.io; .

12. Name the two library packages.​


A. java.util.*;​
java.io;
13.Give the wrapper classes of Primitive data types.
A.
Data type Wrapper class

int Integer

float Float

double Double

char Character

String String

boolean Boolean

byte Byte

short Short

14. Give the size of Primitive data types.​


A.​

Data type Size (in bytes)

byte 1

boolean 1

short 2

char 2

int 4

float 4

long 8

double 8
15. Give the input of Primitive data types.
A.
Data Type Input

int sc.nextInt();

float sc.nextFloat();

double sc.nextDouble();

String sc.nextLine(); or sc.next();

Long sc.nextLong();

char sc.nextCharacter();

byte sc.nextByte();

boolean sc.nextBoolean();

16. Give the return data type of character functions.


A.

Function Return data type

isLetter(char ch) boolean

iaDigit(char ch) boolean

isUpperCase(char ch) boolean

isLowerCase(char ch) boolean

isWhitespace(char ch) boolean

toLowerCase(char ch) char

toUpperCase(char ch) char


17. Give the return data type of mathematical functions.​
A.

Function Return data type

Math.min(); double|float|int|long

Math.max(); double|float|int|long

Math.sqrt(); double

Math.pow(); double

Math.ceil(); double

Math.floor(); double

Math.random(); double

Math.log(); double

Math.round(); long|int

Math.rint(); double

Math.abs(); double|float|int|long

************************
CLASS AS USER DEFINED DATA TYPE
Definitions​

1. Data type:- The data type refers to the identification of the type of
data which is used to perform some operation.

2. Composite data type:- The data type which are based on Primitive
data types are known as Composite data type.​

3. User Defined data type:- The data type which is created by the
user to perform some task is known as user defined data type.

4. Class as composite data type:- The class that combines


fundamental or primitive data types in the form of one unit is known
as composite data type.

5. Wrapper classes:- The class that helps in converting Primitive


data types into object types are known as Wrapper classes.

6. Conversion functions:- Those functions that convert numeric


data into string data are known as conversion functions.

Conversion functions are:-​



i.) toString(;​
ii.) valueOf()​
iii.) parse

7. toString():- It is used to convert the numeric value passed as


argument into the String object.​
Ex:- The number is 78, it will be converted into String as “78”.​

8. parse:- The parse keyword converts the numeric data type,
string passed as an argument into its corresponding primitive data
type.​
Ex:- The string value “78” will be converted into numeric value as
24.​

9. valueOf():- This function is used to convert the numeric String
passed as an argument into corresponding Primitive data type.

10. Character functions:- Those functions that work upon a single


character and return boolean results.
11. isLetter(char ch):- It returns true if the character stored in ch is
letter otherwise it returns false.​

12. isDigit(char ch):- It returns true, if the character stored in ch is a
digit otherwise it returns false.​

13. isLetterOrDigit(char ch):- It returns true if the character stored
in ch is a letter or digit otherwise it returns false.

14. isWhitespace(char ch):- It returns true if the character stored in


ch is a white space otherwise it returns false.

15. isLowerCase(char ch):- It returns true if the character stored in


ch is lower case letter otherwise it returns false.

16. isUpperCase(char ch):- It returns true if the character stored in


ch is upper case letter otherwise it returns false.​

17. toUpperCase(char ch):- This function converts the character
stored in ch into its equivalent letter form.​

18. toLowerCase(char ch):- This function converts the character
stored in ch into its equivalent letter form.

Question and Answers

1. Why is the class also called Composite data type?​


A. The class is composed of Primitive data types so it is known as
composite data type

2. Define Access specifier. Name them.​


A. The Access specifiers are used to control the execution of data
and function of a class. The Access specifier are public, private,
protected and default

3. What do you mean by Package?​


A. A package is a group of logically related classes.​

4. What is the purpose of the new operator?​
A. It is used to create a new instance of a class.

5. Give four examples of Primitive data types.​


A. int, float, double, char and boolean.
6. What is the difference between Primitive data type and User
defined data type?​
A.
Primitive data type User defined data type

Primitive data types are built in User defined data types are
data types provided by the created by the user itself by
Java language. their own name other than a
keyword.

Primitive data types are The availability of these data


available throughout the types is throughout the java
program. program.

They are of fixed type. The sizes of these data types


vary depending upon their
creation.

************************
DECISION MAKING STATEMENTS
Definitions​

1. If statement:- This statement is used to check one or more
conditions.​

Syntax:-​

if(condition)​
{​
Statement;​
}

Example:-​

if(age>=18)​
{​
System.out.println("Eligible for voting");​
}

When the condition is true the control will execute the statement
given within the curly braces.​

2. If else():- This statement is used to execute the statements given
within the if block when the condition is true otherwise the
statement given within the else block gets executed.​

Syntax:-

if(condition)​
{​
Statement;​
}​
Else​
{​
Statement;​
}
Example:-

if(a>b)​
{​
System.out.println(a);​
}​
Else​
{​
System.out.println(b);​
}

3. If else if():- It is used to check a series of conditions where only


one condition body will execute and if all conditions are false then
the last statement will execute. It is also known as a ladder if
statement.

Syntax:-

f(condition)​
{​
Statement;​
}​
else if(condition)​
{​
Statement;​
}​
Else​
{​
Statement;​
}

Example:-​

if(a>b&&a>c)​
{​
System.out.println(a);​
}​
if(b>a&&b>c)​
{​
System.out.println(b);​
if(c>a&&c>b)​
{​
System.out.println(c);​
}

4. Multiple if statement:- This concept is used to check series of


conditions to perform the related task.​

Syntax:-

if(condition)​
{​
Statement;​
}​
else if(condition)​
{​
statement;​
}​
else​
{​
statement;​
}

Example:-

if(a>b&&a>c)​
{​
System.out.println(a);​
}​
if(b>a&&b>c)​
{​
System.out.println(b);
}
if(c>a&&c>b)​
{​
System.out.println(c);​
}
5. Nested if() statement:- One or more if statements inside one if
statement is known as nested if statement.

Syntax:-​

if(condition)​
{​
statement;​
}​
if else if(condition)​
{​
statement;​
}​
else​
{​
statement;​
}

Example:-​

if(a>b&&a>c)​
{​
System.out.println(a);​
}​
if(b>a&&b>c)​
{​
System.out.println(b);
}
if(c>a&&c>b)​
{​
System.out.println(c);​
}

Differentiate between​

1. If statement and Switch statement.​
A.
If statement Switch statement

Can check >, <, ==, and !=. Can check only for equality.
It can check the value of any It can check only integer and
data type. character type values.

It is used to make two way It is used for multiple branching


decisions. statements.

2. Switch statement and if else statement.


A.
Switch If else

It only tests for equality for It can work with all relational
selected values. It cannot operators. It can handle floating
handle floating point constant. point constant

3. Break and Continue statement.​


A.
Break Continue

The break statement is used to The continue statement is used


terminate the loop to skip a particular iteration and
continue the next iteration.

4. If and if else statement.​


A.
If If else

It can check >, <, ==, !=. ​ It can work with all relational
It can check the value of any operators and can handle
data type. It is used to make two floating point constant
way decision

************************
ITERATIONS

1. Iteration:- Whenever we want to perform any operation more than


one time, we use iteration or loop statements.

2. for loop():- It allows a set of statements to be repeated or looped


through a fixed number of times.

Syntax:-

for (initial value; condition; increment/decrement)​


{​
statements;​
}

Example:-​

for(int i=1;i<=10;i++)​
{​
System.out.println(i);​
}

3. Nested for loop():- One or more for loop() within a for loop() is
known as nested for loop().

Syntex:-

for (int i = 1; i <= 5; i++)​


{​
for (int j = 1; j <= i; j++)​
{​
System.out.println(j);​
}​
}

Example:-
for (int i = 1; i <= 5; i++)​
{​
for (int j = 1; j <= i; j++)​
{​
System.out.println(j);​
}​
}

4. Infinite loop:- An infinite loop is a situation where the control does


not reach the test condition within the loop, causing it to continue
running indefinitely.

Syntax:-​

for(initial value;update)​
{​
statement;​
}

Example:-​

for(int i=1; i++)​


{​
System.out.println(i);​
}

5. Empty loop:- The loop which does not contain any statement in its
loop body is known as empty loop.

Syntax:-​

for(initial value;condition;update)​
{​
}

Example:-
for(int i=1;i<=5;i++)​
{​
}

6.while() loop:- This loop is used to execute one or more statements


till the condition is true and the loop terminates when the condition
becomes false. The while() loop is also known as entry controlled
loop as before entering into the loop first the condition is checked
and if it is true the control enters into the loop and execute all the
statement given within the curly braces ( {} ) of while, if the entry
condition is false the loop terminates and executes those
statements given out of the while loop.

Syntax:-​

while(condition)​
{​
statement;​
}

Example:-​

int a=1;​
while(a<=10)​
{​
System.out.println(a);​
a++;​
}

7. do-while() loop:- This loop is used to execute one or more


statements till the condition is true and the loop terminates when
the condition becomes false. THe do-while() loop is also known as
exit controlled loop as the control enters into the loop without
checking any condition and after executing the given statement
once the condition is checked and if it is true, the loop repeats till the
condition is true and when the condition becomes false the loop
goes out of the do-while and executes those statements given out
of the do-while() loop.
Syntax:-​

do​
{​
statement;​
}while(condition);

Example:-​

int a=1;​
do​
{​
System.out.println(a);​
a++;​
}while(a<=10);

8. Continue statement:- This statement forces the control to


perform the next iteration of the loop.

9. Break statement:- The break statement terminates the loop in


which it is present.​

10. What are jump statements?


A. The statements break, continue and return are known as jump
statements.

Differentiate between​

1. while() loop and do-while() loop​
A.
while() do-while()

This loop is used to execute one This loop is used to execute one
or more statements till the or more statements till the
condition is true and the loop condition is true and the loop
terminates when the condition terminates when the condition
becomes false. The while() loop becomes false. THe do-while()
is also known as entry loop is also known as exit
controlled loop as before controlled loop as the control
entering into the loop first the enters into the loop without
condition is checked and if it is checking any condition and
true the control enters into the after executing the given
loop and execute all the statement once the condition is
statement given within the checked and if it is true, the loop
curly braces ( {} ) of while, if the repeats till the condition is true
entry condition is false the loop and when the condition
terminates and executes those becomes false the loop goes
statements given out of the out of the do-while and
while loop. executes those statements
given out of the do-while() loop.

Syntax:- Syntax:-

while(condition)​ do​
{​ {​
statement;​ statement;​
} }while(condition);

Example:- Example:-

int a=1;​ int a=1;​


while(a<=10)​ do​
{​ {​
System.out.println(a);​ System.out.println(a);​
a++;​ a++;​
} }while(a<=10);

2. for() loop and while() loop​
A.
for() while()

It allows a set of statements to This loop is used to execute one


be repeated or looped through a or more statements till the
fixed number of times. condition is true and the loop
terminates when the condition
becomes false. The while() loop
is also known as entry
controlled loop as before
entering into the loop first the
condition is checked and if it is
true the control enters into the
loop and execute all the
statement given within the
curly braces ( {} ) of while, if the
entry condition is false the loop
terminates and executes those
statements given out of the
while loop.

Syntax:- Syntax:-

for (initial value; condition; while(condition)​


increment/decrement)​ {​
{​ statement;​
statements;​ }
}

Example:- Example:-

for(int i=1;i<=10;i++)​ int a=1;​


{​ while(a<=10)​
System.out.println(i);​ {​
} System.out.println(a);​
a++;​
}

************************
FUNCTION OR METHOD

Question and Answers​



1. What do you mean by function or method?
A. A method is a compound set of executable statements used to
carry out some specific task in the name of the method given by the
user. The method or function is also known as a sub-program.

2. Why do we use function or method?​


A. The function sometimes makes complicated things simple in other
words if a program is divided into two various modules and a name
is assigned to each module and to get the output, use module A, in a
proper sequence.​

3. Name the types of method or function.
A. The function are divided into two categories:-​

i.) Pre-defined function​
ii.) User-defined function

4. Name the basic steps that are needed to make a function or


method.​
A. To create a function the following steps are required:-​

i.) Function prototype​
ii.) Function definition​
iii.) Function calling​

5. What is a function prototype?​
A. This is the very first line of function definition that tells about the
status of the function. This status included access specifier, access
modifier, function data type, function name and argument list.

6. What is a function definition?​


A. This is an extension of function prototype which consists of a
valid set of statements within curly braces to perform some task.
7. What do you mean by function invoking?​
A. The method calling the function definition body to execute all the
instructions given within the braces as the body of the function to
carry out the defined task. The function definition body may or may
not have parameters within the brackets. During function calling,
passing of a parameter should be taken care of i.e. the value of the
variable given in the function definition should be passed from here
having the same data types and the same sequence as given in the
function definition.

8. Which keyword is used to create an instance of a class?​


A. new.​

9. Write the format of function definition and also give one example.​
A.
Syntax:-

Access specifiers, access modifiers, function data type, function


name (list of variables)​
{​
statements;​
}

Example:-​

public static void main(int r, int y)​


{​
System.out.println(x+y)​
}

10. What do you mean by access specifier? Name the access


specifiers.​
A. They are java keywords which control the execution of members
of a function i.e. how the function is accessible to the other
functions of the class. The access specifier may be public, private,
protected and default.
11. What do you mean by parameter or signature? Give an example.​
A. This list of variables given with the function, within the brackets
is known as the parameter or signature.

Example:-​

public static void main(int x, int y)​


{​
statements;​
}

12. Write the types of parameters used in the function.​


A. The different types of parameters used in the function are:-​

i.) Formal parameter​
ii.) Actual parameter

13. What do you mean by Formal parameter?​
A. The list of variables along with their data types given within the
brackets with function prototype and function definition is known as
formal parameter or argument or signature.

14. What do you mean by Actual parameter?


A. The list of variables without any data types given within the
brackets at the time of function invoking or calling statement is
known as Actual parameter or argument.

15. What is the difference between call-by-value and


call-by-reference?​
A.
Call-by-value Call-by-reference

In this method during function In this method during function


calling the actual arguments calling the actual argument is
are copied to formal arguments passed by reference that is
and works with them as needed. copied to the formal argument
and works with them as given.

Changes made in formal Changes made in formal


arguments are not reflected in argument are reflected in the
actual arguments. actual argument.
In the call-by-value method In the call-by-reference method
fundamental or primitive data only reference data type is
types are passed. passed.

Example:- int, float, double, char, Example:- class, array,


String. boolean, long. interface.

16. What do you mean by pure function? Give an example.​


A. The function which does not change the state of the argument
that is received when called or invoked is known as pure function
or pre-defined function.

Example:-
public static void main()​
{​
statements;​
}

17. What do you mean by impure function?​


A. The function which changes the state of the arguments that are
received when called or invoked is known as impure function.​

18. How many values does a function return?​
A. A function returns only one value at a time.

19. What do you mean by function signature?​


A. The number and types of parameters given with function
prototype and function definition is known as function signature.​

20. What do you mean by function overloading?​
A. The logical method of creating various functions by the same
name which are differentiated by their data types or number of
arguments is known as function overloading.

21. Name the statement that controls transfer back to a method.​


A. Return statement.

22. Write two advantages of using functions in a program.​


A. i.) Reusability of program code
ii.) It supports modular programming
23. What are the two ways of invoking a function?​
A. i.) Call-by-value​
ii.) Call-by-reference

24. What is the role of the keyword “void” in declaring a function?​


A. The data type or keyword “void” states that the function does not
return any value.

************************
CONSTRUCTOR

Question and Answers

1. Constructor:- A constructor function is always created by the


same name as of the class i.e. class name and constructor name
must be the same.​

Types of Constructor:-​

i.) Default constructor​
ii.) Parameterised constructor​
iii.) Copy constructor​

2. Default constructor:- When a class name is used as a function
followed by an empty bracket is known as default constructor.​

3. Parameterised constructor:- When the class name is used as a
function followed by one or list of primitive data types as
parameters within the brackets is known as parameterised
constructor.

4. Copy constructor:- The constructor is used to initialise one object


along with the stored values to another object of the same class
during declaration.​

5. What is the difference between constructor and method?​


A.
Constructor Method

It is always defined by the same It is always defined by any name


name as the class. except class name and
keywords.

It has no return type, not even It must begin with either void or
void data type. return data type.

It creates an instance of a A method contains one or more


class. java statements as its body.

9. Constructor overloading:- Two or more constructors in a class is
known as constructor overloading.​

10. this operator:- The this keyword represents an object which
executes members of a class, it stores an address of the current
calling object.

11. State two features of a constructor.​


A. Functions of a constructor are:-​

i.) The constructor always has the same name of the class to which
it belongs to.​

ii.) The constructor is a public member function of a class and
activates automatically as soon as the object of that class is
created.

Note:- i.) A constructor function is always created by the same


name as of the class i.e. the class name and constructor name must
be the same.​

ii.) A constructor has no return data types, not even void. In other
words, the constructor never returns a value.

************************
LIBRARY CLASSES (STRING HANDLING)

1. Character:- Any alphabet or digit or any special symbol is known


as character.

2. Character constant:- Single character enclosed within single


inverted commas is known as character constant.​

3. String constant:- Sequence of characters with or without space
enclosed within double quotes is known as string constant.

ASCII CODES​

Character ASCII
CODE

A 65

B 66

…. ...

Z 90

a 97

b 98

…. …..

z 32

Space = 32

A = 65 —-> 32 + 65 = 97 —-> a​
a = 97 —-> 97-32 = 65 —-> A

************************
STRING FUNCTIONS

1. length(); :- It returns length of a string (total no.of characters)


including space and special characters.​

Syntax:-​

datatype variablename = Stringobject.length();

2. .length; :- It returns length of an array.​

Syntax:-​

datatype variablename = arrayobject.lenght;

3. .charAt();:- It returns the character present at the index specified


in the bracket from any string object.​

Syntax:-

datatype variablename = stringobject.charAt(integer value);

4. indexOf(); :- It returns the index number of a character specified in


the brackets from a string object.

Syntax:-

datatype variablename = Stringobject.indexOf(char);

5. lastIndexOf(); :- It returns the last index number of a character


specified in the brackets from a string object.​

Syntax:-​

datatype variablename = Stringobject.lastIndexOf(char);


6. replace(c1, c2); :- It replaces/returns all the occurrence of a
character by a new character in a string.​

Syntax:-​

datatype variablename = Stringobject.replace(c1, c2);

7. compareTo(); :- It is used to compare two strings lexicographically


i.e. length wise and character wise.​

Syntax:-​

datatype variablename = Stringobject.compareTo(String object);

7. trim(); :- It trims all the spaces present in the beginning and end of
the string except the space in between.​

Syntax:-​

datatype variablename = Stringobject.trim();

8. concat(); :- It is used to join two strings one after another without


any space.​

Syntax:-

datatype variablename = Stringobject.concat();

9. reverse(); :- It reverses the given string.​



Syntax:-

datatype variablename = Stringobject.reverse();


10. substring(); :- It returns the substring from a string starting from
nth index character upto the xth index of the string or end of the
string.

Syntax:-​

datatype variablename = Stringobject.substring(start index, end


index);​

Or

datatype variablename = Stringobject.substring(start index);

11. equals(); :- This function returns true if two strings are equal
otherwise it returns false. It is case-sensitive.​

Syntax:-​

datatype variablename = Stringobject.equals(String object);

12. equalsIgnoreCase(); :- This function returns true if two strings


are equal otherwise it returns false. It is not case-sensitive.​

Syntax:-

datatype variablename = Stringobject.equalsIgnoreCase(String


object);

13. toLowerCase(); :- It is used to convert a string into lowercase


form i.e. all the alphabets will be converted from capital to small
letters.​

Syntax:-

datatype variablename = Stringobject.toLowerCase();


14. toUpperCase(); :- It is used to convert a string into uppercase
form i.e. all the alphabets will be converted from small to capital
letters.​

Syntax:-​

datatype variablename = Stringobject.toUpperCase();

15. startsWith(); :- It returns true if the string starts with string value
mentioned within brackets. It returns boolean datatype.​

Syntax:-

datatype variablename = Stringobject.startsWith(String object);

16. endsWith(); :- It returns true if the string ends with the string
value mentioned in brackets. It returns boolean datatype.

Syntax:-​

datatype variablename = Stringobject.endsWith(String object);

17. Library:- Library is a collection of predefined functions which


provide some meaningful instructions to the compiler which helps in
executing the instructions in a program.

************************

You might also like