NPTEL Programming In Java Assignment 6 Answers 2022

NPTEL Programming In Java Assignment 6 Answers 2022 (Week 6)

NPTEL Programming In Java Assignment 6 Answers 2022 :- Here All The Questions and Answers Provided to Help All The Students and NPTEL Candidate as a Reference Purpose, It is Mandetory to Submit Your Weekly Assignment By Your Own Understand Level.


Are you looking for the Assignment Answers to NPTEL Programming In Java Assignment 6 Answers 2022? If Yes You are in Our Great Place to Getting Your Solution, This Post Should be help you with the Assignment answer to the National Programme on Technology Enhanced Learning¬†(NPTEL) Course “NPTEL Programming In Java Week 6 Assignment Solution 2022


NPTEL Programming In Java

From My Side : With the expansion of knowledge and Communication Technology, there’s a desire to develop massive and complicated package. Further, those package ought to be platform freelance, web enabled, straightforward to switch, secure, and robust. to satisfy this demand object-oriented paradigm has been developed and supported this paradigm the Java artificial language emerges because the best programming atmosphere. Now, Java artificial language is being employed for mobile programming, web programming, and plenty of alternative applications compatible to distributed systems. This course aims to hide the essential topics of Java programming in order that the participants will improve their skills to address the present demand of IT industries and solve several issues in their own filed of studies.

With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.

INTENDED AUDIENCE :  The undergraduate students from the engineering disciplines namely CSE, IT, EE, ECE, etc. might be interested for this course.
PREREQUISITES :  This course requires that the students are familiar with programming language such as C/C++ and data structures, algorithms.
INDUSTRY SUPPORT :   All IT companies.


This course can have Associate in Nursing unproctored programming communication conjointly excluding the Proctored communication, please check announcement section for date and time. The programming communication can have a weightage of twenty fifth towards the ultimate score.

Final score = Assignment score + Unproctored programming exam score + Proctored Exam score
  • Assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
  • ( All assignments in a particular week will be counted towards final scoring – quizzes and programming assignments).¬†
  • Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam – out of 100
  • Proctored Exam score =50% of the proctored certification exam score out of 100
If any one of the 3 criteria is not met, you will not be eligible for the certificate even if the Final score >= 40/100. 


BELOW YOU CAN GET YOUR NPTEL Programming In Java Assignment 6 Answers 2022? :


NPTEL Programming In Java Assignment 6 Answers 2022

Q1. Complete the code segment to print the following using the concept of extending the Thread class in Java:


Thread is Running.


Solution Code : –¬†

public class Question61 extends Thread{
public void run(){
System.out.print(“Thread is Running.”);

public static void main(String args[]){

// Creating object of thread class
Question61 thread=new Question61();

// Start the thread

Q2. In the following program, a thread class Question62 is created using the Runnable interface Complete the main() to create a thread object of the class Question62 and run the thread. It should print the output as given below.


Welcome to Java Week 6 New Question.

Main Thread has ended.


Solution Code :-

public class Question62 implements Runnable {

public void run() {
System.out.print(Thread.currentThread().getName()+” has ended.”);

// Create main() method and appropriate statements in it
public static void main(String args[]){
System.out.println(“Welcome to Java Week 6 New Question.”);
Question62 t=new Question62();
Thread tr = new Thread(t);
tr.setName(“Main Thread”);


Q3. ¬†A part of the Java program is given, which can be completed in many ways, for example¬†using the concept of thread, etc.¬† Follow the given code and complete the program so that your program prints the message “NPTEL Java week-6 new Assignment Q3“. Your program should utilize the given interface/ class.

Invalid HTML tag: tag name o:p is not allowed

Solution Code :-

// Interface A is defined with an abstract method run()
interface A {
public abstract void run();

// Class B is defined which implements A and an empty implementation of run()
class B implements A {
public void run() {}

// Create a class named MyThread and extend/implement the required class/interface

// Define a method in MyThread class to print the output
class MyThread extends B {
// run() is overriden and ‘NPTEL Java’ is printed.
public void run() {
System.out.print(“NPTEL Java week-6 new Assignment Q3”);

// Main class Question is defined
public class Question63 {
public static void main(String[] args) {
// An object of MyThread class is created
MyThread t = new MyThread();
// run() of class MyThread is called;

Q4. Execution of two or more threads occurs in a random order. The keyword ‘synchronized’ in Java is used to control the execution of thread in a strict sequence. In the following, the program is expected to print the output as given below. Do the necessary use of ‘synchronized’ keyword, so that, the program prints the Final sum as given below:¬†¬†

Final sum:6000


Solution Code :-

A simple class that demonstrates using the ‘synchronized’
keyword so that multiple threads may send it messages.
The class stores two ints, a and b; sum() returns
their sum, and inc() increments both numbers.
The sum() and incr() methods form a “critical section” —
they can compute the wrong thing if run by multiple threads
at the same time. The sum() and inc() methods are declared
“synchronized” — they respect the lock in the receiver object.
class Pair {
private int a, b;
public Pair() {
a = 0;
b = 0;

// Returns the sum of a and b. (reader)
// Should always return an even number.
public int sum() {

// Increments both a and b. (writer)
synchronized public void inc() {

A simple worker subclass of Thread.
In its run(), sends 1000 inc() messages
to its Pair object.
(1000 may not be big enough to exhibit the bug on uniprocessor —
hardware more like 1000000 may be required).
public class PairWorker extends Thread {
public final int COUNT = 1000;
private Pair pair;
// Ctor takes a pointer to the pair we use
public PairWorker(Pair pair) {
this.pair = pair;
// Send many inc() messages to our pair
public void run() {
for (int i=0; i<COUNT; i++) {;

Test main — Create a Pair and 3 workers.
Start the 3 workers — they do their run() —
and wait for the workers to finish.
public static void main(String args[]) {
Pair pair = new Pair();
PairWorker w1 = new PairWorker(pair);
PairWorker w2 = new PairWorker(pair);
PairWorker w3 = new PairWorker(pair);
// the 3 workers are running
// all sending messages to the same object
// we block until the workers complete
try {
catch (InterruptedException ignored) {}

System.out.println(“Final sum:” + pair.sum()); // should be 6000
If sum()/inc() were not synchronized, the result would
be 6000 in some cases, and other times random values
like 5979 due to the writer/writer conflicts of multiple
threads trying to execute inc() on an object at the same time.

Q5. Given a snippet of code, add necessary codes to print the following:


Name of thread ‘t1’:Thread-0

Name of thread ‘t2’:Thread-1

New name of thread ‘t1’:Week 6 Assignment Q5

New name of thread ‘t2’:Week 6 Assignment Q5 New


Solution Code :-

public class Question65 extends Thread{
public void run(){

public static void main(String args[]){
Question65 t1=new Question65();
System.out.println(“Name of thread ‘t1’:”+ t1.getName());

Question65 t2=new Question65();
System.out.println(“Name of thread ‘t2’:”+ t2.getName());

// Write the necessary code below…
t1.setName(“Week 6 Assignment Q5”);
t2.setName(“Week 6 Assignment Q5 New”);
System.out.println(“New name of thread ‘t1’:”+ t1.getName());
System.out.println(“New name of thread ‘t2’:”+ t2.getName());


Related Posts

Leave a Reply

Your email address will not be published.