Search This Blog

Friday, August 15, 2025

Java Inheritance - Constructors

 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

Thursday, August 14, 2025

Java Inheritance - Keywords

 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

Tuesday, August 12, 2025

Java IO - 1

 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

Saturday, August 9, 2025

Java main Method

 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

Friday, August 8, 2025

Java Multithreading - 5

 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 

Thursday, August 7, 2025

Java Multithreading - 4

 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

Tuesday, August 5, 2025

Java Setup

 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

Saturday, August 2, 2025

Java Modules - 1

 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

Friday, August 1, 2025

Java Keywords

 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)

Wednesday, July 30, 2025

Java Variables - 3

Local Variables 

Local variables are declared within a local scope. A local variable can be:

- a variable declared inside a method
-  a method argument
- a variable declared in a for loop
- a variable declared in a scope bounded by {}, and so on

When you declare a local variable without explicit initialization, what value will Java initialize it to?

a) A default value 
b) A junk value
c) its minimum value
d) none of the above

Created by Nancy K.A.N.
@13:16 30-Jul-2025

Tuesday, July 29, 2025

Java Data types - 2

 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


Monday, July 28, 2025

Java Strings - combining two strings

You have two strings, and you want to combine them into a single string, for example:

String s1="Hello";
String s2 = " World";

String s3 should have a combined value of Hello World

Which of the following methods of the String API can be used?

a) merge
b) join
c) concat
d) replace

Created By: Nancy N.
@16:45 28-Jul-12025

Subscribe to this blog for more...

Sunday, July 27, 2025

Algorithms - 1

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

Saturday, July 26, 2025

Class Relationships

 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

Friday, July 25, 2025

Java Operators Precedence

 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


Thursday, July 24, 2025

Java DMD

 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


Tuesday, July 22, 2025

Java Datatypes -1

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.  

 

Created by Nancy N.

@12:21 22-Jul-2025

Sunday, July 20, 2025

Open-Closed principle

 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

Friday, July 18, 2025

Value-Based classes Quiz

 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

Monday, July 14, 2025

Java Regular Expressions - Quiz

 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



Sunday, July 13, 2025

Bitwise Shift Operators - 1

 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

Friday, July 11, 2025

Product Life Cycle Stages

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

Follow on YouTube Coding With Nancy

Thursday, July 10, 2025

Some Acronyms - Programming practices

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

Follow on YouTube Coding With Nancy

Wednesday, July 9, 2025

Java Best Practices

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

Follow on YouTube Coding With Nancy

Tuesday, July 8, 2025

Java Platform - 1

 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

Follow on YouTube Coding With Nancy

Monday, July 7, 2025

Java Interfaces Default Methods

 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

Follow on YouTube Coding With Nancy

Sunday, July 6, 2025

Java Value-Based class

 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


Saturday, July 5, 2025

Java String API - 2

 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


Friday, July 4, 2025

Java Behavioral Design Patterns

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

Follow on YouTube

https://kannancy.blogspot.com/

Wednesday, July 2, 2025

Java Variables - 2

 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

Follow on YouTube

https://kannancy.blogspot.com/

Tuesday, July 1, 2025

Java String API - 1

 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

Follow on YouTube

https://kannancy.blogspot.com/

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

Saturday, May 31, 2025

Java History - Virtual Threads

 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

Friday, May 30, 2025

Java History - Varargs

 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

Thursday, May 29, 2025

Java - Versions History

 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


Wednesday, May 28, 2025

Java - Inheritance

 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


Monday, May 26, 2025

Java Comments

 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

Friday, May 23, 2025

Java Multi Threading - 1

 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


Wednesday, May 21, 2025

Java - Runnable

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

Tuesday, May 20, 2025

Java Access Specifiers

 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



Friday, May 16, 2025

Java String Class

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


Thursday, May 15, 2025

SortedMap Interface

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

Tuesday, May 13, 2025

Function Pointers in C

 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:


At line 9, when you assign funptr the value of add, it stores the address of the function add and points to the function add:


When you call (*funptr)(9,7), it calls the add function and returns the sum.

At line 12, when you assign the address of the multiply function to funptr, it now points to the function multiply:


Now, on call, (*funptr)(3,9), it returns the product of numbers.

CAUTION - When you use a function pointer, it can point to different functions with the same signature (same number of parameters, same type, and order).

When the program is compiled, linked, and run, the output is:


More on function pointers, in another post...

Subscribe, share, and follow for more

Created by Nancy N.
@2:40 14-May-2025

 








Monday, May 12, 2025

Programming Errors

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



Sunday, May 11, 2025

Dependency Injection

 Is Dependency injection a design pattern?

a) Yes

b) No


Created by Nancy N.

@12:02 11-May-2025

Saturday, May 10, 2025

Functions and Pointers in C - 2

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?





Type your answer in the comment.

Created by Nancy N.
@12:01 10-May-2025








Friday, May 9, 2025

In which category will you put C Programming language?

 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

Wednesday, May 7, 2025

Gang of Four Patterns - 2

 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

Tuesday, May 6, 2025

Interesting Facts about Java - 4

 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

Thursday, May 1, 2025

Object-Oriented Programming - Generalization

 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



Gang of Four Design Patterns

 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

Tuesday, April 29, 2025

Functions and Variables in C Programming

 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.




Created by: Nancy N

29-Apr-2025


Sunday, April 27, 2025

C keyword or not?

 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



Friday, April 25, 2025

What is a Self-Refrential structure?

 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:


Example of self-referential structure:


Here, nptr is a pointer variable of type struct person, and nptr is a variable in the same datatype struct person. 

In a later post, we will see how the self-referential structures are useful.

Created by Nancy K A N
@00:59 26-Apr-2025





Thursday, April 24, 2025

Interesting facts about JAVA - 3

 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:


On compilation, you get an error:


If you declare it as an instance variable:


On compilation, you get the following error:



By: Nancy K A N

@9:48 25-Apr-2025





Wednesday, April 23, 2025

REST - 1

 Which protocol will you use in a REST service?

a) SOAP

b) JMS

c) HTTP

d) SMTP

e) FTP

Tuesday, April 22, 2025

Design Patterns - 1

 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


Wednesday, April 16, 2025

Object Oriented Programming Languages

 Which of the following is/are not an Object Oriented Programming (OOP) language(s)?

a) JavaScript

b) C++

c) COBOL

d) C

Sunday, April 13, 2025

Can I use a C Macro in a Java program?

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:


Now, before you compile the Java code, pipe it to the C preprocessor:

cpp -P MacroTest.java macros/MacroTest.java

Note: Make sure all the folders are created properly before the source code is submitted to the C preprocessor.

Next, go to the macros directory to view the Java code generated by CPP.


Compile and run this source code as usual :



Follow my blog for more @ https://kannancy.blogspot.com/








Monday, April 7, 2025

Java - this keyword - 1

 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?


a) Compile time error - invalid use of this at line 18

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.



C Preprocessor - 1

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?



a) Compile-time error at line 3

b) Compile-time error at line 6 

c)  Hello world!

d) Runtime error - print expected

Friday, April 4, 2025

functions and pointers Program 1

 What will happen when you run this program?




   a) Compile time error: mismatch of data type of function argument in line 7
   b) Prints garbage
   c) Prints 11 and 21
   d) Prints 11 and 22

Type your answer in a comment.



printf and scanf functions

 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.

Thursday, April 3, 2025

Can you guess which of these is a keyword of C Programming Language?

 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

Wednesday, April 2, 2025

Datatype int in C

 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