Both the algorithms and programs are used to solve problems, but they are not the same things in terms of their functionality. A step-by-step process to solve the problem is called an algorithm, and a program is a set of instructions that are given to the computer to solve the problems.
The very basic example of an algorithm and program is shown in the following figure.
Problem: Find the sum of two numbers
Differences Between Programs and Algorithms
The definitions of "programs" and "algorithms" are similar, but there are some key differences between them, which are explained under
Sr.
Algorithm
Program
1.
Domain knowledge helps to build the algorithm
The programmer builds the program
2.
Platform (hardware and software) independent
Platform (hardware and software) dependent
3.
It can be expressed in natural language, flow charts, pseudo code, and in a variety of languages.
A compiler or interpreter translates a program into binary language that is understandable by any computer system.
4.
It is written using plain English and is easily understood without a programming background.
It could be written in any programming language, such as C, C++, Python, or any other computer language.
5.
The constructions of an algorithm are designed based
The construction of the program is implementation-based
6.
Generally, the algorithm is designed to solve the problem
A program can even contain no or many algorithms
7.
An algorithm can be executed by a person.
A program is always executed by a computer.
8.
After the construction of the algorithm, the next step is to analyze it.
After the construction of the Program, the next step is to test it.
Priori Analysis and Posteriori Testing
The time and space complexity of an algorithm can be calculated by using the following two methods
Priori Analysis
Posteriori Testing
The difference between A posteriori analysis and A Priori analysis is given below
Sr.
Priori Analysis
Posteriori Testing
1.
It is required for the Algorithm
It is required for the program
2.
It is independent of language
It is dependent on the language
3.
It is hardware-independent
It is hardware-dependent
4.
It is done before the execution of an algorithm.
It is done after the execution of an algorithm.
5.
It provides an approximate answer.
It provides the exact answer.
6.
It is less expensive than Posteriori Analysis.
It is more expensive than a priori analysis due to the need of software and hardware for execution.
7.
It uses the asymptotic notations to represent the time and space complexity of the algorithm
It doesn’t use asymptotic notations to represent the time and space complexity of a program.
8.
Results are in the form of time and space complexity/function
Results are in the form of watch time (Run time) and memory.
R20 MCA Syllabus – Complete Details & Unit-wise Material
Course Objectives
1. Understand the basic concepts of object-oriented programming.
2. Introduce inheritance, polymorphism, and abstract class design.
3. Learn packages, interfaces, and their implementation.
4. Understand multithreading and exception handling.
5. Design GUI using AWT, Applets, and Swing controls.
Course Outcomes
1. Describe and apply OOP concepts to solve problems.
2. Implement packages and interfaces in Java.
3. Develop multithreaded applications with exception handling.
4. Design GUI-based applications using AWT and Swing.
5. Use Java Collection Framework effectively.
Unit 1: Basics of OOP & Java Fundamentals
Need for OO paradigm , A way of viewing world- Agents, responsibility, messages, methods, classes and instances, class hierarchies (Inheritance), method binding, overriding and exceptions, summary of OOP concepts, coping with complexity, abstraction mechanisms. Java Basics: Data types, variables, scope and life time of variables, arrays, operators, expressions, control statements, type conversion and costing, simple java program, classes and objects- concepts of classes, objects, constructors methods, access control, this keyword, garbage collection, overloading methods and constructors, parameter passing, recursion, string handling.
Inheritance: Hierarchical abstractions, Base class object, subclass, subtype, substitutability, forms of inheritance- specialization, specification, construction, extension, limitation, combination, benefits of inheritance costs of inheritance. Member access rules, super uses, using final with inheritance, polymorphism, abstract classes. Packages and Interfaces: Defining, Creating and Accessing a package, Understanding CLASSPATH, Importing packages, differences between classes and interfaces, defining an interface, Implementing interface, applying interfaces variables in interface and extending interfaces.
Concepts of exception handling, benefits of exception handling, Termination or presumptive models, exception hierarchy, usage of try, catch, throws and finally, built in exceptions, creating own exception sub classes. Differences between multi threading and multitasking, thread life cycle, creating threads, synchronizing threads, daemon threads, thread groups.
Concepts of Applets, differences between applets and applications, lifecycle of an applet, types of applets, creating applets, passing parameters to applets, Swings: Introduction, limitations of AWT, MVC architecture, components, containers, exploring swing- JApplet, JFrame and JComponent, Icons and Labels, text fields, buttons-The JButton class, Check boxes, Radio Buttons, Combo boxes, Tabbed panes, Scroll panes, Trees and Tables.
In this article we will learn what are daemon threads? and how to make thread as daemon thread along with example Java program.
A daemon thread is a thread which runs in the background. Example for daemon thread in Java is the garbage collector. In Java, thread can be divided into two categories:
User threads
Daemon threads
A user thread is a general thread which is created by the user. A daemon thread is also a user thread which is made as a daemon thread (background thread).
Difference between a user thread and a daemon thread is, a Java program will not terminate if there is at least one user thread in execution. But, a Java program can terminate if there are one or more daemon threads in execution.
To work with daemon threads, Java provides two methods:
void setDaemon(boolean flag)
boolean isDaemon()
The setDaemon() method is used to convert a user thread into a daemon thread.The isDaemon() thread can be used to know whether a thread is a daemon thread or not.
Below program demonstrates a daemon thread:
classChildThreadimplementsRunnable{Thread t;ChildThread(String name){
t =newThread(this, name);
t.setDaemon(true);
t.start();}publicvoidrun(){try{while(true){System.out.println("This thread is a daemon thread: "+t.isDaemon());System.out.println(t.getName()+": Hi");Thread.sleep(1000);}}catch(InterruptedException e){System.out.println("Child thread is interrupted");}}}classDaemonThread{publicstaticvoidmain(String args[]){ChildThread one =newChildThread("Daemon Thread");}}
Java
Output of the above program is:
This thread is a daemon thread:trueDaemonThread:HiDaemonThread:HiDaemonThread:HiDaemonThread:Hi
…
Write a Java program to check if a given integer is “Positive” or “Negative”.
(0 (Zero) should be considered positive by this program.)
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question. Think of it like a programming puzzle.
(Remember to match the output given exactly, including the spaces and new lines)
(Passed with presentation error means you will get full marks)
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
4
Positive
Positive
Passed
Test Case 2
-3
Negative
Negative
Passed
Week 01 : Programming Assignment 2
Due on 2025-08-07, 23:59 IST
Write a Java program to calculate the volume of a cylinder given its radius and height.
Formula:
V=π∗r2∗h
You can use Math.PI for the computation.
NOTE:
The code you see is not complete.
Your task is to complete the code as per the question. Think of it like a programming puzzle.
(This question can be solved in just one line of code)
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
3.5
5.0
Volume is: 192.42
Volume is: 192.42
Passed
Week 01 : Programming Assignment 3
Due on 2025-08-07, 23:59 IST
Write a Java program to print the multiplication table of a given number up to 4.
NOTE:
Print EXACTLY as shown in the sample output.
DO NOT MISS a single space otherwise you will not be scored.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
5
5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20
5 x 1 = 5\n
5 x 2 = 10\n
5 x 3 = 15\n
5 x 4 = 20\n
Passed after ignoring Presentation Error
Week 01 : Programming Assignment 4
Due on 2025-08-07, 23:59 IST
Complete the code fragment that reads two integer inputs from keyboard and compute the quotient and remainder.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
556
9
The Quotient is = 61\n
The Remainder is = 7
The Quotient is = 61\n
The Remainder is = 7
Passed
Week 01 : Programming Assignment 5
Due on 2025-08-07, 23:59 IST
Write a Java program to print the area and perimeter of a rectangle.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
5.6 8.5
Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60
Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60
Passed
W02 Programming Assignments 1
Due on 2025-08-07, 23:59 IST
Write a Java program to calculate the area of a rectangle.
The formula for area is: Area = length × width
You are required to read the length and width from the user, compute the area, and print the result.
This task helps you practice using variables, arithmetic operations, and printing output in Java.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
5
10
Area is: 50
Area is: 50
Passed
W02 Programming Assignments 2
Due on 2025-08-07, 23:59 IST
Problem Statement
Write a Java program to calculate the perimeter of a rectangle.
The formula for perimeter is: Perimeter = 2 multiplied by (length + width)
You are required to read the length and width as integers from the user, compute the perimeter, and print the result.
This problem helps in practicing arithmetic operations and output printing in Java.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
4
6
Perimeter is: 20
Perimeter is: 20\n
Passed after ignoring Presentation Error
W02 Programming Assignments 3
Due on 2025-08-07, 23:59 IST
Finding the Maximum Element in an Array
Problem Statement
What is the Maximum Element? In an array of numbers, the maximum is the largest number among all elements.
In this assignment:
You will read n numbers from the user
Store them in an array
Find the largest number among them
Print the maximum number
This task helps you apply loops and arrays together to solve a real logic-based problem.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
5
15 42 9 28 37
Maximum is: 42
Maximum is: 42\n
Passed after ignoring Presentation Error
W02 Programming Assignments 4
Due on 2025-08-07, 23:59 IST
Create a Class and Access Its Member Variable
Problem Statement
In this task, you will practice creating and using a class in Java.
You need to:
Create a class called Rectangle
Declare two integer member variables length and width
In the main method, create an object of the Rectangle class, assign values to length and width, and print their sum
This problem helps you understand how to define a class, create objects, and access class members in Java.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
5
10
Sum of length and width is: 15
Sum of length and width is: 15\n
Passed after ignoring Presentation Error
W02 Programming Assignments 5
Due on 2025-08-07, 23:59 IST
Working with Multiple Classes, Constructors, and the this Keyword
Problem Statement
In this task, you will learn how to:
Declare multiple classes in the same Java program
Use constructors to initialize values
Apply the this keyword to refer to instance variables
What you need to do:
Declare a class called Circle with one member variable radius
Write a constructor for Circle that takes radius as a parameter and assigns it using the this keyword
In the main method, create an object of Circle and print its radius
This task helps understand how classes work together and how constructors and the this keyword are used for clarity.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
7
Radius of the circle is: 7
Radius of the circle is: 7\n
Passed after ignoring Presentation Error
W06 Programming Assignments 1
Due on 2025-09-04, 23:59 IST
Safe Division with Run-time Error Handling
Problem Statement
In Java, some operations can cause run-time errors, for example dividing a number by zero. We can use a try-catch block to handle such errors and avoid program crashes.
Task:
Read two integers from the user
Divide the first number by the second inside a try-catch block
If the second number is zero, print "Cannot divide by zero"
Otherwise, print the result
This task introduces basic run-time error handling in a safe and controlled way.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
10
0
Cannot divide by zero
Cannot divide by zero\n
Passed after ignoring Presentation Error
Test Case 2
10
2
Result is: 5
Result is: 5\n
Passed after ignoring Presentation Error
W06 Programming Assignments 2
Due on 2025-09-04, 23:59 IST
Programming Assignment: Nested try-catch Block
Problem Statement
In Java, nested try-catch blocks allow handling multiple levels of errors separately. You can place one try-catch block inside another to handle different types of errors in different places.
Programming Assignment:
Read two integers from the user
Inside an outer try-catch block, perform the following:
Inside a nested try block, divide the first number by the second
If division by zero occurs, handle it with the inner catch block
In the outer catch block, handle any other unexpected errors
Print appropriate messages for each scenario
This programming assignment introduces nested try-catch structure.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
10
2
Division successful\n
Result is: 5
Division successful\n
Result is: 5\n
Passed after ignoring Presentation Error
W06 Programming Assignments 3
Due on 2025-09-04, 23:59 IST
Programming Assignment: try Block with Multiple catch Blocks
Problem Statement
In Java, a try block can be followed by multiple catch blocks to handle different types of errors separately.
This improves error handling by allowing specific actions for different exceptions.
Key Concepts:
The first matching catch block handles the error
Catch blocks are written in order from most specific to general
Programming Assignment:
Read two integers from the user
Inside a try block, divide the first number by the second
Handle ArithmeticException separately to detect division by zero
Handle any other general errors using another catch block
Print suitable messages based on the type of error
This demonstrates structured error handling with multiple catch blocks.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
20
4
Division successful\n
Result is: 5
Division successful\n
Result is: 5\n
Passed after ignoring Presentation Error
W06 Programming Assignments 4
Due on 2025-09-04, 23:59 IST
Programming Assignment: Using finally in try-catch Block
Problem Statement
In Java, the finally block is a special part of error handling.
What is finally?
The code inside a finally block always runs, whether there is an error or not
It is usually used to close resources like files, database connections, or simply to show a message
Programming Assignment:
Read two integers from the user
Inside a try block, divide the first number by the second
If division by zero occurs, show an error message using catch block
Use a finally block to print "Program Ended" no matter what happens
This helps you understand how finally block always runs in a program.
Public Test Cases
Input
Expected Output
Actual Output
Status
Test Case 1
15
3
Result is: 5\n
Program Ended
Result is: 5\n
Program Ended\n
Passed after ignoring Presentation Error
W06 Programming Assignments 5
Due on 2025-09-04, 23:59 IST
Programming Assignment: Using throws Statement for Error Handling
Problem Statement
In Java, the throws keyword is used when a method might cause an error, but the method itself does not handle it. Instead, it passes the responsibility to the caller of the method.
Why use throws?
Some methods may cause errors called "checked exceptions"
Instead of handling the error inside the method, we declare throws to inform the caller
Programming Assignment:
Create a method called calculateSquareRoot
The method reads a number and returns its square root
If the number is negative, it throws an Exception
In the main method, use a try-catch block to handle the error
This demonstrates how to use throws and handle errors safely in the caller method.