{"id":20821344,"url":"https://github.com/prakharjadaun/java-lab-work","last_synced_at":"2025-12-27T04:08:47.985Z","repository":{"id":123404239,"uuid":"456571201","full_name":"prakharjadaun/Java-Lab-Work","owner":"prakharjadaun","description":"Contains all the experiments that I have performed in the Java Lab","archived":false,"fork":false,"pushed_at":"2022-02-07T16:00:13.000Z","size":70,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T06:28:20.396Z","etag":null,"topics":["exceptions-handling","inheritance","java","jdbc","servlets","threading"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prakharjadaun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-07T15:48:24.000Z","updated_at":"2022-10-07T02:48:01.000Z","dependencies_parsed_at":"2024-08-13T23:15:16.539Z","dependency_job_id":null,"html_url":"https://github.com/prakharjadaun/Java-Lab-Work","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/prakharjadaun/Java-Lab-Work","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prakharjadaun%2FJava-Lab-Work","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prakharjadaun%2FJava-Lab-Work/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prakharjadaun%2FJava-Lab-Work/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prakharjadaun%2FJava-Lab-Work/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prakharjadaun","download_url":"https://codeload.github.com/prakharjadaun/Java-Lab-Work/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prakharjadaun%2FJava-Lab-Work/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28071776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exceptions-handling","inheritance","java","jdbc","servlets","threading"],"created_at":"2024-11-17T22:11:59.991Z","updated_at":"2025-12-27T04:08:47.958Z","avatar_url":"https://github.com/prakharjadaun.png","language":"Java","readme":"# **Java Lab Work - UPES**\n\nThis respository contains all the assignments that I have performed in my Java lab. \n\n## **Experiment 1 : Basics of Java**\n\n1.\tWrite program to print the kth digit from last. e.g. input 23617 and k=4 output 3.\n2.\tWrite a program to print first digit. e.g. input 23516 output 2.\n3.\tWrite program to print the second digit. e.g. input 23516 the output is 3.\n4.\tWrite program to find sum of all digits. Input 23617 output 2+3+6+1+7=19.\n5.\tWrite program, which will find sum of product to consecutive digits. e.g. when the input is 23145 the output is 2x3 + 3x1 + 1x4 + 4x5 = 33.\n6.\tWrite program, which reads two number (assume that both have same number of digits). The program outputs the sum of product of corresponding digits. Input 327 and 539 output 3x5+2x3+7x9=84. \n7.\tWrite program to print positional values of digits. Input 21463 output 3, 60, 400, 1000 and 20000.\n8.\tModify first example for taking input through command line arguments.\n9.\tModify second example for taking input through command line arguments.\n10.\tDefine fa. If point p is (x,y) then p.fa() will make it (x+y,2y). (20,4) (24,8)\n11.\tDefine fb. If point p is (x,y) then p.fb() will make it (2x,x+y). (20,4) (40,24)Define fc. If point p is (x,y) then p.fc() will make it (x+y,x*y). (20,4) (24,80)\n\n## **Experiment 2 : Basics of Java Programming**\n\n1. Write a program to find the largest of 3 numbers.\n2. Write a program to implement a command line calculator. (Try for Add sub Mul Division in same program for 2 digits.)\nInteger.parseInt will be used\u003cbr\u003e\nFor e.g. java calc 20 + 30\u003cbr\u003e\nOutput should be Sum of 20 and 30 is 50\njava calc 50 * 30\u003cbr\u003e\nOutput should be Product of 50 and 30 is 1500\n3. Write a program to accept 10 student's mark in an array, arrange it into ascending order, convert it into the following grades and print marks and grades in the tabular form.\u003cbr\u003e\nBetween 40 and 50 : PASS\u003cbr\u003e\nBetween 51 and 75 : MERIT\u003cbr\u003e\nand above : DISTINCTION\u003cbr\u003e\nfor example:\u003cbr\u003e\nEnter Marks: 50\u003cbr\u003e\n30\u003cbr\u003e\n50\u003cbr\u003e\n50\u003cbr\u003e\n30\u003cbr\u003e\n50\u003cbr\u003e\nOutput should be sorted array with Grade like:\u003cbr\u003e\n55 Merit\u003cbr\u003e\n41 Pass\u003cbr\u003e\n29 Fail\u003cbr\u003e\n4. WAP to Take input as DD MM YYYY(04 08 2021) in command line and calculate number of days since 1 January 1970.\n\n## **Experiment 3 :**\n\n1. Write a program to accept three digits (i.e., 0 - 9) and print all its possible combinations.\u003cbr\u003e\n(For example if the three digits are 1, 2, 3 than all possible combinations are : 123, 132, \n213, 231, 312, 321.)\n2. Write a Java Program to accept 10 numbers in an array and compute the square of each number. Print the sum of these numbers.\n3. Write a program to input a number of a month (1 - 12) and print its equivalent name of \nthe month. ( e.g 1 to Jan, 2 to Feb. 12 to Dec.)\n4. Write a program to find the sum of all integers greater than 40 and less than 250 that are divisible by 5.\n\n## **Experiment 4 : Inheritance**\n\n1. Write a Java program to show that private member of a super class cannot be accessed from derived classes. \n2. Write a program in Java to create a Player class. Inherit the classes Cricket _Player, Football _Player and Hockey_ Player from Player\nclass. \n3. Write a class Worker and derive classes DailyWorker and SalariedWorker from it. Every worker has a name and a salary rate. Write \nmethod ComPay (int hours) to compute the week pay of every worker. A Daily Worker is paid on the basis of the number of days \nhe/she works. The Salaried Worker gets paid the wage for 40 hours a week no matter what the actual hours are. Test this program to \ncalculate the pay of workers. You are expected to use the concept of polymorphism to write this program.\n4. Consider the trunk calls of a telephone exchange. A trunk call can be ordinary, urgent or lightning. The charges depend on the duration \nand the type of the call. Write a program using the concept of polymorphism in Java to calculate the charges.\n5. Design a class employee of an organization. An employee has a name, empid, and salary. Write the default constructor, a constructor \nwith parameters (name, empid, and salary) and methods to return name and salary. Also write a method increaseSalary that raises the \nemployee’s salary by a certain user specified percentage. Derive a subclass Manager from employee. Add an instance variable named \ndepartment to the manager class. Supply a test program that uses theses classes and methods\n\n## **Experiment 5 : Interface**\n\n1. Write a program to create interface named test. In this interface the member function is square. Implement this interface in arithmetic \nclass. Create one new class called ToTestInt. In this class use the object of arithmetic class.\n2. Write a program to create interface A, in this interface we have two method meth1 and meth2. Implements this interface in another \nclass named MyClass.\n3. Write a program in Java to show the usefulness of Interfaces as a place to keep constant value of the program\n4. Write a program to create an Interface having two methods division and modules. Create a class, which overrides these methods.\n5. Write program to create an interface StackInterface having methods push (), pop () and display (). StackClass implements \nStackInterface. Class StackClass contains the main method which is having a switch case for selecting the particular operation of the \nstack\n\n## **Experiment 6 : Packages**\n\n1. Write a Java program to implement the concept of importing classes from user defined package and created packages.\n2. Write a program to make a package Balance. This has an Account class with Display_Balance method. Import Balance package in \nanother program to access Display_Balance method of Account class. \n3. WAP to create a package p with class A with 4 types of access protected methods. How we will use these methods in different packages \nclass i.e. there is main() in class B in package Q and 4 methods are in Class A in package p.\n\n## **Experiment 7 : Exceptions**\n\n1. Write a program in Java to display the names and roll numbers of students. Initialize respective array variables for 10 students. Handle \nArrayIndexOutOfBoundsExeption, so that any such problem doesn’t cause illegal termination of program. \n2. Create an exception class, which throws an exception if operand is nonnumeric in calculating modules. (Use command line arguments). \n3. Write a code to create your own exception class. Create another class, inside main method prompt user to enter a number if number is \nless than 500 throw instances of your custom exception class.\n4. You are given two integers, a and b as input, you have to compute a/b: If a and b are not bit signed integers or if is zero, exception \nwill occur and you have to report it. Read sample Input/Output to know what to report in case of exception. \u003cbr\u003e\nSample Input 0:\u003cbr\u003e\n10\u003cbr\u003e\n3\u003cbr\u003e\nSample Output 0: \u003cbr\u003e\n3\u003cbr\u003e\nSample Input 1:\u003cbr\u003e\n10\u003cbr\u003e\nHello\u003cbr\u003e\nSample Output 1 :\u003cbr\u003e\njava.util.InputMismatchException\u003cbr\u003e\nSample Input 2:\u003cbr\u003e\n10\u003cbr\u003e\n0\u003cbr\u003e\nSample Output 2:\u003cbr\u003e\njava.lang.ArithmeticException: / by zero\u003cbr\u003e\nSample Input 3:\u003cbr\u003e\n23.323\u003cbr\u003e\n0\u003cbr\u003e\nSample Output 3:\u003cbr\u003e\njava.util.InputMismatchException\u003cbr\u003e\n\n5. You are required to compute the power of a number by implementing a calculator. Create a class Calc which consists of a single \nmethod long power(int, int). This method takes two integers, a and b, as parameters and finds a\nb\n. If either a or b is negative, then \nthe method must throw an exception which says \"a and b should not be negative\". Also, if both a and b are zero, then the method \nmust throw an exception which says \"a and b should not be zero\"\u003cbr\u003e\nFor example, -4 and -5 would result in java.lang.Exception: a and b should not be negative.\u003cbr\u003e\nComplete the function power in class Calc and return the appropriate result after the power operation or an appropriate exception as \ndetailed above.\u003cbr\u003e\n\u003cb\u003eInput Format\u003c/b\u003e\u003cbr\u003e\nEach line of the input contains two integers, a and b. The code must read the input and send the values to the method as \nparameters.\u003cbr\u003e\nConstraints\u003cbr\u003e\n* -10 \u003c= a\u003c= 10\u003cbr\u003e\n* -10 \u003c= b\u003c= 10\u003cbr\u003e\n\n\u003cb\u003eOutput Format\u003c/b\u003e\u003cbr\u003e\nEach line of the output contains the result, if both a and b are positive. If either a or b is negative, the output contains \"a and b\nshould be non-negative\". If both a and b are zero, the output contains \"a and b should not be zero.\"\u003cbr\u003e\n\u003cb\u003eSample Input 0 :\u003c/b\u003e\u003cbr\u003e\n3 5\u003cbr\u003e\n2 4\u003cbr\u003e\n0 0\u003cbr\u003e\n-1 -2\u003cbr\u003e\n-1 3\u003cbr\u003e\n\u003cb\u003eSample Output 0 :\u003c/b\u003e\u003cbr\u003e\n243\u003cbr\u003e\n16\u003cbr\u003e\njava.lang.Exception: n and p should not be zero.\u003cbr\u003e\njava.lang.Exception: n or p should not be negative.\u003cbr\u003e\njava.lang.Exception: n or p should not be negative\u003cbr\u003e\n\n## **Experiment 8 : String Handling and Exceptions**\n\n1. Write a program for searching strings for the first occurrence of a character or substring and for the last occurrence of a character or \nsubstring. \n2. Write a program that converts all characters of a string in capital letters. (Use StringBuffer to store a string). Don’t use inbuilt function. \n3. Write a program in Java to read a statement from console, convert it into upper case and again print on console. (Don’t use inbuilt \nfunction) \n4. Write a program in Java to create a String object. Initialize this object with your name. Find the length of your name using the \nappropriate String method. Find whether the character ‘a’ is in your name or not; if yes find the number of times ‘a’ appears in your \nname. Print locations of occurrences of ‘a’ .Try the same for different String objects\n\n5. Write a Java code that converts int to Integer, converts Integer to String, converts String to int, converts int to String, converts String \nto Integer converts Integer to int.\n6. Write a Java code that converts float to Float converts Float to String converts String to float converts float to String converts String \nto Float converts Float to float. \n\n## **Experiment 9 : Threads**\n\n1. Write a program to implement the concept of threading by extending Thread Class and Runnable interface.\n2. Write a program for generating 2 threads, one for printing even numbers and the other for printing odd numbers.\n3. Write a program to launch 10 threads. Each thread increments a counter variable. Run the program with synchronization. \n4. Write a Java program to create five threads with different priorities. Send two threads of the highest priority to sleep state. Check the \naliveness of the threads and mark which thread is long lasting\n\n## **Experiment 10 : Collections**\n\n1. Write a program for the following\u003cbr\u003e\n* Read all elements from ArrayList by using Iterator.\n* Create duplicate object of an ArrayList instance.\n* Reverse ArrayList content.\n2. Write a program for the following HashMap\n* find whether specified key exists or not.\n* find whether specified value exists or not\n* get all keys from the given HashMap\n* get all key-value pair as Entry objects\n3. Write a program for the following HashSet\n* copy another collection object to HashSet object.\n* delete all entries at one call from HashSet\n* search user defined objects from HashSet\u003cbr\u003e\n\n## **Experiment 11 : JDBC**\n\n1. Create a database table to store the records of employee in a company. Use getConnection function to connect the database. The \nstatement object uses executeUpdate function to create a table.\n2. Create a database of employee of company in mysql and then use java program to access the database for inserting information of \nemployees in database. The SQL statement can be used to view the details of the data of employees in the database.\n3. Create a table Meeting having columns (NameOfParticipant, MeetingID, ScheduledTime, Email, Mobile), Populate with random data \nand perform following operations. READ COMPLETE QUESTION TO POPULATE DATABASE.\u003cbr\u003e\na) Using JaveCode determine the names of the columns in the MEETING table and display the column names on the console.\u003cbr\u003e\nb) Write a query to find the names of all participants for the meeting with ID 1144. Display the names on the console, preceded by \nthe message, “Names of participants in meeting 1144”.\u003cbr\u003e\nc) Insert a new participant with using only the participant’s name. Don’t specify the participant ID - let the ID be determined by the \ndatabase. Determine the ID that was assigned to the new participant and display it on the console (the statement that displays the \nID should display the name of the new participant as well).\u003cbr\u003e\nd) Count the number of people participating in the meeting with ID 1105. Display a message on the console that gives both the \nmeeting name and the number of participants.\u003cbr\u003e\ne) Determine the names of all people who participate in meetings that meet on Tuesdays. Display the names, preceded by the \nmessage, “Participants attending Tuesday meetings”.\u003cbr\u003e\n\n## **Experiment 12 : Servlet**\n\n1. Servlet : \u003cbr\u003ea) ServletContext interface\u003cbr\u003e b) getParameterValues() of Servlet Request\u003cbr\u003e\n2) Write a Servlet page to display current date of the server.\u003cbr\u003e\n3) Write a Servlet page to which include the two other Servlet page through of include directives feature provided in Servlet.\n4) Write a Servlet page to create a simple calculator.\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprakharjadaun%2Fjava-lab-work","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprakharjadaun%2Fjava-lab-work","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprakharjadaun%2Fjava-lab-work/lists"}