Infosys Certified L1 Junior Java Programmer
Practice with real exam-pattern questions for Infosys Certified L1 Junior Java Programmer. Each question includes a detailed explanation to help you understand the concept, not just memorise the answer. Try 10 questions free — no login required.
Full question bank for this exam + 1,357+ others. Cancel anytime.
Join Premium10 Infosys Certified L1 Junior Java Programmer practice questions with answers
Real Lex exam-pattern multiple-choice questions for the Infosys Certified L1 Junior Java Programmer certification. Each question includes the correct answer. The full question bank is available to Premium members.
- Question 1
A constructor doesn't have any return type, because?
I) By default it returns the object on which class type it was created
II) Based on the type of the constructor called, returns any of the primitive types only
III) Nothing will be returned from a constructor either implicitly or explicitly.- ✓
I only
Correct - B
II only
- C
III only
- D
I or II
- ✓
- Question 2
Assuming all the necessary imports are done, predict the output of the below code:
public class FileStreamDemo {
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("sample.txt");
String text = "Java Basics";
byte[] b = text.getBytes();
fos.write(b);
FileInputStream fis = new FileInputStream("sample.txt");
int i = fis.read();
System.out.println((char)i);
fos.close();
fis.close();
}
}- ✓
J
Correct - B
Java
- C
Java Basics
- D
Basics
- ✓
- Question 3
Harry is implementing a generic class to store a collection of items and wants to ensure that the class can accept various types of objects. Which wildcard should be used in the generic class declaration to allow the class to accept any type of object?
- ✓
<T>
Correct - B
<?>
- C
<*>
- D
<E>
- ✓
- Question 4
Consider the following Java code:
// Assume all the necessary imports are done
public class StudentManager{
public static void main(String[] args) {
List<String> names = new ArrayList<>();
names.add("John");
names.add("Jane");
names.add("Alex");
names.add("Emily");
String searchTerm = "Alex";
boolean containsSearchTerm = names.contains(searchTerm);
int indexOfSearchTerm = names.indexOf(searchTerm);
System.out.println("Contains Search Term: "+containsSearchTerm);
System.out.println("Index of Search Term: "+indexOfSearchTerm);
}
}What will be the output of the above code when executed?
- ✓
Contains Search Term: true, Index of Search Term: 2
Correct - B
Contains Search Term: false, Index of Search Term: 2
- C
Contains Search Term: true, Index of Search Term: 3
- D
Contains Search Term: false, Index of Search Term: 3
- ✓
- Question 5
You are working on a project that involves managing a list of employees. Each employee has a unique ID and a name. You want to create a generic class to handle this list.
The EmployeeList class is defined as follows:
public class EmployeeList<T>{
private List<T> employees;
public EmployeeList(){
employees=new ArrayList<>();
}
public void addEmployee(T employee){
employees.add(employee);
}
public T getEmployee(int id){
for(T employee : employees){
if(employee.getId()==id){
return employee;
}
}
return null;
}
}
Given the above code, which of the following statements is true?
- ✓
The class EmployeeList can only hold objects of type Employee
Correct - B
The class EmployeeList can hold objects of any type
- C
The class EmployeeList will not compile because it is missing a constructor
- D
The class EmployeeList will not compile because the getEmployee method is missing a return statement
- ✓
- Question 6
What will be the output of the following code snippet? (Assume necessary class declaration is done and the main method is given)
StringBuffer sb = new StringBuffer("Welcome");
sb.replace(1, 3, "java");
System.out.println(sb);- ✓
Wjavacome
Correct - B
Javacome
- C
Wjavome
- D
Wjavame
- ✓
- Question 7
Which of the following is the part of the output when the below code gets executed? (Choose exactly three correct options)
//Assume that code is written inside a main method with proper class declaration
var s = "Hello";
var t = new String(s);
if ("Hello".equals(s)) System.out.println("one");
if (t == s) System.out.println("two");
if (t.intern() == s) System.out.println("three");
if ("Hello" == s) System.out.println("four");
if ("Hello".intern() == t) System.out.println("five");- ✓
one
Correct - B
two
- C
three
- D
four
- E
five
- ✓
- Question 8
What code may be inserted at line 1 for successful compilation and execution of the below code?
Given:
import java.time.*;
import java.time.temporal.TemporalAdjusters;
public class Demo {public static void main(String[] args) {
LocalDate today = LocalDate.now();
LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear());
Period period = today.until(lastDayOfYear);
System.out.println();
System.out.println("Months remaining in the year: "+_______); // line 1
System.out.println();
}
}- ✓
period.getMonths()
Correct - B
Date.geetDate()
- C
date.toString()
- D
Period.getMonth()
- ✓
- Question 9
What will be the output of the below code?
public class Demo {
public static void main(String[] args) {
int[] a = { 10, 20, 30};
int b = 0;
try { b = a[2];
System.out.println("Value of b=" + b);// Statement 1
String str = args[0];
System.out.println("Length of the string is:=" + str.length());//Statement 2
} catch (ArithmeticException|NullPointerException ec){
System.out.println("An exception has occurred");//Statement 3
} finally {
System.out.println("In the finally block");// Statement 4
}
System.out.println("Exception handled successfully");// Statement 5
} }- ✓
Runtime Exception: Null Pointer Exception and no other output
Correct - B
Statement 1, 4 and Runtime Exception: ArrayIndexOutOfBoundsException
- C
Statements 1,3,4 and 5 will be part of the output
- D
Statements 1,2,4 and 5 will be part of the output
- ✓
- Question 10
The InfyAccount team wants to find the average salary of employees using the below code.
Requirement:
- If the number of months <= 0, the code should display a message as "Invalid data".
- For validating the number of months, the developer has defined a custom-exception class 'MyException'.
Write a missing code for the MyException class to meet the above requirement.
//Missing Code for MyException class
public class Demo {
public static void printAverage(double totalSalary, int noOfMonths) throws MyException {
if (noOfMonths <= 0)
throw new MyException("Invalid data");
System.out.println("Average salary = Rs. " + totalSalary / noOfMonths);
}public static void main(String[] args) {
try {
printAverage(400000, 12); // Output: Average salary = Rs. 33333.333333333336
//printAverage(400000, 0); // Output: Invalid data
} catch (MyException e) {
System.out.println(e.getMessage());
}
}}
Choose the correct option from below.- ✓
class MyException extends Exception {
Correct
public Exception(String message) {
super(message);
}
} - B
class MyException {
public MyException(String message) {
super(message);
}
} - C
class MyException extends Exception {
public String MyException(String message) {
return (message);
}
} - D
class MyException extends Exception {
public MyException(String message) {
super(message);
}
}
More in Code
Pay once. Clear every cert this year.
One subscription, full Telegram channel access, every PDF posted during your membership.
- Full access to all 1,357+ certifications
- Monthly updated question banks
- Telegram private channel access
- Cancel anytime
- Everything in Monthly
- Save ₹2,100 vs monthly billing
- Priority answer key requests
- Best for increasing DQ score fast
- Everything in Quarterly
- Lifetime channel access — no renewals
- All future certifications included
- Priority response from admin team
Common questions, straight answers.
A monthly-updated Telegram channel where we post real exam-pattern question banks and detailed answer keys for 1,357+ Infosys Lex certifications. You join once, you get every PDF posted during your membership.
Right after payment on our Graphy page, you'll receive a private invite link to the Telegram channel. Access is instant — usually under 30 seconds.
We compile question banks from the actual Lex test pattern, sourced and verified by 180K+ community members who've recently cleared these exams. Match rate is consistently 85–95%.
Every single month. When Infosys rolls out new versions of certifications, we post updated dumps within 7–10 days. You'll see channel activity weekly.
Clearing certifications is one of the highest-weighted DQ factors. Members typically clear 3–5 certifications in their first 3 months, which moves DQ scores up by a full band.