Sunday, 31 March 2024

Java Fundamentals : Java Core

 


By Mukul Sinha

JAVA BASICS

(I.C.S.E EXAM 2025) - Computer Applications

Multiple Choice Questions:- (Section Q1 20 Marks)

Topic : Object Oriented Programming

Topic: Revision of Class IX :    

1. Introduction of Class and Object:(Revision of Class IX)

Points to remember:-

1. Classes are user-defined data types that act as the blueprint for individual objects, attributes and methods.

2. Objects are instances of a class created with specifically defined data. 

3. Objects can correspond to real-world objects or an abstract entity. 

4. When class is defined initially, the description is the only object that is defined.

5. Methods are functions that objects can perform. 

6. They are defined inside a class that describe the behaviors of an object. 

7. Each method contained in class definitions starts with a reference to an instance object. 

8. Additionally, the subroutines contained in an object are called instance methods. 

9. Programmers use methods for reusability or keeping functionality encapsulated inside one object at a time.

10. Attributes represent the state of an object. 

11. In other words, they are the characteristics that distinguish classes. 

12. Objects have data stored in the attributes field. 

13. Class attributes belong to the class itself and are defined in the class template.

14. Encapsulation. The encapsulation principle states that all important information is contained inside an object and only select information is exposed. 

15. The implementation and state of each object are privately held inside a defined class. 

16. Other objects do not have access to this class or the authority to make changes. 

17. They are only able to call a list of public functions or methods. 

18. This characteristic of data hiding provides greater program security and avoids unintended data corruption.

19. Abstraction. Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. 

20. The derived class can have its functionality extended. 

21. This concept can help developers more easily make additional changes or additions over time.

22. Inheritance : Classes can reuse code and properties from other classes. 

23. Relationships and subclasses between objects can be assigned, enabling developers to reuse common logic, while still maintaining a unique hierarchy. 

24. Inheritance forces more thorough data analysis, reduces development time and ensures a higher level of accuracy.

25. Polymorphism. Objects are designed to share behaviors, and they can take on more than one form. 

26. The program determines which meaning or usage is necessary for each execution of that object from a parent class, reducing the need to duplicate code. 

27. A child class is then created, which extends the functionality of the parent class. 

28. Polymorphism enables different types of objects to pass through the same interface.


Object Oriented Programming  Benifits
Points to remember:-
Benefits of OOP include the following:
1. Modularity. Encapsulation enables objects to be self-contained, making troubleshooting and collaborative development easier.
2. Reusability. Code can be reused through inheritance, meaning a team does not have to write the same code multiple times.
3. Productivity. Programmers can construct new programs quickly through the use of multiple libraries and reusable code.
4. Easily upgradable and scalable. Programmers can implement system functionalities independently.
5. Interface descriptions. Descriptions of external systems are simple, due to message-passing techniques that are used for object communication.
6. Security. Using encapsulation and abstraction, complex code is hidden, software maintenance is easier and internet protocols are protected.
7. Flexibility. Polymorphism enables a single function to adapt to the class it is placed in. Different objects can also pass through the same interface.
8. Code maintenance. Parts of a system can be updated and maintained without needing to make significant adjustments.
9. Lower cost. Other benefits, such as its maintenance and reusability, reduce development costs.

Multiple Choice Questions:-

1. In procedural Oriented Programming paradigm where a complex programming problem into its smaller problems using ________.

(a)  Procedural Oriented Programming            (b) Object Oriented Programming

(c) Structural Programming                             (d) None of these.

Ans:- (b) Object Oriented Programming

2.  Principles of Object Oreinted Programming are Polymorphism, Abstraction, Encapsulation and_______  .

(a)  Procedural Oriented Programming            (b) Object Oriented Programming

(c) Inheritance                                                  (d) None of these.

Ans:- (c) Inheritance


3. ______ is an act of representing essential feature without including the background details.

(a) Abstraction                                                        (b) Inheritance

(c) Polymorphism                                                  (d) None of these.

Ans:- (a) Abstraction


4. ______ is a powerful mechanism by which a class acquires the properties of another class. It allows a class to use the attributes and behaviour of its parent class.   .

(a) Abstraction                                                        (b) Inheritance

(c) Polymorphism                                                  (d) None of these.

Ans:- (b) Inheritance.


