Which of the following is used to call a parent class constructor from the child class constructor?
a) extends
b) this(parent classname)
c) super
d) instanceof
Created by Nancy K.A.N.
@23:08 15-Aug-2025
Which of the following is used to call a parent class constructor from the child class constructor?
a) extends
b) this(parent classname)
c) super
d) instanceof
Created by Nancy K.A.N.
@23:08 15-Aug-2025
Which of the following keywords are related to inheritance in Java?
a) this
b) super
c) class
d) interface
Created by Nancy K.A.N.
@14:16 14-Aug-2025
Java provides objects for standard input, output, and error. These are respectively in, out, and err. In which class are these objects defined or members of?
a) InputStream class
b) PrintStream class
c) System class
d) Console class
Created by Nancy K.A.N.
@11:34 12-Aug-2025
Java's main method is an entry point to a Java application. What is the return type of Java's main method?
a) int
b) float
c) void
d) double
Type your answer in the comments...
Created by Nancy K.A.N.
@14:20 09-Aug-2025
Java is a multithreaded language. Every Java thread has a priority. Every new thread is created with priority equal to the thread that created it. Thread priority plays an important role in the way threads are executed.
Which of the following is the data type of thread priority?
a) double
b) byte
c) long
d) int
e) float
Created by Nancy N.
@22:13 08-Aug-2025
Which of the following is not a thread state in Java?
a) WAITING
b) TIMED_WAITING
c) DESTROYED
d) TERMINATED
e) RUNNABLE
f) BLOCKED
g) TIMED_BLOCKED
Created by Nancy K.A.N.
@12:01 07-Aug-2025
Which of the following environment variables will you use to set the Java path?
a) PATH
b) JDK_PATH
c) JAVA_HOME
d) JAVA_PATH
Created by Nancy K.A.N.
@15:23 05-Aug-2025
Java modules are different from packages, and they add an additional encapsulation to applications. In which version of Java were modules added?
a) Java 7
b) Java 8
c) Java 9
d) Java 10
Created by Nancy K.A.N.
@16:59 02-Aug-2025
Keywords are the reserved words that have a predefined meaning in a programming language. I like to call them as action-associated or action-oriented words. Whenever you use a specific keyword, you are sure that a certain action will take place.
Java has 52 keywords, and some of the keywords are not used, like goto. Java has reserved identifiers or contextual keywords, such as exports, module, and others. And then there are literal values mistaken for keywords, like true, false, and null.
Which of the following is not a keyword of Java?
a) strictfp
b) synchronized
c) var
d) instanceof
e) volatile
Created by Nancy K.A.N.
@12:29 01-Aug-2025
Follow my blog and YouTube channel (@CodingWithNancy)
Java is a strictly typed language. Unlike C, where the size of some data types is machine-dependent, Java has a fixed size and thus range for every type. Keeping the fact in mind that Java is a strictly typed language, what will be the output of the following code?
1. /**
2. *
3. * @author Nancy
K.A.N.
4. */
5. public class Datatype2Demo {
6. public static void main(String[] args) {
7. short x = 32768;
8. System.out.println("x = "+x);
9. }
10. }
11.
Created by Nancy K.A.N.
@12:50 29-Jul-2025
Algorithms are essential for every programmer. There are algorithms for searching, sorting, pattern matching, traversing, and more.
Which of the following are sorting algorithms?
a) Binary
b) Boyer-Moore
c) Radix
d) Heap
e) Bubble
Created by Nancy N.
@12:42 27-Jul-2025
Aggregation is a special form of _______________________ that represents ownership relationship between two objects.
a) composition
b) inheritance
c) association
d) implementation
Created By Nancy N
@16:40 26-Jul-2025
Java expressions are created using a combination of variables and operators. When multiple operators are used in the same expression, Java executes these operators in a specific order. This is called operator precedence.
Here are four operators:
a) ++
b) +
c) ()
d) <<
In which order will these be executed if added into the same expression (high to low precedence)?
a) b, c, d, a
b) c, d, a, b
c) c, a, b, d
d) a, b, c, d
Created by Nancy N.
@10:18 25-Jul-2025
What does DMD in Java stand for?
a) Dispatching Method Dynamically
b) Distributing Messages Dynamically
c) Dynamic Message Distribution
d) Dynamic Method Dispatch
Created by Nancy N.
@12:32 24-Jul-2025
Can you assign a fractional value to an int by typecasting? What will be the outcome of the following code?
1. /**
2. * @author Nancy
K.A.N.
3. */
4. public class Datatype1 {
5. public static void main(String[] args) {
6. int x= (int)4.7;
7. System.out.println("x="+x);
8. }
9. }
10.
You are writing code for an application following the Open-Closed principle. Which of the following actions will you choose not to violate the Open-Closed principle?
a) You extend an existing class
b) You add a method to an existing class rather than extending it
c) You extend an existing class and also override a method of the superclass
Created by Nancy N.
@11:41 20-07-2025
Follow this blog for more interesting information
Subscribe to the YouTube channel @CodeWithNancy
Which of the following is not a Value-Based class?
a) Integer
b) Double
c) Object
d) Boolean
Created by Nancy N.
@18:04 18-Jul-2025
What will be the output of this regular expression (Java) code?
1. /*
2. * Code by Nancy K.A.N.
3. */
4. import java.util.regex.Matcher;
5. import java.util.regex.Pattern;
6.
7. public class RegexSubStringTest {
8. public static void main(String[] args) {
9. String str1 = "This is an example of 'Java Regular
Exressions'";
10. Pattern pattern = Pattern.compile("'(.*?)'");
11. Matcher matcher = pattern.matcher(str1);
12. if (matcher.find())
13. {
14. System.out.println(matcher.group(1));
15. }
16. }
17. }
18.
Created by Nancy K.A.N.
@17:13 14-Jul-2025
Follow my YouTube channel: @CodeWithNancy
What is the output of the following code?
/**
* @author Nancy K.A.N.
*/
public class BitwiseDemo1 {
public static void main(String[] args) {
int a =4;
int b = a<<3;
System.out.println(b);
}
}
By Nancy K.A.N.
@22:06 13-Jul-2025
Follow my YouTube channel @CodingWithNancy
The software industry accepts and follows the following life cycle stages for a product:
1. Project proposal
2. Requirement gathering and analysis
3. Designing
4. Code development
5. Testing
6. Implementation
7. Maintenance
8. End Of Life (EOL)
8-A An entirely new product or another product with better features
Created by Nancy K.A.N.
@15;42 11-Jul-2025
DRY - Don't Repeat Yourself
KISS - Keep It Simple Stupid
SLAP - Single Level Abstraction Principle
SOLID - contains five principles (SRP, OCP, LSP, ISP, DIP)
SRP - Single Responsibility Principle
OCP - Open-Closed Principle
LSP - Liskov Substitution Principle
ISP - Interface Segregation Principle
DIP - Dependency Inversion Principle
Created by Nancy K.A.N.
@21:17 10-Jul-2025
In Java, what are the best practices for naming classes and variables?
a) Upper Camel case for class names
b) Lower camel case for class names
c) Upper Camel case for variable names
d) Lower Camel case for variable names
e) all lowercase for class names as well as variable names
Created by Nancy K.A.N.
@19:10 09-Jul-2025
Java incorporated platform independence by ___________________.
a) Interfaces
b) classes
c) Java Native Interface
d) Java Virtual Machine
Created by Nancy K.A.N.
@13:39 08-Jul-2025
In which Java version were the interface default methods introduced?
a) Java 7
b) Java 8
c) Java 9
d) Java 11
Created by Nancy K.A.N.
@17:32 07-Jul-2025
A Value-Based class is a Java class that wraps a value. All the wrapper classes (Byte, Short, Integer, Long, Character, Float, Double, and Boolean) in Java are Value-Based classes, as they wrap the primitive type. In addition to the wrapper classes, the Optional class and the Date and Time API classes are also Value-Based classes.
A Value-Based class contains final fields and does not contain accessible constructors.
Which of the following statements is NOT true about Value-Based classes?
a) The class uses the instance's monitor to perform synchronization
b) If accessible constructors are created, they should be marked deprecated
c) The class should be instantiated only by using a factory method
d) The Value-Based class is always final
Created by Nancy K.A.N.
@22:22 06-Jul-2025
Follow on YouTube Coding With Nancy
What is the output of the following code?
(Hint: CharSequence is an interface.)
Created by Nancy K.A.N.
@12:10 05-Jul-2025
Follow on YouTube Coding With Nancy
Behavioral patterns in Java address object communication. Using behavioral patterns, you can define the interaction and communication among objects as well as between objects and the user. For example, you can use behavioral design patterns to distribute responsibilities or a chain of command. Which of the following are behavioral patterns?
a) Command pattern
b) Observer pattern
c) Singleton pattern
d) Factory pattern
e) Facade pattern
Created by Nancy K.A.N.
@14:14 04-Jul-2025
Which of the following are invalid variable names in Java?
a) !
b) $
c) _$
d) _
Created by Nancy K.A.N.
@23:09 02-Jul-2025
Which of the following methods is used to convert a Java String to an array of characters?
a) split()
b) getChars()
c) getBytes()
d) toCharArray()
Created by Nancy K.A.N.
@23:05 01-Jul-2025
Which of the following are not local variables?
a) Variables declared in a method
b) Variables declared in a block inside a method
c) Non-static variables declared in a class
d) Variables as method arguments
e) Static variables declared in a class
Created by Nancy K.A.N.
@21:29 30-Jun-2025
Which of the following keywords are not related to Java exceptions?
a) try
b) throw
c) catch
d) final
e) finally
f) catches
g) throws
Created by Nancy K.A.N.
@22:24 29-Jun-2025
Which of the following are Java unchecked exceptions?
a) InterruptedException
b) ArithmeticException
c) NullPointerException
d) SQLException
e) ClassNotFoundException
Created by Nancy K.A.N.
@22:14 28-Jun-2025
https://kannancy.blogspot.com/
In which area of memory is the object reference stored?
a) Method area
b) memory registers
c) Stack area
d) Heap area
Created by Nancy K.A.N.
@23:15 27-Jun-2025
https://kannancy.blogspot.com/
Which interface will you implement to incorporate multithreading in your Java application?
a) Run
b) Runnable
c) Thread
d) Executor
Created by: Nancy K.A.N.
@17:22 26-Jun-2025
https://kannancy.blogspot.com/
Which class will you extend to create a multithreaded application?
a) Threads
b) Runnable
c) Thread
d) Object
Created by Nancy K.A.N.
@15:42 25-Jun-2025
Follow my YouTube channel for Tech videos: https://www.youtube.com/@CodingWithNancy
Which interface in Java is a super interface of all interfaces?
a) Collections
b) Collection
c) Thread
d) None
Created by: Nancy K.A.N.
@18:42 24-Jun-2025
Which UML diagram is used to represent object interaction over time?
a) Class diagram
b) Activity diagram
c) Sequence diagram
d) Activity diagram
Created by Nancy K.A.N.
@17:17 23-Jun-2025
Subscribe to:
YouTube channel for Tech videos: https://www.youtube.com/@CodingWithNancy
Blog: https://kannancy.blogspot.com/
UML is an acronym for __________________________ used in Object Oriented Programming to represent the design and structure of software systems.
a) Unified Machine Language
b) Universal Machine Language
c) Universal Modeling Language
d) Unified Modeling Language
Created by: Nancy K.A.N.
@14:59 22-Jun-2025
Aggregation is a ____________ relationship with the contained class.
a) has-a
b) is-a
c) part-of
d) independent of
Created by Nancy K.A.N.
@14:58 21-Jun-2025
Which of the following Java collections classes does not allow duplicate elements in the collection?
a) ArrayList
b) Vector
c) LinkedList
d) TreeSet
Created by Nancy K.A.N.
@12:05 19-Jun-2025
Watch Tech videos on my YouTube channel https://www.youtube.com/@CodingWithNancy
Java introduced NIO in version 1.4. Java NIO is used for ____________________.
a) File directory services
b) for character-based IO stream
c) IO non-blocking operations
d) for only byte-based IO
Created by Nancy K.A.N.
@13:49 18-Jun-2025
Watch Tech videos on my YouTube channel https://www.youtube.com/@CodingWithNancy
Which keyword will you use to inherit a class from another class?
a) implements
b) extend
c) extends
d) aggregates
Created by Nancy K.A.N.
@12:25 17-Jun-2025
Which keyword is used when an interface needs to inherit from another interface?
a) super
b) implements
c) extend
d) extends
Created by Nancy K.A.N.
@17:40 16-Jun-2025
Which of the Following is a Java checked exception?
a) ArithmeticException
b) ArrayIndexOutOfBoundsException
c) FileNotFoundException
d) ClassCastException
Created by Nancy K.A.N.
@12:23 15-Jun-2025
Java annotations are a form of metadata that provides additional or supplemental data to a Java source file. An annotation provides information to the Java compiler and JVM.
An annotation starts with the @ symbol and does not change the action of a program. Annotations can be applied to classes, constructors, methods, instance variables, and so on.
A program can use predefined annotations like @deprecated, or a programmer can create their own annotations depending on the requirement.
@interface TestAnnotation {
String myStr();
}
In which version of Java were annotations introduced?
a) Java 11
b) Java 17
c) Java 8
d) Java 5
e) Java 6
Created by Nancy K A N
@14:47 14-Jun-2025
Regex or Regular Expressions are a part of the Java API. You can use the regex API to search, extract, or search and replace text strings. The regex API is available in java.util.regex package. Java uses the Pattern and Matcher classes to process regular expressions.
Here is a simple example of a Regular expression. The code searches for a pattern and prints the matching string.
/**
*
* @author Nancy K.A.N.
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SimpleRegexTest {
public static void main(String[] args) {
String str1 = "This is an example of Java Regular Exressions";
Pattern pattern = Pattern.compile("Java");
Matcher matcher = pattern.matcher(str1);
if (matcher.find())
{
System.out.println(matcher.group());
}
}
}
Compile and run the code and comment the output.
Created by Nancy KAN
@13:50 13-Jun-2025
Which of the following is the root interface of Java collections?
a) Collections
b) Collection
c) Abstract Collection
d) Concurrent Collection
Created by Nancy N.
@12:38 11-Jun-2026
In which Java package are the Socket and ServerSocket classes available?
a) java.lang.network
b) java.util.net
c) java.net
d) java.net.socket
Created by Nancy N.
@13:01 10-Jun-2025
What will be the output of the following PushbackInputStream code:
You have a text file Test1.txt. The test1.txt contains the following text:
To Store object data into a file, you can serialize a class by implementing the Serializable interface. If you do not want to store a particular field in the file, which of the following modifiers will prohibit it?
a) private
b) protected
c) volatile
d) final
e) static
Created by Nancy N.
@14:06 06-06-2025
Which of the following is/are true for Bitwise XOR?
a) Bitwise XOR is associative
b) Bitwise XOR can be used only with double and float data types
c) Bitwise XOR is represented by ~
d) Bitwise XOR can be used only with byte, short, int, and long
Created by Nancy N.
@14:58 05-Jun-2025
Which of the following classes can unread bytes?
a) SequentialPushbackInputStream
b) PushbackReader
c) PushbackInputStream
d) PipedInputStream
Created by Nancy N.
@13:12 04-06-2025
The Java enhanced for loop can be used to iterate through an array or a collection, without specifying the size or the number of elements in the array or collection. For example:
Inheritance is great for code reuse. To restrict the overuse or misuse of inheritance, sealed classes and interfaces were introduced.
In which version of Java were sealed classes introduced first as a preview?
a) Java version 9
b) Java version 11
c) Java version 15
d) Java version 17
Created by Nancy N.
@14:02 02-Jun-2025
Java Lambda expression is a short piece of code that takes parameters and returns a value like a function. A lambda is an anonymous function. Lambdas are implemented in the code.
Java introduced lambda expressions to bring the concept of functional programming.
A simple Lambda code to add two numbers and return the sum will look like this:
(x+y) -> x+y
Which version of Java implemented Lambdas?
a) version 7
b) version 8
c) version 9
d) version 11
Created by Nancy N
@10:57 01-Jun-2025
Virtual threads were introduced as a part of the project Loom. Virtual threads are lightweight when it comes to memory and CPU overhead. Virtual threads have less context switching cost than native threads.
Virtual threads are suitable for tasks like I/O, where a thread is blocked for most of the time, like in a server application. Virtual threads are not fast.
Virtual threads were introduced and finalized in different versions of Java.
In which version of Java were virtual threads introduced and finalized?
a) Version 17 and 20
b) Version 17 and 19
c) Version 19 and 20
d) Version 19 and 21
Created by Nancy N.
@13:50 31-May-2025
Varargs (Variable-length arguments), as the name suggests, is a concept that allows a method to receive a variable number of arguments. When you use the varargs method, you do not need to overload a method, for example: int add (int ... n){}, this add method can be called by passing any number of integer values. Although it may seem that overloading is not required, in some cases where you want to overload a method with different data type arguments, overloading is the way to go.
In which version of Java Varargs concept was introduced?
a) Version 4
b) Version 5
c) Version 7
d) Version 9
Created by Nancy N.
@12:44 3-=May-2025
In which version of Java were Generics was introduced?
a) Version 3
b) Version 5
c) Version 6
d) version 7
Created by Nancy N.
@29-May-2025
Which of the following keywords is used to inherit an interface?
a) implement
b) extends
c) extend
d) super
Created by Nancy N.
@12:09 28-May-2025
Which of the following is not a valid Java comment?
a) <! comment !>
b) /** @version 1 */
c) /* Java comment */
d) // java comment
e) # java comment
Type your answer in a comment
Created by Nancy N.
@1:08 27-May-2025
Which methods will you implement to incorporate user-defined threads in your Java program?
a) start()
b) join()
c) run()
d) yield()
Created by Nancy N.
@12:43 23-May-2025
Which of the following is true about Runnable?
a) Runnable is a class
b) Runnable is a method in the Thread class
c) Runnable is an interface
d) Runnable is a checked exception required to be handled by every class extending the Thread class
Post your answer in a comment.
Created by Nancy N.
@21-May-2025
Which of the following is not a Java Access Specifier?
a) private
b) volatile
c) protected
d) unprotected
e) static
f) public
g) transient
Created by Nancy N
@11:03 21-May-2025
In which package is the String class declared?
a) java.util
b) java.io
c) java.lang
d) java.text
e) java.textstrings
Type your answer in the comment.
Created by Nancy N.
@13:42 16-May-2025
Which of the following classes implements the SortedMap interface?
a) HashTable
b) TreeSet
c) TreeMap
d) HashSet
e) ConcurrentSkipListMap
Type your answer in a comment.
Created By Nancy N.
@13:32 15-May-2025
A C pointer is a variable that holds the address of another variable. Can it hold the address of a function? The answer is YES. You can declare a pointer variable and store the address of a function in this variable.
int add(int,int);
int *funptr=&add;
Or you can also assign a function name to the pointer instead.
int *funptr=add;
In C, a function name acts as a constant pointer to the function, so you can omit the & (address operator).
One of the benefits is that the same pointer variable can call different functions depending on which function it is pointing to. Using a function pointer, you can call the functions dynamically. It is useful when you want to pass a function as an argument. Here is an example:
Three types of programming errors are:
a) Compile-time error - caused by syntax, for example, boolen flag = false;
b) Runtime error—caused by unexpected conditions or invalid operations, such as memory overflow or opening a file that does not exist.
c) Logical error - programmer's logic faults - for example, faulty condition: if (x > y) print x is small
Created by Nancy N.
@11:30 am 12-May-2025
Is Dependency injection a design pattern?
a) Yes
b) No
Created by Nancy N.
@12:02 11-May-2025
Pointers in C are one of the strongest features if used thoughtfully. Pointer variables allow you to access a value in memory using its address. Here is a code for your brain exercise.
Study the code given below. What will happen when you compile and run this code?
In which category will you put the C Programming language?
a) High-level language
b) Machine-level language
c) Middle-level language
d) Low-level language
Type your answer in a comment.
Created by Nancy N.
@13:14 09-May-2025
Design patterns are reusable elements that provide standard solutions for software design issues. Gang of Four Design patterns are categorised into Creational, Structural, and Behavioural. Do you know how many total Gang of Four patterns there are?
a) 20
b) 32
c) 23
d) 45
Created by Nancy N.
@14:07 07-May-2025
Java was not created for the Internet. It was developed to serve the need for a platform-independent (architecture-neutral) programming language for embedded software for consumer electronics like remote controls.
C and C++ were the popular programming languages for embedded software (still in use). The problem was that C and C++ programs need to be compiled every time you want to run them on a different processor. So you needed a separate compiler for every target. James Gosling and the team wanted to design a programming language that could address this compilation-related issue. Java was created to be compiled to bytecodes, which are independent of the target platform.
Created by Nancy N.
@10:21 06-may-2025
In object-oriented programming, Generalization is achieved by
A. Inheritance
B. Polymorphism
C. Encapsulation
D. Abstraction
Type your answer in a comment.
Created by: Nancy N
@01:30 02-May-2025
In 1994, Eric Gamma, Richard Helm, Ralph Johnson, and John Vissides introduced the GoF (Gang of Four) design patterns. These design patterns addressed the common design problems and their solutions. These patterns addressed problems and solutions for which of the following type of programming:
a) Procedural programming
b) Object-based programming
c) Markup programming
d) Object-Oriented Programming
Type your answer in the comment.
Share this blog with your friends and also with those who are not your friends.
Subscribe to my blog for more interesting questions, codes, and articles...
By Nancy N
@11:54 01-May-2025
Variables can be passed to a C function as arguments, and the function can access these variables as function parameters. After processing information, the function can return a value to the main C program. The question here is, can a function return its local variable to the main program? There are different possibilities; here is one of these. Can you guess the output of the code given below? Comment the reason why you think the output you are providing is the right one.
29-Apr-2025
Which of the following is NOT a C programming language keyword?
a) auto
b) external
c) sizeof
d) volatile
Created by Nancy N
@18:24 27-Apr-2025
Self-referential structures are used in C and C++ programming. A self-referential structure is a structure that contains a pointer to itself, or you can say a pointer to a variable of the same type. A self-referential structure can have one or more pointer variables pointing to the same type.
Example of simple structure:
const is a Java reserved word with no assigned semantics to it. So, you cannot create an identifier with the name const. It is not a keyword, so it cannot be used in a Java program. It is just a prohibited word. A word that has no meaning in Java but is forbidden for any kind of use. Funny, isn't it?
If you declare to as a local variable:
Which protocol will you use in a REST service?
a) SOAP
b) JMS
c) HTTP
d) SMTP
e) FTP
There are three types of Gang of Four (GoF) Design patterns
1. Creational
2. Structural
3. Behavioral
Can you find which of these is a creational design pattern?
a) Facade
b) Strategy
c) Factory
d) Observer
Created and posted by Nancy N.
@15:40 pm GMT
Which of the following is/are not an Object Oriented Programming (OOP) language(s)?
a) JavaScript
b) C++
c) COBOL
d) C
Can I use a C Macro in a java program?
The answer is YES, you can.
Java programming does not use macros, but you can use C macros in Java. To do that you can pipe the source code containing macro and Java code through the C preprocessor. Below is an example code:
In Java, this keyword can be used in more than one way. Does the program below accurately use this keyword?
What happens when you run this code?
b) Runtime error - invalid nested call to a constructor
c) Program prints - hello
d) Program prints - hi
Type your answer in the comment.
Follow and share my blog for more interesting posts on programming and DS.
A macro or a preprocessor statement is used by the compiler before it compiles the program to transform the program.
What is the output of the following C program?
b) Compile-time error at line 6
c) Hello world!
d) Runtime error - print expected
What will happen when you run this program?
In which of the following header files printf and scanf functions are included?
a) inout.h
b) stdlib.h
c) stdio.h
d) io.h
Provide your answer in a comment.
Which of the following is a keyword of C Programming language?
a) printf
b) scanf
c) sizeof
d) getstr
Type the answer in a comment
What is the size of an int (integer) in the C language?
a) 1 byte
b) 2 bytes
c) 4 bytes
d) depending on OS