Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Computer Class As Computation

Class 10th icse computer application chapter class as computation

Uploaded by

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

Computer Class As Computation

Class 10th icse computer application chapter class as computation

Uploaded by

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

S.J.B.S.

S PUBLIC SCHOOL
2nd Block, Rajajinagar, Bangalore-560010

An Internal Assessment based on computer applications

In the partial fulfillment of the requirement for The Indian Certificate Of


Secondary Examination.

Topic: Class as the basis of computation

Under the guidance of


Mrs. Roopashree Mam
Submitted by : - Abhay.S.J
Class: - 10th standard
Roll no: - 01
CONTENTS:
1. Library Classes
2. Wrapper Class
3. Autoboxing
4. Unboxing
5. Java Utility Methods
6. Encapsulation
7. Java Access Specifiers
8. Inheritance
9. Java Packages
10. Scope of Variables in Java
1.Library Classes
Definition: Library classes in Java refer to predefined classes that
are part of the Java standard library (often referred to as the Java
API). These are classes that provide ready-to-use methods and
functionality for tasks like input/output (I/O), string manipulation,
data structures, networking, and more.
Common Library Classes:
java.util (for data structures like ArrayList, HashMap)
java.io (for file input/output)
java.lang (for basic language functionalities such as String, Math)
Example:
java
Copy code
import java.util.ArrayList;
public class LibraryClassExample {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
System.out.println(list); // Output: [Hello, World]
}
}
Here, ArrayList is a library class that provides a dynamic array.

2. Wrapper Class
Definition: A wrapper class in Java provides a way to use primitive
data types (like int, char, etc.) as objects. Each primitive type has a
corresponding wrapper class, such as Integer for int, Double for
double, and so on.
Common Wrapper Classes:
Integer for int
Character for char
Boolean for boolean
Example:
java
Copy code
public class WrapperClassExample {
public static void main(String[] args) {
int num = 5;
Integer wrappedNum = Integer.valueOf(num); // Boxing
System.out.println(wrappedNum);
}
}
In this example, Integer is a wrapper class that wraps the primitive
int into an object.

3. Autoboxing
Definition: Autoboxing is the automatic conversion of primitive
data types into their corresponding wrapper class objects. This is
useful in cases where an object is required, such as in collections
(e.g., ArrayList or HashMap).
Example:
java
Copy code
public class AutoboxingExample {
public static void main(String[] args) {
int num = 10;
Integer wrappedNum = num; // Autoboxing: automatic conversion
from int to Integer
System.out.println(wrappedNum);
}
}
Here, num is automatically converted from int to Integer.

4. Unboxing
Definition: Unboxing is the reverse of autoboxing, where an object
of a wrapper class is automatically converted into its corresponding
primitive type.
Example:
java
Copy code
public class UnboxingExample {
public static void main(String[] args) {
Integer wrappedNum = 20;
int num = wrappedNum; // Unboxing: automatic conversion from
Integer to int
System.out.println(num);
}
}
In this example, wrappedNum (an Integer object) is automatically
unboxed into an int.

5. Java Utility Methods


Definition: Java utility methods refer to useful helper functions
provided by various Java utility classes, such as in the java.util
package. These methods assist in common tasks like manipulating
collections, performing date/time operations, and formatting.
Common Utility Classes:
Collections for working with collections (sort(), reverse(), etc.)
Arrays for array manipulation (binarySearch(), sort(), etc.)
Example:
java
Copy code
import java.util.Collections;
import java.util.ArrayList;
public class UtilityMethodsExample {
public static void main(String[] args) {
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(3);
numbers.add(1);
numbers.add(2);
Collections.sort(numbers); // Utility method to sort the list
System.out.println(numbers); // Output: [1, 2, 3]
}
}
Collections.sort() is a utility method that sorts a list.

6. Encapsulation
Definition: Encapsulation is the principle of wrapping data
(variables) and code (methods) together as a single unit, usually by
making variables private and providing public getter and setter
methods for access.
Benefits: It hides the internal state of an object and only exposes a
controlled interface.
Example:
java
Copy code
public class EncapsulationExample {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Main {
public static void main(String[] args) {
EncapsulationExample obj = new EncapsulationExample();
obj.setName("John");
System.out.println(obj.getName()); // Output: John
}
}
The class EncapsulationExample encapsulates the name variable by
providing public methods to access it.

7. Java Access Specifiers


Definition: Access specifiers in Java define the scope of visibility for
classes, methods, and variables. Java has four access specifiers:
public: Accessible from anywhere.
private: Accessible only within the class.
protected: Accessible within the same package and subclasses.
No Modifier (Package-private): Accessible only within the same
package.
Example:
java
Copy code
public class AccessSpecifierExample {
public int publicVar = 1;
private int privateVar = 2;
protected int protectedVar = 3;
int defaultVar = 4; // package-private
}

8. Inheritance
Definition: Inheritance allows a class to acquire properties and
behavior (methods) from another class. The class that is inherited is
called the superclass or parent class, and the class that inherits is
called the subclass or child class.
Syntax: class SubClass extends SuperClass
Example:
java
Copy code
class Animal {
void eat() {
System.out.println("This animal eats food.");
}
}
class Dog extends Animal {
void bark() {
System.out.println("The dog barks.");
}
}
public class InheritanceExample {
public static void main(String[] args) {
Dog dog = new Dog();
dog.eat(); // Inherited from Animal class
dog.bark(); // Defined in Dog class
}
}
In this example, Dog inherits the eat() method from Animal.

9. Java Packages
Definition: A package in Java is a namespace that organizes a set of
related classes and interfaces. Java provides built-in packages such
as java.util and java.io. You can also create your own packages.
Purpose: To prevent naming conflicts and make it easier to locate
and use classes.
Example:
java
Copy code
package mypackage; // Declare a package
public class MyClass {
public void display() {
System.out.println("Hello from the package!");
}
}

10. Scope of Variables in Java


Definition: The scope of a variable refers to the region of the
program where the variable is accessible. There are several types of
scope in Java:
Local Variables: Declared inside a method or block and accessible
only within that method or block.
Instance Variables: Declared within a class but outside any method
and accessible by all methods of the class.
Static Variables: Declared using the static keyword and shared
among all instances of the class.
Example:
java
Copy code
public class ScopeExample {
int instanceVar = 5; // Instance variable
public static void main(String[] args) {
int localVar = 10; // Local variable
System.out.println(localVar);
}
}
In this example, localVar is a local variable, while instanceVar is an
instance variable.
Thank you..

You might also like