5. __________ is a n ability of a method or an object to take on multiple forms. In Oops _______ allows an operation to exhibits different behaviour in diffferent instances. 

(a) Abstraction                                                        (b) Inheritance

(c) Polymorphism                                                  (d) None of these.

Ans:- (c) Polymorphism 


6. __________ is a represents data(attributes) fof multiple object with similar features. A lion giraffe and cow all belong to the Animal class. Similarly mango, apple, and orange all belongs to Fruit class>  . 

(a) Abstraction                                                        (b) Inheritance

(c) Polymorphism                                                  (d) None of these.

Ans:- (c) Polymorphism 


7. Classes that derives from previous class are________.

(a) super class                                                        (b) sub class

(c) both a and b                                                      (d) None of these.

Ans:- (b) sub class 


8. The concept tht implements - a super class and a sub class.                                                                       [ICSE 2024]

(a) Abstraction                                                        (b) Inheritance

(c) Polymorphism                                                  (d) None of these.

Ans:- (b) Inheritance.


9. The concept tht implements - the act of representing essential features without including backgroud details.[ICSE 2024] 

(a) Abstraction                                                        (b) Inheritance

(c) Polymorphism                                                  (d) None of these.

Ans:- (b) Abstraction.


10. Assertion(A): Static methods can access static and instance variable.                                                    [ICSE 2024]

      Reason(R): Static variable can be accessed only by static methods. 

(a) Assertion and Reason both are true                  (b) Assertion  is true and Reason is false 

(c) Assertion  is false and Reason is true               (d) Assertion and Reason both are false.    

Ans:- (d) Assertion and Reason both are false.

Reason:- Static methods ca access only the static variables. It does not access or change the instance variable. Static variable can be accessed by both instance and static methods.  


Topic: Revision of Class IX :    

2. Introduction to Java(Revision of Class IX)

Points to remember:-

Some other things to know about Java:

a. Java was invented in 1991 by James Gosling of Sun Microsystems 

b. The original name for Java was Oak, but it was later changed to Green, then Java Coffee, and finally to Java in 1995 

c. Java is free to download for personal use and development 

d. Java is the world's third most popular programming language, after Python and C 

e. Java emphasizes exception handling and type safety to prevent errors and make code more robust 

f. Java has a garbage collector that automatically frees up memory that is no longer being used 

Java is a programming language and computing platform that's used to create many applications, including:

Smartphone operating systems

* Enterprise software

* Mobile apps

* Big data applications

* Server-side technologies

* Web applications

* Games 


Why Java?

1. Java is a popular choice for developers because it's: 

2. Multiplatform: Runs on billions of devices worldwide 

3.Object-oriented: Based on the C and C++ languages 

4. Fast, secure, and reliable: A platform for coding a wide range of applications 

5. "Write once, run anywhere": The primary goal of Java was to be able to run on any device 


Multiple Choice Questions:- 

1. Which language does CPU understand?  

(a) Machine Language                                     (b) High-Level Language

(c) Assembly Language                                   (d) English Language.

Ans:- (a) Machine Langauge.

2. Stand alone java applications ____________ for execution.

(a) needs java compiler web browser                (b) donot need needs java compiler web browser

(c) needs assembler                                           (d) need a linker..

Ans:- (b) donot need needs java compiler web browser.


3. The full for of JRE is 

(a) Java Run Time Editor                                     (b) Java Run Time Expression

(c)  Java Run Time Environment                         (d) Java Run Time Enabler.

Ans:- (c) Java Run Time Environment

4.Java uses _________________ for execution.

(a) Compilatin and Interpretation                         (b) compilation only  

(c)  interpreatation only                                        (d) None of these

Ans:- (a) Compilatin and Interpretation.


5. A program that translates code written in-a high-level language into machine code is called _______________. 

(a) Assembler                                                       (b) Colpiler  

(c) Linker                                                             (d) None of these

Ans:- (c) Compiler. 


6. Java can be used to write ______________. 

(a) stand-alone application only                                               (b) internet application only  

(c) Both stand-alone application and internet application       (d) All of these

Ans:- (b) Both stand-alone application and internet application.


7. Java applications runs on  ______________. 

(a) Windows platform                                       (b) UNIX platform  

(c) Machintosh                                                  (d) All of these. 

Ans:- (d) All of these.


