What is Programming in Java?
Java is a popular object-oriented programming language that was first released in 1995. It is used for developing a wide range of applications, including desktop applications, mobile applications, web applications, and enterprise applications.
Here are some key features and concepts of Java programming:
Object-oriented programming: Java is an object-oriented language, which means that it focuses on the creation of objects that contain both data and methods that operate on that data.
Platform independence: Java programs can run on any platform that supports a Java Virtual Machine (JVM), which makes it a popular choice for cross-platform development.
Memory management: Java uses automatic memory management through a garbage collector, which helps to prevent memory leaks and makes it easier to write memory-safe code.
Exception handling: Java has a built-in mechanism for handling runtime errors or exceptions, which helps to ensure that programs can recover gracefully from unexpected errors.
Multi-threading: Java supports multi-threading, which allows programs to execute multiple threads of execution simultaneously, making it well-suited for developing concurrent applications.
Standard libraries: Java provides a large number of standard libraries that developers can use to build applications more quickly and easily, including libraries for networking, database access, and user interface development.
To get started with Java programming, you will need to install the Java Development Kit (JDK) on your computer. Once you have installed the JDK, you can use an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA to write and debug your code.
To learn Java programming, you can start with the basics of the language, such as data types, control structures, and object-oriented programming concepts. There are many online resources and tutorials available for learning Java, including Oracle's official Java tutorials, which cover everything from the basics to advanced topics like concurrency and networking.
Week 6 : Programming Assignment 1
Complete the code segment to print the following using the concept of extending the Thread class in Java:
-----------------OUTPUT-------------------
Thread is Running.
-------------------------------------------------
Solution :
public class Question61 extends Thread{ public void run(){ System.out.print("Thread is Running."); } |
Week 6 : Programming Assignment 2
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.
-----------------OUTPUT-------------------
Welcome to Java Week 6 New Question.
Main Thread has ended.
-------------------------------------------------
Solution :
// Create main() method and appropriate statements in it
public static void main(String[] args) {
Question62 obj = new Question62();
Thread t1 = new Thread(obj);
t1.setName("Main Thread");
t1.start();
System.out.println("Welcome to Java Week 6 New Question.");
t1.setName("Main Thread");
} |
Week 6 : Programming Assignment 3
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.
Solution :
// 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");
}
} |
Week 6 : Programming Assignment 4
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:
-----------------OUTPUT-------------------
Final sum:6000
-------------------------------------------------
Solution :
// Returns the sum of a and b. (reader)
// Should always return an even number.
public synchronized int sum() {
return(a+b);
}
// Increments both a and b. (writer)
public synchronized void inc() {
a++;
b++;
}
} |
Week 6 : Programming Assignment 5
Given a snippet of code, 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
-------------------------------------------------
Solution :
// Write the necessary code below...
t1.setName("Week 6 Assignment Q5");
t2.setName("Week 6 Assignment Q5 New"); |
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 THE 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.
| Programming in JAVA | Answers |
| Assignment 1 | Click Here |
| Assignment 2 | Click Here |
| Assignment 3 | Click Here |
| Assignment 4 | Click Here |
| Assignment 5 | Click Here |
| Assignment 6 | Click Here |
| Assignment 7 | Click Here |
| Assignment 8 | Click Here |
| Assignment 9 | NA |
| Assignment 10 | NA |
| Assignment 11 | NA |
| Assignment 12 | NA |
Comments
Post a Comment