Nptel Programming in Java Week 7 Assignment Answers
Nptel Programming in Java Week 7 Assignment Answers
Searching for the Week 7 answers of the NPTEL “Programming in Java” course? You’re in the right spot! Here, you’ll find reliable and up-to-date solutions to help you complete your Week 7 assignment with confidence.
Programming In Java
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.
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.
COURSE LAYOUT – Click To Know More
Nptel Programming in Java Week 7 Assignment Answers
Que. 1
What will be the output of the following Java program?
import java.io.*;
class ReadFile {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("NPTEL.txt");
BufferedReader br = new BufferedReader(fr);
System.out.println(br.readLine());
br.close();
}
}
Assume NPTEL.txt
contains:
a) Hello, World!
b) This is Programming in Java online course.
c) IOException
d) null
Que. 2
Which of these classes is used to write primitive data types to an output stream in Java?
a) FileWriter
b) DataOutputStream
c) PrintWriter
d) BufferedOutputStream
Que. 3
What will the following code print?
import java.io.*;
class RandomAccessFileExample {
public static void main(String[] args) throws IOException {
RandomAccessFile file = new RandomAccessFile("test.dat", "rw");
file.writeInt(100);
file.seek(0);
System.out.println(file.readInt());
file.close();
}
}
a) 0
b) Runtime Error
c) Compilation Error
d) 100
Que. 4
Complete the following snippet with the required code.
File file = new File("file.txt");
if ( _____ ) {
System.out.println("File exists.");
} else {
System.out.println("File does not exist.");
}
a) file.exists()
b) file.isFile()
c) file.fileExists()
d) file.isAvailable()
For Latest Update Join our official channel: Click here to join
Que. 5
What will the following Java program output?
import java.io.*;
class SequenceInputStreamExample {
public static void main(String[] args) throws IOException {
ByteArrayInputStream input1 = new ByteArrayInputStream("123".getBytes());
ByteArrayInputStream input2 = new ByteArrayInputStream("ABC".getBytes());
SequenceInputStream sequence = new SequenceInputStream(input1, input2);
int i;
while ((i = sequence.read()) != -1) {
System.out.print((char) i);
}
}
}
a) 123ABC
b) ABC123
c) Compilation Error
d) Runtime Error
Que. 6
What is the output of the following Java program?
class Main {
public static void main(String args[]) {
final int i;
i = 20;
i = 30;
System.out.println(i);
}
}
a) 30
b) Compiler Error
c) Garbage value
d) 0
Que. 7
What will be the output of the following Java program?
import java.io.*;
class CharArrayInput {
public static void main(String[] args) {
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i, j;
try {
while ((i = input1.read()) == (j = input2.read())) {
System.out.print((char) i);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
a) abc
b) abcd
c) abcde
d) none of the mentioned
Que. 8
What will be the output of the following Java program?
public class Calculator {
int num = 100;
public void calc(int num) {
this.num = num;
}
public void printNum() {
System.out.println(num);
}
public static void main(String[] args) {
Calculator obj = new Calculator();
obj.calc(20);
obj.printNum();
}
}
a) 20
b) 100
c) 1000
d) 2
For Latest Update Join our official channel: Click here to join
Que. 9
What will be the output of the following code?
import java.io.*;
public class m7 {
public static void main(String[] args) {
try {
PrintWriter writer = new PrintWriter(System.out);
writer.write(9 + 97);
writer.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
a) It will give compile-time error
b) It will give run-time error
c) j
d) 106
Que. 10
What will be the output of the following code?
Assume file.txt
contains:
“This is Programming in Java online course.”
import java.io.File;
class FileSizeExample {
public static void main(String[] args) {
String filePath = "file.txt";
File file = new File(filePath);
long fileSize = file.length();
System.out.println(fileSize);
}
}
a) 42
b) 35
c) 7
d) 0
Nptel Programming in Java Week 8 Assignment Answers – Click Here