NPTEL Programming In Java Assignment 6 Answers 2022

NPTEL Programming In Java Assignment 6 Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge

What is Programming In Java?

With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, that 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, the Java programming language is being used for mobile programming, Internet programming, and many other applications compatible with 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 field of studies.

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of the 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 THE 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.

Below you can find the answers for NPTEL Programming In Java Assignment 6

NPTEL Programming In Java Assignment 6 Answers July 2022

1. Which of the following is NOTa method of the Thread class in Java?

a. public void run()
b. public void exit()
c. public void start()
d. public final int getPriority0

Answer:- b

2. Which of the following statement is true in case of starting a thread with “run)” and *start0′ method?

a. There is no difference between starting a thread with ‘run()’ and ‘start()’ method.
b. When you call start() method. main thread intenally calls run() method to start newly Created Thread
c. When you call run() method directly no new Thread is created and code inside run() will execute on curent Thread.
d. None

Answer:- b

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

NPTEL Programming In Java Assignment 6 Answers 2022

3. Which of the following can be used to create an instance of Thread?

a. By implementing the Runnable interface.
b. By extending the Thread class.
c. By creating a new class named Thread and calling method run().
d. By importing the Thread class from package.

Answer:- a, b

4.

NPTEL Programming In Java Assignment 6 Answers 2022
Answer:- d

5. Which method restarts a dead thread

a. start()
b. restart()
c. restart Thread)
d. none

Answer:- d

6. Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU?

a) After thread A is notified, or after two seconds
b) Two seconds after thread A is notified.
c) After the lock on B is released, or after two seconds.
d) Two seconds after lock B is released.

Answer:- a

👇For Week 07 Assignment Answers👇

NPTEL Programming In Java Assignment 6 Answers 2022

7.

NPTEL Programming In Java Assignment 6 Answers 2022
Answer:- d

8.

NPTEL Programming In Java Assignment 6 Answers 2022
Answer:- d

9. Which of the following is/are not a correct constructor for a thread object?

a. Thread(Runnable a, String str):
b Thread(Runnable a, int priority):
c. Thread(Runnable a, ThreadGroup t):
d. Thread(int priority):

Answer:- b, c, d

10. Which eXception is thrown when an array element is accessed beyond the array size?

a. ArayElementOut OfBounds
b. Arraylndex OutOiBounds Exception
c. AmaylndexOutOfBounds
d. None of these

Answer:- b

For More NPTEL Answers:- CLICK HERE

Join Our Telegram:- CLICK HERE

NPTEL Programming In Java Assignment 6 Answers 2022 {Jan – June}

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

Code:-

MCQ Assignment Week 6 Answer:- CLICK HERE

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

👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇

NPTEL Programming In Java Assignment 6 Answers 2022

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.

Code:-

// Create main() method and appropriate statements in it
public static void main(String[] args) {  
        Question62 ex = new Question62();  
        Thread t1= new Thread(ex);  
        t1.setName("Main Thread");
        t1.start();  
        System.out.println("Welcome to Java Week 6 New Question.");  
        t1.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.

Code:-

// Class MyThread is defined which extends class B
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");
	}
}

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:  

Code:-

// Returns the sum of a and b. (reader)
// Should always return an even number.
synchronized public int sum() { // line 1 :- answer
return(a+b);
}
// Increments both a and b. (writer)
synchronized public void inc() { //line 2 :- answer
a++;
b++;
}
}

Q5. Add necessary codes to print the following:

—————–OUTPUT——————-

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

Code:-

t1.setName("Week 6 Assignment Q5"); 
t2.setName("Week 6 Assignment Q5 New");

👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇

NPTEL Programming In Java Assignment 6 Answers 2022

Disclaimer:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.

For More NPTEL Answers:- CLICK HERE

Join Our Telegram:- CLICK HERE

Programming In Java Assignment 6 Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge

If you found this article Interesting and helpful, don’t forget to share it with your friends to get this information.

Leave a Comment