Computer (1)
Computer (1)
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.
Inheritance:-
Inheritance is the process by which one class acquires the
property of another class.
Polymorphism:-
Abstraction:-
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.
************************
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:-
Features of Java:-
● Object-Oriented
● Platform Independent
● Distributed
● Multi-threads
● Security
● High Performance
● Portable
● Compiler & Interpreter
● Simple Programming Language
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.
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.
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.
************************
VALUES AND DATATYPES
Definitions
Types of Expressions:-
int 0
float 0.0f
double 0.0d
long 0L
short 0
char null
string null
boolean false
Operator Expression
Ex:-
{
int a=10,b=20;i
int c = a+b;
}
next() nextLine()
int Integer
float Float
double Double
char Character
String String
boolean Boolean
byte Byte
short Short
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();
Long sc.nextLong();
char sc.nextCharacter();
byte sc.nextByte();
boolean sc.nextBoolean();
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.
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.
************************
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);
}
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);
}
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 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
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
Syntax:-
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:-
Example:-
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.println(j);
}
}
Syntax:-
for(initial value;update)
{
statement;
}
Example:-
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++)
{
}
Syntax:-
while(condition)
{
statement;
}
Example:-
int a=1;
while(a<=10)
{
System.out.println(a);
a++;
}
do
{
statement;
}while(condition);
Example:-
int a=1;
do
{
System.out.println(a);
a++;
}while(a<=10);
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:-
Syntax:- Syntax:-
Example:- Example:-
************************
FUNCTION OR METHOD
Example:-
Example:-
Example:-
public static void main()
{
statements;
}
************************
CONSTRUCTOR
It has no return type, not even It must begin with either void or
void data type. return data type.
************************
LIBRARY CLASSES (STRING HANDLING)
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
Syntax:-
Syntax:-
7. trim(); :- It trims all the spaces present in the beginning and end of
the string except the space in between.
Syntax:-
Syntax:-
11. equals(); :- This function returns true if two strings are equal
otherwise it returns false. It is case-sensitive.
Syntax:-
Syntax:-
15. startsWith(); :- It returns true if the string starts with string value
mentioned within brackets. It returns boolean datatype.
Syntax:-
16. endsWith(); :- It returns true if the string ends with the string
value mentioned in brackets. It returns boolean datatype.
Syntax:-
************************