We have compiled most frequently asked Java J2EE Interview Questions which will help you with different expertise levels.


Question 1.
Compare in brief C++, Java, and C#.
C++, Java, and C# share a common ancestry but differ in many ways. C# and lava are like close cousins. Both support distributed programming and both use intermediate code to achieve safety and portability. However, the details differ. Both also support run-time error checking, security, and managed execution. But, the details differ a lot once more. Furthermore, unlike Java, C# provides access to pointers, a facet supported by C++. In this way, we come to see that C# combines the raw power of C++ with the type safety of Java.

Question 2.
Discuss the evolution of the various versions of C#.
Many new features have been added to C# ever since its initial version 1.0 in the year 2000, the first major revision being 2.0, followed by release 3.0, and eventually 4.0.

The most important change brought about by C# 2.0 was the revolutionary introduction of generics. LINQ (Language Integrated Query) and lambda expressions were the major additions made by the 3.0 release while named & optional arguments and the keyword dynamic (which relaxes type checking rules to run-time rather than at compile time) along with support for parallel programming by means of TPL (Task Parallel Library) and PLINQ (Parallel LINQ) were the major introductions made by the version 4.0 of C#.

Question 3.
Give two compelling reasons for the creation of C#.
Java answered many of the needs of the programmers but was lacking on two scores, namely:-

  • Mixed-language programming / Cross-language interoperability
  • Full integration with the Windows platform ‘

C# was the result of mainly these two needs and Microsoft’s overall .NET strategy in the late 1990s.

Question 4.
Mention two main points as to how C# relates to the .NET Framework.

  • First, C# was initially meant to program on the .NET Framework.
  • Secondly, the libraries used by C# are those as defined by the .NET Framework.

Question 5.
Distinguish between managed and unmanaged code.
A normal C# program written under the control of the CLR (Common Language Runtime) is subject to several constraints and as such obtains consequent benefits thereof – such code is known as managed code. On the contrary, unmanaged code does not run under the control of the CLR. But, the point to be noted is that managed and unmanaged code can work together.

Question 6.
What are the value types allowed by C#?
In addition to the thirteen simple types such as bool, char,decimal, double, float, int etc. C# allows enumerations, structures and nullable types, all of which are value types.

Question 7.
What is the decimal data type intended for?
The decimal type is indeed the most interesting C# numeric type intended for use in monetary/financial calculations. It can successfully represent up to 29 decimal places without any rounding errors, a fact that makes it especially useful for computations involving money/ finance.

Question 8.
Is there any special significance of the char data type in C#?
Unlike most other languages such as C++, which use the standard 8-bit ASCII character set, C# uses a 16-bit character type called Unicode, which is large enough to accommodate all of the characters found in all the human languages including Chinese, French, German, and, of .course, English.

Question 9.
What do you understand by a widening and a narrowing conversion?
When one type of data is assigned to another type of variable, an implicit widening conversion takes place automatically in C# if the two types are compatible and the range of the destination type is greater than that of the source type. In all other cases, you need to apply a cast. When a cast includes a narrowing conversion such as from a float to an int, information may be lost due to truncation, e.g., if the value 1.14 is assigned to an integer, the resulting value will be just 1 and 0.14 is lost.

Note: You may like to compare this concept with Java. For this, you are advised to refer to chapter 1.

Question 10.
What is the difference between the use of the prefix increment ++x and the use of the postfix increment x++ in C# and Java?
There is essentially no difference between the use of the postfix increment x++ and the prefix increment ++x in C# and Java. If you know how to use these operators in one of these languages, you can use them the same way in the other.

Question 11.
What is the difference between short-circuit logical operators || OR and && AND in C# and Java?
The short circuit logical operators || OR and && AND operate in the same manner in both C# and Java.

Question 12.
Can you name an operator in C# that takes three operands?
The ternary operator with the most general form:-
exp1? exp2: exp3;
(if exp1 is true, exp2 becomes the value of the whole expression else exp3 becomes the value of the whole expression)

Note: the use of the ternary operator in Java as well. It operates the same way.

