Search This Blog

Monday, June 30, 2025

Java Variables - 1

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

Follow on YouTube

https://kannancy.blogspot.com/

Sunday, June 29, 2025

Java Exceptions - 1

 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

Follow on YouTube

https://kannancy.blogspot.com/

Saturday, June 28, 2025

Java Unchecked Exceptions

 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

Follow on YouTube

https://kannancy.blogspot.com/


Friday, June 27, 2025

Java classes and Objects

 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


Follow on YouTube

https://kannancy.blogspot.com/


Thursday, June 26, 2025

Java Multithreading - 3

 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


Follow on YouTube

https://kannancy.blogspot.com/


Wednesday, June 25, 2025

Java Multithreading - 2

 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

Tuesday, June 24, 2025

Java Interface

 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

Monday, June 23, 2025

UML Diagrams

 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/


Sunday, June 22, 2025

UML

 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

Saturday, June 21, 2025

OOP - Concepts

 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

Thursday, June 19, 2025

Java Collections - 2

 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

Wednesday, June 18, 2025

Java NIO

 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


Tuesday, June 17, 2025

Java Class Inheritance

 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

Monday, June 16, 2025

Java Interface Inheritance

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

Sunday, June 15, 2025

Java Exceptions

 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

Saturday, June 14, 2025

Java History - Annotations

 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



Friday, June 13, 2025

Java - Simple Regular Expressions

 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



Wednesday, June 11, 2025

Java Collections - 1

 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

Tuesday, June 10, 2025

Java Network classes - 1

 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


Monday, June 9, 2025

Java PushbackInputStream - Code Example

What will be the output of the following PushbackInputStream code:

You have a text file Test1.txt. The test1.txt contains the following text: 

abcdefghijklmnopqrstuvwxyz

The following code reads the file Test1.txt. Can you guess the output of the following code?

/**
 *
 * @author Nancy K A N
 */
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PushbackInputStream;

public class PushbackInputStreamDemo {
    public static void main(String[] args) throws IOException{
        try {
            
            PushbackInputStream piStream= new PushbackInputStream(
                    new FileInputStream("C:\\JavaPractice\\BlogJava\\Test1.txt"));
            int readByte = piStream.read();
            System.out.println((char)(readByte));
            readByte=piStream.read();
            System.out.println((char)(readByte));
            readByte=piStream.read();
            System.out.println((char)(readByte));
            piStream.unread(readByte);
            readByte=piStream.read();
            System.out.println((char)(readByte));
           
        } catch (FileNotFoundException ex) {
            System.out.println("File not found");
        }       
    }
}



Created by Nancy N.
@14:50 09-Jun-2025



















Friday, June 6, 2025

Java - IO - usecase

 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



Thursday, June 5, 2025

Java _ Bitwise Operators XOR

 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













Wednesday, June 4, 2025

Java - IO - 1

 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


Tuesday, June 3, 2025

Java History - Enhanced for loop

 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:


In which version of Java was the enhanced for loop introduced?

a) Version 5
b) Version 3
c) Version 6
d) Version 2

Created by Nancy N.
@13:17 03-Jun-2025



Monday, June 2, 2025

Java History - Sealed classes and interfaces

 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


Sunday, June 1, 2025

Java History - Lambda Expressions

 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