Practical 1
Last updated
Was this helpful?
Last updated
Was this helpful?
Write a program to create a class, instance variable, constructor and method. After this create a class FirstDemo with main method and access the member of above class.
Class: A blueprint for creating objects. A class encapsulates data for the object and methods to manipulate that data.
Instance Variable: A variable that is defined in a class for which each instantiated object of the class has a separate copy.
Constructor: A special method that is called when an object is instantiated. It is used to initialize the object.
Method: A function defined in a class that operates on instances of that class.
Write a program to create one dimensional and multidimensional array and display the array using for and for each loop. All the data of array should be taken from user.
One-Dimensional Array: A list of elements of the same type.
Multidimensional Array: An array of arrays, where each element is itself an array.
Write a program to demonstrate single level and multi-level inheritance.
Inheritance: The mechanism by which one class acquires the properties and behavior of another class.
Single Inheritance: A class can inherit from only one class.
Multi-Level Inheritance: A class can inherit from another class, which in turn can inherit from another class.
Done by using the extends
keyword.
Example: class Child extends Parent
Provide example on method overriding condition.
Method Overriding: A subclass providing a specific implementation of a method that is already provided by its superclass.
Overriding Condition: The method in the subclass must have the same name, same parameters or signature, and same return type as the method in the superclass.
Provide example on dynamic method dispatch.
Dynamic Method Dispatch: The mechanism by which a call to an overridden method is resolved at runtime, rather than compile-time.
Polymorphism: The ability of an object to take on many forms.
Method Overriding: A subclass providing a specific implementation of a method that is already provided by its superclass.
Demonstrate inheritance in interface (extending the interface).
Interface: A reference type in Java, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types.
Inheritance in Interface: An interface can inherit from another interface.
Write a program to demonstrate multithreading using both Thread class and Runnable interface.
Multithreading: The ability of a CPU to execute multiple threads concurrently.
Thread Class: A class in Java that provides methods to create and perform operations on a thread.
Runnable Interface: An interface in Java that provides a method to run a thread.
Thread: A path of execution within a program.
Concurrency: The ability of different parts or units of a program, algorithm, or problem to be executed out-of-order or in partial order, without affecting the final outcome.
Synchronization: The coordination of multiple threads to prevent conflicts
Deadlock: A situation where two or more threads are waiting for each other to release a resource, preventing them from continuing.
Write a program to demonstrate inter thread communication.
Inter-Thread Communication: The process of communication between two or more threads.
wait(): Causes the current thread to wait until another thread invokes the notify()
method or the notifyAll()
method for this object.
notify(): Wakes up a single thread that is waiting on this object's monitor.
notifyAll(): Wakes up all threads that are waiting on this object's monitor.
Write a program to demonstrate reading and writing data in file.
File Handling: The process of working with files on a computer.
Reading Data: The process of reading data from a file is performed using input streams like BufferedReader.
Writing Data: The process of writing data to a file is performed using output streams like BufferedWriter.