8. Java application ________________.

(a) are platform dependent                                (b) are platform independent  

(c) does not need a platform to run                   (d) cannot run Windows.  

Ans:- (c)  does not need a platform to run


9. A java progra mcan run as a stand alone application only if it has________________. 

(a) a void method                                               (b) a main method    

(c) an overoaded method                                   (d) no method.  

Ans:- (c) an overoaded method 


10. Choose which is the correct statemenr 

A. Applet can be executed in a web browser only

B. Applet can be executed in an applet viewer only

C. Applet can be executed in both  web browser and applet viewer.

D.Applet canot be executed

Ans:- (C) Applet can be executed in both  web browser and applet viewer. 


Topic: Revision of Class IX :    

3. Values and Types.(Revision of Class IX)

Points to remember:-


1. Primitive Data Types.
A primitive data type specifies the size and type of variable values, and it has no additional methods.
There are eight primitive data types in Java:
Data Type  Size               Description
byte            1 byte Stores whole numbers from -128 to 127
short           2 bytes Stores whole numbers from -32,768 to 32,767
int            4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
long            8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float            4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double        8 bytes Stores fractional numbers. Sufficient for storing 15 to 16 decimal digits
boolean      1 bit      Stores true or false values
char            2 bytes Stores a single character/letter or ASCII values

2. Reference Data Types
Non primitive data types includes classes, interface, and arrays are also called reference data types. They are created by programmers as they are not predefined like primitive data types. They are also called reference data type or object data types.

3. Type Conversion
Type casting or type conversion is the term used when a value is converted from one data type to another. In Java type conversion can be done in two different ways. Implicit type conversion and explicit type conversion.

a. Implicit Type Conversion Automatically convert from lower data type version to higher data type version.
shortint long
charint floatdouble
shortint long

b. Explicit Type Conversion  Convertion done forcefully 
a. Conversion from int to float  
int x=10;
float val =(float)x;
b. Conversion from float to int  
float x=10.5F;
int val =(int)x;
c. Conversion from float to double    

float x=10.5F;

double val =(float)x;
d. Conversion from double to float

dlouble x=10.5383F;

float val =(double)x;
e. Conversion from short to int
short x=34;
int val=(int)x;
f. Conversion from int to short
int x=34;
short val=(short)x;

4. Escape Sequence:-  A character with a backslash (\) just before it is an escape sequence or escape character. We use escape characters to perform some specific task. 4
The total number of escape sequences or escape characters in Java is 8. 
Each escape character is a valid character literal. 
The list of Java escape sequences:

1. Java uses_______ charcter sets.   

(a) ASCI only                                                   (c) Unicode

(b) Extended ASCII Only                                 (d) None of these..

Ans:- (c) Unicode

2.The smallest indivisual components in a program is called ______________

(a) Token                                                         (c) Keywords

(b) Identifier                                                    (d) methods.

Ans:- (a) Token

3. Which of the following is not a token:-

(a) Operators                                                    (c) Keywords

(b) Identifier                                                    (d) Procedures

Ans:- (d) Procedures 


4. Operator in Java. (Revision of Class IX)

Points to remember:-

Operators

1. Operators in Java are the symbols used for performing specific operations in Java. 

2. Operators make tasks like addition, multiplication, etc which look easy although the implementation of these tasks is quite complex.

3. Operators are the building blocks of Java expressions, allowing you to perform calculations, comparisons, and more.

4.Types of Operators in Java
   There are multiple types of operators in Java all are mentioned below:
            a. Arithmetic Operators
            b. Unary Operators
            c. Assignment Operator
            d. Relational Operators
            e. Logical Operators
            f. Ternary Operator
            g. Bitwise Operators
            h. Shift Operators
            i. instance of operator
5.Arithmetic Operators
       They are used to perform simple arithmetic operations on primitive and non-primitive data types. 
* : Multiplication
/ : Division
% : Modulo
+ : Addition
– : Subtraction


6. Unary operators need only one operand. They are used to increment, decrement, or negate a value. 

(i)       – : Unary minus, used for negating the values.

(ii)      + : Unary plus indicates the positive value (numbers are positive without this, however). It performs an automatic conversion to int when the type of its    operand is the byte, char, or short. This is called unary numeric promotion.

