Navigation Menu
Search code, repositories, users, issues, pull requests..., provide feedback.
We read every piece of feedback, and take your input very seriously.
Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
- Notifications You must be signed in to change notification settings
Welcome to the NPTEL "Programming in Java" course repository! This repository hosts a comprehensive collection of programming assignments, quizzes, and test solutions for the NPTEL "Programming in Java" course offered in the years 2024, 2022, and 2020.
iamrudhresh/NPTEL-JAVA-PROGRAMMING
Folders and files, repository files navigation, nptel "programming in java" course repository, course overview.
This repository contains a wealth of resources designed to supplement your learning journey in Java programming. Whether you're a beginner seeking to grasp the fundamentals or an experienced developer looking to enhance your skills, you'll find a variety of materials tailored to your needs.
Programming Assignments : Dive into hands-on coding exercises that reinforce key concepts covered in the course. Each assignment presents unique challenges to sharpen your Java programming skills.
Quizzes : Test your understanding of Java programming with quizzes designed to assess your knowledge and comprehension of course topics. Challenge yourself and track your progress as you advance through the course.
Test Solutions : Access solutions to course tests to compare your answers, gain insights into problem-solving strategies, and reinforce your learning. These solutions serve as valuable resources for self-assessment and improvement.
Course Years
2024 : Access the latest course materials and stay updated with the most recent advancements in Java programming.
2022 : Explore course content from previous years to review foundational concepts and deepen your understanding of Java programming principles.
2020 : Access historical course materials to compare and contrast with more recent content, gaining valuable insights into the evolution of Java programming practices over time.
How to Use This Repository
Explore : Browse through folders corresponding to each course year to access assignments, quizzes, and test solutions.
Practice : Engage with programming assignments to hone your coding skills and reinforce theoretical knowledge.
Assess : Test your understanding by attempting quizzes and comparing your answers with provided solutions.
Learn : Analyze test solutions to gain insights into effective problem-solving techniques and improve your proficiency in Java programming.
Get Started
To begin your journey in Java programming with NPTEL, dive into the folders and start exploring the wealth of resources available at your fingertips!
- Java 100.0%
NPTEL Programming in Java Week 1 Assignment Solution 2023
NPTEL Programming in Java Week 1 Assignment Solution – Hello everyone, in this blog, we will provide you the solution for assignment one of Programming in Java. We will try our best to provide you all the correct answers, but you confirm this answer according to your own and submit the assignment.
NPTEL Programming in Java Week 1 : Assignment 1 Answers
1) what is the incorrect statergent about bytecode a. java when compiles the source code, it converts it to bytecode..
- a. Java when compiles the source code, it converts it to bytecode.
- b. JVM (Java Virtual Machine) is an interpreter of bytecode.
- c. Bytecode is not portable and it needs to be compiled separately for each platform.
- d. JVM offers a protected environment which helps in enhanced safety for the system.
Answer:- c. Bytecode is not portable and it needs to be compiled separately for each platform.
Explanation – Bytecode is a compiled code that is executed by an interpreter. Java source code is compiled into bytecode, which is executed by the Java Virtual Machine (JVM). Because the JVM is available on many different platforms, the bytecode can be executed on any platform that has a JVM. The JVM acts as an interpreter, translating the bytecode into machine code that can be executed by the computer’s processor. This makes bytecode portable, meaning it can run on any platform that has a JVM. And also JVM offers a protected environment which helps in enhanced safety for the system.
2) Consider the Following Program, What is the Output of the above code ?
- b. Compiler error due to line n1
- c. Compiler error due to line n2
- d. Print nothing
Answer:- b. Compiler error due to line n1
Explanation – The code will give an error in line n1 because the variable ‘b’ is defined as a string but it is being used in a switch statement which expects a constant expression. The switch statement is executed based on the value of the constant expression, but in this case, the value of ‘b’ is a string which is not a constant expression. Also, in the switch statement, there is no default case and no case that matches the string “false” , so the program will not print anything. So the answer is compiler error due to line n1.
3) Which one of the following is not a primitive datatype?
Answer:- c. class
Explanation – In Java, primitive data types are the basic data types that are built into the Java programming language. They include byte, short, int, long, float, double, boolean, and char. These data types are used to store numeric, boolean, and character values.A class, on the other hand, is a template or blueprint for creating objects. It is a user-defined data type, which is used to create objects of that class. Classes contain methods, fields, and constructors, which are used to define the properties and behavior of an object.So, “class” is not a primitive datatype in Java.
4) Which of the following is not a keyword in java?
Answer:- c. integer
Explanation – In Java, keywords are predefined, reserved words that have special meanings in the programming language. They cannot be used as identifiers (variable names, method names, etc.) in a program.”final”, “super” and “extend” are all keywords in Java.”final” is used to indicate that a variable, method, or class cannot be overridden or subclassed.”super” is used to refer to the parent class of a subclass.”extend” is used to indicate that a class is a subclass of another class.”integer” is not a keyword in Java, it is used to refer to a data type that stores a numerical value. The correct name for this data type in Java is “int”.So, “integer” is not a keyword in java.
5) Consider the Following Program, What will be the Output of the Program if it is executed?
- a. 15-even-1
- b. 15-odd-1
- c. 15-even-
Answer:- b. 15-odd-1
Explanation – In this code, the value of ‘a’ is first set to 5 and then 6 is added to it making it 11. Then, in the switch statement, the value of (a-1) is 10, so it goes to the case 10 statement.The case 10 block is executed and first, it prints “15”. Then it checks the value of (a-12) which is -1 and since it is not equal to zero, it prints “-odd-” . So the output is “15-odd-“Finally, it goes to the default block and it prints (a2), which is 121. So the final output is “15-odd-1”.So the answer is “b. 15-odd-1”.
Q6) Why does the error “javac is not recognized as an internal or external command” occur?
- a. Path is not set for javab. JDK is not correctly installed c. .class file is not foundd. javac jar is missing from java library
Answer:- a. Path is not set for java
Explanation – The error “javac is not recognized as an internal or external command” occurs when the system cannot find the javac executable. This can happen if the path to the JDK (Java Development Kit) bin directory, where the javac executable is located, is not set in the system’s environment variables.To fix this error, you need to set the path to the JDK bin directory in the system’s environment variables. This will allow the system to find the javac executable and execute it properly.Other reasons like JDK is not correctly installed, .class file is not found, and javac jar is missing from java library can also cause the same error, but they are less likely to happen, as they are related to the installation of JDK and not the environment variable.
7) Following is a piece of code where some parts of a statement is missing: In the following, some options are given. You have to choose the correct option(s) for the argument in System.out.print() function to print the value 102.
- a. nptel[nptel.length-2]+ nptel[0]
- b. nptel[0] + nptel[nptel.length-2]
- C. “” + nptel[nptel.length-2]+nptel[0]
- d. “” + nptel[0] + nptel[nptel.length-2]
answer:- a. nptel[nptel.length-2]+ nptel[0]
Explanation – In this code, an array named “nptel” is created, which holds the characters ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’ in the respective indexes 0 to 5. To print the value 102, we need to concatenate the elements at the second last index and the first index. The second last index of the array is 5-2=3, and the first index is 0. So we need to concatenate the elements at index 3 and 0.In option (a) “nptel[nptel.length-2]+nptel[0]” is used, which is the correct way to concatenate the elements at index 3 and 0.
8) Which of the following concept that Java doesn’t support?
- a. inheritance
- b. serialization
Answer:- c. goto
Explanation – Java does not support the “goto” statement, which is a control statement that allows jumping from one point in a program to another point. Java uses control statements like if, for, while, and switch-case for flow control, instead of the goto statement.So the correct answer is c. goto
9) The subsystem of JVM that is used to load class files is known as _______.
- a. Classloader
- d. Compiler
Answer:- a. Classloader
Explanation – The classloader is a subsystem of the JVM (Java Virtual Machine) that is responsible for loading class files into the JVM. The classloader reads the bytecode of the class file and converts it into instructions that can be executed by the JVM. It is responsible for loading the class files required for the execution of a program. So the correct answer is a. Classloader
10) What is the value of total after executing the following code snippet?
Answer – b. 5
Explanation – In this code snippet, the value of “mark” is 5. So the condition inside the ternary operator (mark>6) is false. Therefore, the code inside the “:” (colon) will be executed. It decrements the value of “grace” by 1 and the new value of grace is 1. Then the value of “mark” which is 5 is added to the new value of grace which is 1.So the final value of “total” is 5 + 1 = 6So the correct answer is b. 5
CRITERIA TO GET A CERTIFICATE in NPTEL Course Programming in Java
Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course. Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.
NOTE: Please note that there will not be an unproctored programming exam for this course this term
NPTEL Programming in Java Week 1 Programming Assignment 1 Solution
Q1) complete the code segment to help ragav , find the highest mark and average mark secured by him in “s” number of subjects., q2) consider first n even numbers starting from zero(0).complete the code segment to calculate sum of all the numbers divisible by 3 from 0 to n. print the sum..
Explanation of above Program – In this code, a for loop is used to iterate through the first n even numbers starting from 0. The loop starts with the variable i set to 0, and increments by 2 each time to only check even numbers. Within the loop, an if statement checks if the current number (i) is divisible by 3. If it is, the number is added to the variable sum and printed out. Once the loop has finished, the sum of all the numbers divisible by 3 is printed out.
Q3) Complete the code segment to find the perimeter and area of a circle given a value of radius . You should use Math.PI constant in your program. If radius is zero or less than zero then print ” please enter non zero positive number “.
Explanation of above program – In this code, the value of radius is first taken as input from the user using the Scanner class. Then, an if statement is used to check if the radius is less than or equal to 0. If the radius is less than or equal to 0, the program prints “Please enter a non-zero positive number.” If the radius is greater than 0, the perimeter and area of the circle are calculated using the given formula and the Math.PI constant. The perimeter is calculated as 2 * pi * radius and the area is calculated as pi * radius^2. The perimeter and area are then printed out.
Q4) Complete the code segment to check whether the number is an Armstrong number or not.
Explanation of above program – In this code, the value of n is first taken as input from the user using the Scanner class. Then, a while loop is used to check if the number is an Armstrong number. The loop starts with the variable temp set to n and decrements by one digit each time. Within the loop, the last digit of the number is extracted and raised to the power of the number of digits in the number. This value is added to the sum variable. Once the loop has finished, an if-else statement checks if the sum is equal to the original number. If it is, the result variable is set to 1, otherwise it is set to 0. The result is then printed out.
Q5) Complete the code segment to find the largest among three numbers x,y, and z. You should use if-then-else construct in Java.
Explanation of above program – In this code, the values of x, y, and z are first taken as input from the user using the Scanner class. Then, an if-else ladder is used to find the largest number among x, y, and z. The first if statement checks if x is greater than y and z. If it is, the variable result is set to x. If not, the second if statement checks if y is greater than x and z. If it is, the variable result is set to y. If neither x nor y are the largest, the else statement sets the variable result to z. The largest number is then printed out.
Disclaimer – We recommend you to complete your project independently because we do not guarantee the accuracy of our solutions. Instead, these answers are based only on our area of expertise, and we are only presenting them to serve as a resource for students.
Leave a Comment Cancel reply
Save my name, email, and website in this browser for the next time I comment.
IMAGES
VIDEO