Java Related Interview Questions
Questions Answers Views Company eMail

What is the difference between the program and the process?

1 359

. What are the differences between constructor and method of a class in Java?

1 384

How do you use final keywords and final variables in Java?

2 228

In Java, what types of classes perform inheritance?

2 244

What types of inheritance does Java support?

2 223

What is Java exception handling?

1 230

What are the differences between unchecked exception, checked exception, and errors?

2 326

What are the types of loops in Java, and how are they used?

2 231

How do you declare an infinite loop?

2 261

What is the difference between the continue and break statement?

2 242

What is the entry point in Java, and how is it written?

2 270

In Java, what are public static void main string args?

2 234

In Java, what’s the purpose of static methods and static variables?

2 301

How do you use, call, and access a static method in Java?

2 297

How do you use, call, and access a non-static method in Java?

2 262


Un-Answered Questions { Java Related }

What is spring bean life cycle?

265


What is the use of @required annotation?

240


The following program reads data (details of students) from a file named students.txt and converts it into e-mail addresses. The results are written to a file named studentemail.txt. students.txt consists of a number of lines, each containing the data of a student in colon delimited format: Last Name:First Name:Student Number Each input record is converted to an e-mail address and written to studentemail.txt in the following format: the first character of the last name + the first character of the first name + the last four digits of the student number + “@myunisa.ac.za” import java.io.*; public class EmailConverter { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new FileReader ("students.txt")); PrintWriter output = new PrintWriter(new FileWriter ("studentemail.txt")); String line = input.readLine(); while (line != null) { // Extract the information for each student String[] items = line.split(":"); // Generate the email address String email = "" + items[0].charAt(0) + items[1].charAt(0) + items[2].substring(4,8) + "@myunisa.ac.za"; email = email.toLowerCase(); // Output output.println(email); line = input.readLine(); } input.close(); output.close(); } } Rewrite the class so that it handles possible errors that may occur. In particular, it should do the following: • It should catch at least three appropriate exceptions that might occur, and display suitable messages. • At this stage, the program will not run correctly if there is an empty line in the input file. Change the program so that if an empty line is encountered, an exception is thrown and the empty line is ignored. This exception should be handled with the display of a suitable error message. • Before the e-mail address is added to the output file, check if the student number has 8 digits. If not, throw an InvalidFormatException (which the program should not handle itself)

1687


What is primitive data type in java?

721


Difference between final and effectively final ?

820


What do you mean by checked exceptions?

740


Which is the default scope of bean in spring? In addition, are they synchronized?

241


What are the Packages of websphere?

680


Write a program to bind string values in a preparedstatement?

731


What is front controller in struts2?

746


Why do we need jdbc api?

680


Why char array is favored over string for the storage of passwords?

761


What’s the difference between struts and turbine? What’s the difference between struts and espresso?

729


What is the difference between session.save() and session.persist() method?

295


what is mena by object block any what is the use of that

1972