(iii)     ++ : Increment operator, used for incrementing the value by 1. There are two varieties of increment operators. 

(iv)     Post-Increment: Value is first used for computing the result and then incremented.

(v)      Pre-Increment: Value is incremented first, and then the result is computed.

(vi)     – –  : Decrement operator, used for decrementing the value by 1. There are two varieties of decrement operators. 

(vii)    Post-decrement: Value is first used for computing the result and then decremented.

(viii)   Pre-Decrement: The value is decremented first, and then the result is computed.

(ix) ! : Logical not operator, used for inverting a boolean value.


7.  Assignment Operator

 ‘=’ Assignment operator is used to assign a value to any variable. It has right-to-left associativity, i.e. value given on the right-hand side of the operator is assigned to the variable on the left, and therefore right-hand side value must be declared before using it or should be a constant.

int x=10;


+=, for adding the left operand with the right operand and then assigning it to the variable on the left.

Ex:-

int x=10;

int x+=5;

System.out.println(x);

Output

x=10+5=15


-=, for subtracting the right operand from the left operand and then assigning it to the variable on the left.

Ex:-

int x=10;

int x-=5;

System.out.println(x);

Output

x=10-5=5


*=, for multiplying the left operand with the right operand and then assigning it to the variable on the left.

Ex:-

int x=10;

int x*=5;

System.out.println(x);

Output

x=10*5=50


/=, for dividing the left operand by the right operand and then assigning it to the variable on the left.

Ex:-

int x=10;

int x/=5;

System.out.println(x);

Output

x=10/5=2


%=, for assigning the modulo of the left operand by the right operand and then assigning it to the variable on the left.

Ex:-

int x=10;

int x%=5;

System.out.println(x);

Output

x=10%5=0


8. Relational Operators: These operators are used to check for relations like equality, greater than, and less than. They return boolean results after the comparison and are extensively used in looping statements as well as conditional if-else statements. The general format is

Some of the relational operators are- 
= =                        - Equal to returns true if the left-hand side is equal to the right-hand side.
!=                          - Not Equal to returns true if the left-hand side is not equal to the right-hand side.
<                           - less than: returns true if the left-hand side is less than the right-hand side.
<=                         - less than or equal to returns true if the left-hand side is less than or equal to the right-hand side.
>                           - Greater than: returns true if the left-hand side is greater than the right-hand side.
>=                         - Greater than or equal to returns true if the left-hand side is greater than or equal to the right-hand side.

9. Logical Operators: These operators are used to perform “logical AND” and “logical OR” operations, i.e., a function similar to AND gate and OR gate in digital electronics. One thing to keep in mind is the second condition is not evaluated if the first one is false, i.e., it has a short-circuiting effect. Used extensively to test for several conditions for making a decision. Java also has “Logical NOT”, which returns true when the condition is false and vice-versa

Conditional operators are:
&& (Logical AND): returns true when both conditions are true.
||, (Logical OR): returns true if at least one condition is true.
! (Logical NOT): returns true when a condition is false and vice-versa 

10. Ternary Operator: The ternary operator is a shorthand version of the if-else statement. It has three operands and hence the name Ternary.
The general format is:
condition ? if true : if false

11. Bitwise Operators: These operators are used to perform the manipulation of individual bits of a number. They can be used with any of the integer types. They are used when performing update and query operations of the Binary indexed trees. 

&                      - Bitwise AND operator: returns bit by bit AND of input values.
|                        - Bitwise OR operator: returns bit by bit OR of input values.
^                       - Bitwise XOR operator: returns bit-by-bit XOR of input values.
~                       - Bitwise Complement Operator: This is a unary operator which returns the one’s complement representation of the input value, i.e., with all bits inverted.

12. Shift Operators: These operators are used to shift the bits of a number left or right, thereby multiplying or dividing the number by two, respectively. They can be used when we have to multiply or divide a number by two. General format- 

 number shift_op number_of_places_to_shift;
<<, Left shift operator: shifts the bits of the number to the left and fills 0 on voids left as a result. Similar effect as multiplying the number with some power of two.
>>, Signed Right shift operator: shifts the bits of the number to the right and fills 0 on voids left as a result. The leftmost bit depends on the sign of the initial number. Similar effect to dividing the number with some power of two.
>>>, Unsigned Right shift operator: shifts the bits of the number to the right and fills 0 on voids left as a result. The leftmost bit is set to 0.