Question 13.
Can you create a ‘for’ loop without any conditional expressions? What does it amount to?
Leaving the conditional expressions in a ‘for’ loop makes it an infinite loop that will run forever:-
for (; 😉 // intentional infinite loop
An infinite for’ loop can be created in Java the same way.

Question 14.
What does each loop do?
Each loop cycles through the elements of a collection.

Note that there is a for-each style loop in Java as well but without the foreach keyword.

Question 15.
What do the break and continue statements do? Bring out the main point of difference between them.
The break statement causes early termination of the loop, whereas the continue statement causes an early iteration of the loop. Again, note that the break and continue statements work the same way in Java.

Question 16.
Explain the use of the keyword new.
The keyword new is used to create objects, e.g.
Room classroom = new Room( );
Here, the classroom by itself does not contain the object (Room).
Rather, it contains a reference to it.
On the other hand, consider:-
int i = 100;
Here, i contains the value 100 since i is a variable of type int, which, in turn, is a value type. Again, consider:-
Room classroom1 = new Room ( );
Room classroom2 = new Room ( );
classroom2 = classroom1;
Room classroom3 = new Room ( );
classroom2 = classroom3;
After the execution of this sequence, classroom2 refers to the same object (Room) as classroom3. The object (Room) referred to by the classroom1 is unchanged.

Note: The keyword new works in essentially the same manner in Java.

Question 17.
Can now be used with value types?
Yes, although new is mainly meant for reference types.
For example,
int k = new int ( );
initializes k to zero.

Question 18.
Point out the difference between C++ and C# as regards the release of previously allocated memory.
In C++, the delete operator is used to free memory that was previously allocated. But, C# uses a different, more trouble-free approach, viz. garbage collection.

Note: Also, try to note the similarity between Java and C# in this respect, viz. garbage collection.

Question 19.
What is the purpose of the destructor in C#?
We can define a method in C# that shall be called just prior to the object’s final destruction by the .garbage collector. This method is known as the destructor, which can be used in some highly specialized situations to ensure that the object is destroyed/terminated cleanly.

Question 20.
What do you understand by ‘this’?
When a method is called, it is, by itself, passed a reference to the invoking object, i.e. the object on which the method is called. This reference is referred to as ‘this’.

Note: Try to see Java’s ‘this’ reference. Do you note any differences?

Question 21.
Can you elaborate on the concept of jagged arrays?
In general, when we create a two-dimensional array, we are creating what is a rectangular array with the length of each row being the same for the entire array, e.g. a 2 x 3 array implies an array of two rows with three elements in each row. But, C# allows you to create a special two-dimensional array called a jagged array, which is an array of arrays, where the length of each array can differ. In this way, we can have a table where the lengths of the rows differ, e.g.

int [ ][ ] jag – new int [4] [ ];
jag [0] = new int [10]; //length of first array is ten
jag [1} ~ new int [2]; //length of second array is two
jag [2] = new int [5]; // length of third array is five
jag [3] = new int [8]; //length of fourth array is eight

Note: There is a concept of jagged arrays in Java as well. Try to see the difference in the declaration of multi-dimensional arrays in C# and Java. It would not be possible to take up the complete discussion here. However, if interested, you can refer to the authors’ works – “The Essentials of Java” & “The Essentials ofC# 4.0″ in this context.

Question 22.
Can you point out the main difference between C/C++ strings and C# strings?
In C/C++, strings are simply arrays of characters terminated by the ‘\0’ null character whereas in C#, string is a built-in data type. In fact, in C#, strings are objects and thus, reference types.

Question 23.
Can the contents of strings in C# be changed?
No, strings in C# are immutable (see also Question 586). This might seem to be a drawback but since unused string objects are automatically garbage-collected, you can simply create a new string with the desired changes.

Question 24.
What are C#’s access modifiers?
In C#, member access control is achieved through four access modifiers, namely, public, private, protected and internal. The protected modifier applies only in case of inheritance; the internal modifier applies mostly to the use of an assembly, which for C# loosely implies a deployable program/library. When a member of a class is modified by the public specifier, then that member can be accessed by any code in your program. If a member of a class is specified to be private, it can then only be accessed by other members of its class so that methods in other classes will not be able to access a private member of another class.

Note: Try to see Java’s access specifiers. What differences do you note?

Question 25.
What is the use of the ref and out keywords?
By means of the ref and out keywords, it becomes possible to pass any of the value types by reference.

Question 26.
Is it possible to have a variable number of arguments in C#?
Yes, it can be achieved by means of the params modifier which represents an arbitrary number of parameters.

Note: Can a variable number of arguments be used in Java? Left as an exercise for you.

Question 27.
What is the use of the object initializers?
The primary use of the object initializers is with the anonymous types created in a LINQ expression. Object initializers provide a means to create an object and initialize its fields and properties.

Question 28.
Can you elaborate on the use of the optional arguments?
By means of optional arguments, you can specify a default value for a method’s parameter. This feature has been introduced in C# 4.0.

Question 29.
Can optional arguments result in ambiguity?
One problem that can result while using optional arguments is ambiguity. This occurs when a method having optional arguments is overloaded.

Question 30.
What do you understand by named arguments?
Named arguments are a feature related to the passing of arguments to a method. This feature has recently been introduced in C# 4.0. With the help of named arguments, one can specify the name of the parameter to which an argument applies.

Question 31.
Specify the forms of the Main ( ) method available in C#.
The following four versions of Main ( ) are currently available in C#:-

  1. static void Main ( )
  2. static int Main ( )
  3. static void Main (string args[ ])
  4. static int Main (string args[ ])

Question 32.
Elucidate the role of the keyword static.
In general, a class member has to be accessed through an object of its instance. But, it is possible in C# to create a member that can be used by itself, without any reference to a specific instance. To create such a member, you have to precede its declaration with the keyword static. Besides static variables and methods, we can even have static classes, which have two significant uses. First, a static class is used to contain a set of related static methods. Second, a static class is needed when creating extension methods, which relate mostly to LINQ.

Question 33.
Point out any two restrictions on static methods?
First, a static method cannot have a ‘this’ reference. Second, a static method can directly call only other static methods of its class.

Question 34.
When an operator is overloaded, does its original meaning get lost?
When we overload an operator relative to a class, none of its original meanings is lost. It is just that a new operation/meaning relative to that class gets added. For instance, overloading the – operator to handle the removal of a node from a linked list does not alter its original meaning relative to integers, i.e. subtraction.

Question 35.
What are indexers used for?
Indexers provide the means by which an object can be indexed like an array. Array indexing is done using the [ ] operator. It is possible to define the [ ] operator for the classes one creates, but it is not done using an operator method. Rather, we use an indexer.

Question 36.
What are properties used for?
Properties offer a streamlined approach to manage excess to the instance data of a class.

Question 37.
Are indexers and properties related to each other?
Indexers and properties are related to each other as both of them depend upon another feature of C#, viz. the get & set accessors.

Question 38.
Can you overload an indexer?
Yes, an indexer can be overloaded. The version executed shall be the one that is the closest type-match between its parameter and the argument used as an index.

Question 39.
Does an indexer require an underlying array?
It is not necessary that an indexer necessarily operates on an underlying array. Rather, it must simply provide functionality that seems to be ‘array-like to the user of the indexer.

Question 40.
What is the main difference between a private variable and a property?
Suppose, you want to limit the range of values that can be assigned to a field. It is possible to achieve this aim by means of a private variable along with methods to access its value. However, the property offers a much better, more streamlined way to achieve the same goal.

Question 41.
What do you mean by an auto-implemented property?
Auto-implemented properties with the most general form:-
prop_data_type prop_name { get; set; }
where, prop_data_typerefers to the data type of the property and prop_name refers to its name, were introduced in C# 3.0.

Auto-implemented properties made it possible to implement very simple properties without having to explicitly specify the variable managed by the property. Instead, the compiler was assigned the task of automatically supplying the underlying variable.

Question 42.
Can properties be overloaded?
No, you cannot overload a property. But, you can have two different properties with both accessing the same variable.

Question 43.
Can a property be passed as a ref or out parameter to a method?
No, since the property does not specify a storage location, it cannot be passed as a ref or out parameter to a method.

Question 44.
Can you use a different access modifier with the get and set accessors than the one used for their indexer/property?
By default, the get and set accessors have the same accessibility as that of their indexer/property But, you can use a different access modifier as well, e.g. if the indexer/property is public, you can give get or set its own access modifier such as private.

Question 45.
Both the base class and the derived class can have their own constructors. So, what constructor is responsible for building an object of the derived class – the one in the base class, or the one in the derived class, or both?
The constructor for the base class constructs the base class part of the object and the constructor for the derived class builds the derived class portion of the object.

Note: This is similar to the concept of superclass and subclass in Java.

Question 46.
How does a derived class call a constructor defined in its base class?
A derived class can call a constructor defined in its base class by using an expanded form of the derived class’ constructor declaration and the base keyword in the following manner:-
derived_class_constructor (parameter_list) : base (arg_list)
where arg_list specifies any arguments required by the constructor in the base class.

Question 47.
In what order are constructors called in a class hierarchy?
In a class hierarchy, constructors are called in their order of derivation (just like in Java).

Question 48.
What do you mean by method overriding?
The process of redefining a virtual method inside a derived class is referred to as method overriding. When overriding a method, the name, return type, and signature of the overriding method must exactly be the same as that of the virtual method being overridden.

Question 49.
What do you understand by dynamic method dispatch?
Dynamic method dispatch is the means by which a call to an overridden method is resolved at run-time rather than at compile tim£. It is important since C# implements run-time polymorphism this way.

Note: The concepts of method overriding and dynamic method dispatch work in the same way in Java as in C#.

Question 50.
Can properties/indexers be modified by the keyword virtual and overridden using override?
The answer to both the queries is in the affirmative.

Question 51.
Can you give one good reason for using overridden methods?
Overridden methods are another way that C# implements the ‘One interface, multiple methods’ aspect of polymorphism.

Question 52.
Can an abstract method have a body?
No, not at all!

Question 53.
Can you use virtual and abstract together?
An abstract method is, by itself, virtual and there is thus, no need to specify the virtual modifier. In fact, it’s an error to use virtual and abstract together!

Question 54.
Can you create an object of an abstract class using new?
An abstract class does not specify a complete implementation and whence, there can be no objects of an abstract class. Therefore, attempting to create an object of an abstract class using new will lead to a consequent compile-time error.

Question 55.
What are the two uses of the keyword sealed?

  1. You can use sealed to prevent a class from being inherited by preceding the class declaration with the keyword sealed.
  2. You can use sealed virtual methods to prevent further overrides.

Note: Is there a similar keyword in Java? Yes – the final’ keyword.

Question 56.
What do you mean by boxing and unboxing?
When an object reference refers to a value type, the value type is said to be ‘boxed inside the object and this process is referred to as boxing. The reverse process of retrieving a value from a boxed object using an explicit cast from the object reference to its corresponding value type is referred to as unboxing.

Note: Are there any differences between C# and Java as regards the concepts of boxing and unboxing? Try to find out for yourself! We would just like to mention that there are concepts of auto-boxing and auto-unboxing in Java.

Question 57.
Is the object class a universal data type? If it is, what are its pitfalls?
The object class is indeed a universal data type in C# and it is possible to use an object reference to refer to any type of data. This makes it possible to get past C#’s otherwise impregnable/strong type checking. But, this must be avoided as far as possible since it can lead to unexpected errors and bugs. Indeed, it’s best to save an object’s universal nature for highly special situations. More importantly, true generics are available ever since C# 2.0, and this feature enables you to easily define classes and algorithms that work automatically with different data types in a type-safe manner.

Note: Does Java too have such a similar superclass universal in nature? Yes, it has! Find it out!!

Question 58.
Define an interface in C#.
An interface defines a set of methods that will be implemented by a class. An interface, by itself, does not implement any method. In this way, we see that an interface is a purely logical construct that describes functionality without defining any implementation whatsoever.

Question 59.
What is the main point of difference between structures and classes?
Structures and classes are similar to each other except that structures are handled as value types whereas classes are treated as reference types.

Question 60.
What is the similarity and difference between interfaces and abstract classes?
Interfaces are syntactically similar to abstract classes. But, in an interface, no method can have a body. Thus, an interface does not provide any implementation at all. It tells what is to be done but is completely silent about how it is to be done. Once an interface is specified, any number of classes can implement it. Moreover, one class may implement any number of interfaces.

Question 61.
How will you choose between an interface and an abstract class?
When you can fully describe the concept in terms of ‘what it does’ without any need to specify ‘how it does it, you should use an interface. However, if you need to include at least some implementation details, you should use an abstract class to represent your concept.

Question 62.
When would you prefer to use a structure instead of a class?
In general, if you need to just store a group of related data, but don’t need to operate on that data through a reference and don’t need inheritance, structures are a more efficient choice and should be preferred to classes.

Question 63.
Can an enumeration be used to control a switch statement or as a control variable in a ‘for’ loop?
Since enumerations represent integer values, they can easily be used to control a switch statement or as the control variable in a ‘for’ loop.

Note: There are enumerations in Java as well. However, there remains many a difference between C# and Java in this respect.

Question 64.
What are an exception and an exception handler?
An exception is an error that occurs at run-time. Exception handling streamlines error handling by allowing the program to specify a block of code, called an exception handler, which is executed automatically in case of an error. Exception handler eliminates the need to manually check the success/failure of each specific operation or method call. In case an error occurs, it is processed/handled by the exception handler gracefully.

Note: Once again, try to see Java’s exception handling mechanism. Do you note any differences?

Question 65.
Can you elaborate on the consequences of an uncaught exception?
In general, if your program does not catch an exception, it will be caught by the run-time system, which, in turn, will report an error and terminate the program abnormally / ungracefully.

Question 66.
What is the major benefit of exception handling?
One of the major benefits of exception handling is that it enables your program to respond to an error and then continue running, that is, handle the error gracefully, and then continue further.

Question 67.
What are the pitfalls of using the ‘catch all’ handler as a means of dealing with exceptions?
The inappropriate use of the ‘catch all’ handler can result in situations where errors that would otherwise be detected during testing would go unnoticed. It is also difficult to correctly handle all types of exceptions with a single ‘catch all’ handler. The ‘catch all’ handler should therefore be used rarely in certain specialized and exceptional situations.

Question 68.
Can you have a try block followed by a final block with no catch clauses?
Syntactically, when a final block follows a try block, no catch clauses are technically required. In such a case, the final block gets executed after exit from the try block, but no exceptions are handled in such a case/event.

Question 69.
Elucidate the use of the checked and unchecked keywords.
Overflow exceptions in arithmetic computations are controlled by the keywords – checked and unchecked. To ignore the overflow, unchecked is used and to catch the overflow exception, checked is used.

Question 70.
What is a stream in C#?
C# programs perform Input / Output through streams. A stream is an abstraction that produces/consumes information. A stream is liked a physical device by the I/O system. It is useful to note that all streams behave in the same manner irrespective of the physical device they might be linked to.

Note: Do streams in Java behave the same way? Left as an exercise for you!

Question 71.
Name the standard console I/O streams.
Console.In, Console.Out, and Console. Error are the three standard console I/O streams.

Question 72.
How is binary data read and write?
Binary values of the C# built-in types are read and written using the BinaryReader and BinaryWriter streams, respectively. It is pertinent to mention over here that this data is read and written using not its human-readable text format but using its internal, binary form.

Question 73.
Define a delegate and an event.
A delegate is a means to encapsulate a method. It is useful to note that a delegate in C# is similar to a function pointer in C/C++. An event is a notification that an action has occurred. Delegates and events are related since an event is built upon a delegate.

Question 74.
What do you understand by multicasting?
In simple language, multicasting is the creation of a chain of methods that shall be called by itself when the delegate is invoked; this chain can be created by instantiating the delegate, then using + or += operator to add methods to the chain, and – or -= operator to remove methods from the chain.

Question 75.
In what way are delegated useful?
First of all, delegates are useful as they support events. Second, delegates provide a means to execute methods at run-time without having to precisely know what those methods are at compile time. This ability of the delegates comes in especially handy if we want to create a framework that allows components to be plugged in.

Question 76.
Name the two types of lambda expressions.
The two types of lambda expressions are the expression lambdas and the statement lambdas.

Question 77.
How does an event work?
An object that has an interest in an event registers an event handler for that event. When the event occurs, all registered handlers represented by delegates are invoked.

Question 78.
Define a namespace.
A namespace is, in essence, a declarative region, which provides a way to keep a set of names separate and away from conflict with another.

Question 79.
Can namespaces be nested, one inside another?
The answer to this query is in the affirmative.

Question 80.
List the C# preprocessor directives.
Following is the required list of C# preprocessor directives;-

  1. #define
  2.  #elif
  3. #else
  4. #endif
  5. #endregion
  6. #error
  7. #if
  8. #line
  9. #pragma
  10. #region
  11. #undef
  12. #warning

Question 81.
What do you mean by generics?
Generics imply parameterized types. They provide a streamlined and type-safe approach to deal with different data types as compared to the universal object class. They also promote the reusability of code. Generics were introduced by C# 2.0 and they have revolutionized the C# language ever since their inception.

Note: Generics have also been introduced in Java and are somewhat similar to templates in C++. However, differences remain.

Question 82.
Can properties/indexers/operators be generic?
Properties/indexers/operators cannot be generic. But, they can be used in a generic class to make use of the generic type parameters provided therein.

Question 83.
Explain in brief the utility of LINQ.
LINQ (Language Integrated Query) gives C# the ability to generate queries for any LINQ-compatible data source. Moreover, the syntax used for the query remains the same irrespective of the data source so that the syntax used to query data in a relational database is the same as the one used to query data stored in an array, for instance. There is no need to use SQL or any other mechanism not related to C# so that the query capability is fully and wholly integrated into the C# language.

LINQ can also be used along with SQL, XML files, ADO.NET Datasets as also with C# collections and arrays. Thus, we see that LINQ provides a uniform platform to access data in general.

Question 84.
What do you understand by nullable types?
A nullable type is a special version of a value type that is represented by a structure. In addition to the values defined by the underlying type, it can also store the value null. In this way, we see that a nullable type has the same range and characteristics as its underlying type but has the additional capability to represent a value, which indicates that a variable of that type is unassigned. It may also be noted that only value types have nullable equivalents.

Question 85.
Differentiate between dynamic type and the object class.
In one way, the dynamic type is similar to the object class since it can be used to refer to any type of object. The difference is that in the case of dynamic, all type checking is deferred until run-time whereas, with the object class, type checking still takes place at compile time.

Question 86.
How can you create a string in C# that is mutable?
A mutable string in C# can be created by means of the StringBuilder class, which is in the System. Text namespace.

Note: Compare and contrast the way a mutable string is created in Java.

Question 87.
What do you understand by multithreading?
C# has built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run concurrently. Each such part is called a thread, and each thread defines a separate path of execution. A text editor formatting its text and printing at the same time is a good example of multithreading. In this way, we see that multithreading is a specialized version of multitasking.

Question 88.
What is meant by TPL?
TPL (Task Parallel Library) is one of the most important features added to the .NET Framework by version 4.0. This library enhances multithreaded programming in two ways. First, it facilitates the creation and use of multiple threads. And, second, it automatically makes use of multiple processors.

Question 89.
What is meant by PLINQ?
Another important feature added by .NET 4.0 is PLINQ (Parallel Language Integrated Query). PLINQ enables you to write queries that automatically make use of multiple processors and parallelism wherever appropriate. It enables the addition of parallelism to a query with minimal effort.

Question 90.
While using the TPL, what are the two basic ways in which you can add parallelism?
Data Parallelism & Task Parallelism.

Question 91.
Elucidate the utility of collections.
Collections simplify many programs by providing off-the-shelf solutions to several common but at times difficult to develop data structures. For instance, there are built-in collections that support dynamic arrays, linked lists, stacks, queues, and hash tables.

Question 92.
What is the ArrayList class?
The tire ArrayList class supports dynamic arrays, which can grow or shrink as per the user requirements.

Question 93.
What is a Hashtable?
Hashtable creates a collection that uses a hash table for storage (the hash table, in turn, stores information using a mechanism known as hashing).

Question 94.
Define a SortedList.
SortedList creates a collection that stores key / value pairs in sorted order, based on the value of the keys.

Question 95.
On what principle does a Stack operate?
Stack is a “First-in, Last-out” list. To visualize a stack, imagine a stack of plates on a table. The first plate put down is the last one to be retrieved.

Question 96.
What is the principle behind the Queue?
The queue is a “First-in, First-out” list, i.e. the first item put in a queue is the first item retrieved from it. Queues are common in real life, e.g. lines at a bank or railway reservation center are queues.

Question 97.
What is a BitArray?
The BitArray class supports a collection of bits. Since it stores bits rather than objects, its capabilities are different than those of other collections.

Question 98.
Elaborate on the role of the enumerator.
Quite often, one needs to cycle through the elements in a collection, e.g. you may want to display each element. One way to do this is by means of the for each loop. Enumerator provides another way for the same.

Question 99.
What is the utility of the collection initializers?
C# includes a feature called the collection initializer, which helps to initialize certain collections. The syntax is similar to an array initialization.

Question 100.
What types of comments are supported by C#? Does it support XML documentation comments?
C# supports three types of comments – the first two are / / and /*’*/. The third type is based on XML tags and is called a documentation comment or an XML comment. A single line documentation comment begins with III while a multiline documentation comment begins with /** and ends with */•

Such documentation comments, in general, precede the declaration of things like classes, namespaces, methods, properties and events; you can embed information about your program into the program itself using these documentation comments and on compiling the program, you can have these comments placed into an XML file as well.

You are advised to compare and contrast the type of comments supported by Java for yourself (refer Chapter 1 in this context). .

Note :

 We have briefly referred to certain similarities and differences between Java and C# as regards various 
topics in the foregoing text, which could be of vital importance from the "INTERVIEW" point of view. 
As already pointed out, it would not be possible to take up a complete discussion of these here. However, 
you can refer to the authors' works - "The Essentials of Java" & " The Essentials of C# 4.0" in this context.