13. instance of operator: The instance of the operator is used for type checking. It can be used to test if an object is an instance of a class, a subclass, or an interface. General format- 

object instance of class/subclass/interface

.

5. Inputs in Java. (Revision of Class IX)

Points to remember:-

1. Buffered Reader Class BufferedReader class is used to read text from a character-input stream efficiently. It provides buffering, which significantly improves the performance of reading operations compared to reading directly from the underlying stream.


Syntax for creating object of Buffered Reader Class

Buffered Reader  br=new Buffered Reader(new InputStreamReader(System.in));


Example of Buffered Reader class

import java.io;

class Main {

  public static void main(String[] args) {

    Buffered Reader  br=new Buffered Reader(new InputStreamReader(System.in));


    System.out.println("Enter name, age and salary:");


    // String input

    String name = String.valueOf(br.readLine());


    // Numerical input

    int age = Integer.parseInt(br.readLine());

    double salary =Double.parseDouble(br.readLine());


    // Output input by user

    System.out.println("Name: " + name);

    System.out.println("Age: " + age);

    System.out.println("Salary: " + salary);

  }

}

2. Scanner Class  Scanner class helps to take the standard input stream in Java.

Syntax for creating object of Scanner class

Scanner  sc=new Scanner(System.in);



Example of Scanner class

import java.util.Scanner;


class Main {

  public static void main(String[] args) {

    Scanner myObj = new Scanner(System.in);


    System.out.println("Enter name, age and salary:");


    // String input

    String name = myObj.nextLine();


    // Numerical input

    int age = myObj.nextInt();

    double salary = myObj.nextDouble();


    // Output input by user

    System.out.println("Name: " + name);

    System.out.println("Age: " + age);

    System.out.println("Salary: " + salary);

  }

}



Method Description

nextBoolean()                  -       Reads a boolean value from the user

nextByte()                        -  Reads a byte value from the user

nextDouble()                  -       Reads a double value from the user

nextFloat()                  -       Reads a float value from the user

nextInt()                          -       Reads a int value from the user

nextLine()                  -       Reads a String value from the user

nextLong()                  -    Reads a long value from the user

nextShort()                  -       Reads a short value from the user

6. Mathematical Library Methods (Revision of Class IX)


Mathematical Library Mathods 

1. abs()        - To find the absolute value of an argument

                           Ex. int x=Math.abs(-1);         // +1 is the output

2. floor()        - To find the round of the argument with most value 

                           Ex. int x=Math.floor(3.4);    //3 is the output

3. ceil()        - To find the round of the argument with least value

                           Ex. int x=Math.ceil(3.4);      //4 is the output

4. pow()        - To find the absolute value of an argument

                           Ex. int x=Math.pow(2,4);      //2x2x2x2=16 is the output

5. singnum()        - To find the sin number value of an argument

                           Ex. int x=Math.signum(2, -1);  // -2 is the output

6. round()        - To find the round value of an argument

                           Ex. int x=Math.round(3.4533);  //3 is the output

7. max()        - To find the max value of an argument

                           Ex. int x=Math.max(2,3);          // 3 is maximum

8. min()        - To find the min value of an argument

                           Ex. int x=Math.min(-1,3);       // -1 is minimum

9. sqrt()        - To find the square root value of an argument

                           Ex. int x=Math.sqrt(3);           // square root of 3 is 1.732

10.cbrt()        - To find the cube root value of an argument

                           Ex. int x=Math.cbrt(8);         // cube root of 8 is 2


BufferedReader Class
It is the simple 
Scanner Class






Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

7. Conditional Constructs in Java (Revision of Class IX)

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

8. Iterative Constructs in Java.(Revision of Class IX)

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

9. Nested for Loop (Revision of Class IX)

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 2: Classes as the Basis of All Computations

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 3: User - defined Methods

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 4: Constructors

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 5: Library Classes

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 6: Encapsulations

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 7: Array

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Chapter 8: String Handling

Points to remember:-

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.



No comments:

Post a Comment

CLASS X TYPES OF NUMBERS

 CLASS X  TYPES OF NUMBERS List of types of Numbers 1. Arm Strong Number 2.  Co-prime Number 3. Duck Number [I.C.S.E 2024] 4. Magic Number  ...