Short Answer .NET Interview Questions (PAGE 4)

Category: ASP.NET Questions, Dot Net Questions    |    3 views    |    Add a Comment

Q61. Is a delegate a type-safe functions pointer?
Ans. Yes

Q62. What is the return type of an event in .NET?
Ans. There is No return type of an event in .NET.

Q63. Is it possible to specify an access specifier to an event in .NET?
Ans. Yes, though they are public by default.

Q64. Is it possible to create a shared event in .NET?
Ans. Yes, but shared events may only be raised by shared methods.

Q65. How to prevent overriding of a class in .NET?
Ans. Use the keyword NotOverridable in VB.NET and sealed in C#.

Q66. How to prevent inheritance of a class in .NET?
Ans. Use the keyword NotInheritable in VB.NET and sealed in C#.

Q67. What is the purpose of the MustInherit keyword in VB.NET?
Ans. MustInherit keyword in VB.NET is used to create an abstract class.

Q68. What is the access modifier of a member function of in an Interface created in .NET?
Ans. It is always public, we cant use any other modifier other than the public modifier for the member functions of an Interface.

Q69. What does the virtual keyword in C# mean?
Ans. The virtual keyword signifies that the method and property may be overridden.

Q70. How to create a new unique ID for a control?
Ans. ControlName.ID = “ControlName” + Guid.NewGuid().ToString(); //Make use of the Guid class

Q71A. What is a HashTable in .NET?
Ans. A Hashtable is an object that implements the IDictionary interface, and can be used to store key value pairs. The key may be used as the index to access the values for that index.

Q71B. What is an ArrayList in .NET?
Ans. Arraylist object is used to store a list of values in the form of a list, such that the size of the arraylist can be increased and decreased dynamically, and moreover, it may hold items of different types. Items in an arraylist may be accessed using an index.

Q72. What is the value of the first item in an Enum? 0 or 1?
Ans. 0

Q73. Can we achieve operator overloading in VB.NET?
Ans. Yes, it is supported in the .NET 2.0 version, the “operator” keyword is used.

Q74. What is the use of Finalize method in .NET?
Ans. .NET Garbage collector performs all the clean up activity of the managed objects, and so the finalize method is usually used to free up the unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc.

Q75. How do you save all the data in a dataset in .NET?
Ans. Use the AcceptChanges method which commits all the changes made to the dataset since last time Acceptchanges was performed.

Q76. Is there a way to suppress the finalize process inside the garbage collector forcibly in .NET?
Ans. Use the GC.SuppressFinalize() method.

Q77. What is the use of the dispose() method in .NET?
Ans. The Dispose method in .NET belongs to IDisposable interface and it is best used to release unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc from the memory. Its performance is better than the finalize() method.

Q78. Is it possible to have have different access modifiers on the get and set methods of a property in .NET?
Ans. No we can not have different modifiers of a common property, which means that if the access modifier of a property’s get method is protected, and it must be protected for the set method as well.

Q79. In .NET, is it possible for two catch blocks to be executed in one go?
Ans. This is NOT possible because once the correct catch block is executed then the code flow goes to the finally block.

Q80. Is there any difference between System.String and System.StringBuilder classes?
Ans. System.String is immutable by nature whereas System.StringBuilder can have a mutable string in which plenty of processes may be performed.

Share/Save/Bookmark

 

30 simple Java questions

Category: JAVA Questions    |    5 views    |    Add a Comment
  1. How could Java classes direct program messages to the system console, but error messages, say to a file?

    The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:

    Stream st =  new Stream (new   FileOutputStream ("techinterviews_com.txt")); System.setErr(st); System.setOut(st);
  2. What’s the difference between an interface and an abstract class?

    An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

  3. Why would you use a synchronized block vs. synchronized method?

    Synchronized blocks place locks for shorter periods than synchronized methods.

  4. Explain the usage of the keyword transient?

    This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

  5. How can you force garbage collection?

    You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

  6. How do you know if an explicit object casting is needed?

    If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example:

    Object a;Customer b; b = (Customer) a;

    When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

  7. What’s the difference between the methods sleep() and wait()

    The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

  8. Can you write a Java class that could be used both as an applet as well as an application?

    Yes. Add a main() method to the applet.

  9. What’s the difference between constructors and other methods?

    Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

  10. Can you call one constructor from another if a class has multiple constructors

    Yes. Use this() syntax.

  11. Explain the usage of Java packages.

    This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

  12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?

    You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:/dev/com.xyz.hr.Employee.java. In this case, you’d need to add c:/dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:
    c:\>java com.xyz.hr.Employee

  13. What’s the difference between J2SDK 1.5 and J2SDK 5.0?

    There’s no difference, Sun Microsystems just re-branded this version.

  14. What would you use to compare two String variables - the operator == or the method equals()?

    I’d use the method equals() to compare the values of the Strings and the = = to check if two variables point at the same instance of a String object.

  15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

    A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first.

  16. Can an inner class declared inside of a method access local variables of this method?

    It’s possible if these variables are final.

  17. What can go wrong if you replace && with & in the following code:
    String a=null; if (a!=null && a.length()>10) {...}

    A single ampersand here would lead to a NullPointerException.

  18. What’s the main difference between a Vector and an ArrayList

    Java Vector class is internally synchronized and ArrayList is not.

  19. When should the method invokeLater()be used?

    This method is used to ensure that Swing components are updated through the event-dispatching thread.

  20. How can a subclass call a method or a constructor defined in a superclass?

    Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.

  21. What’s the difference between a queue and a stack?

    Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.

  22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?

    Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.

  23. What comes to mind when you hear about a young generation in Java?

    Garbage collection.

  24. What comes to mind when someone mentions a shallow copy in Java?

    Object cloning.

  25. If you’re overriding the method equals() of an object, which other method you might also consider?

    hashCode()

  26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?

    ArrayList

  27. How would you make a copy of an entire Java object with its state?

    Have this class implement Cloneable interface and call its method clone().

  28. How can you minimize the need of garbage collection and make the memory use more effective?

    Use object pooling and weak object references.

  29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?

    If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.

  30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?

    You do not need to specify any access level, and Java will use a default package access level.

Share/Save/Bookmark

 

DBA Interview Questions

Category: Database Questions    |    3 views    |    Add a Comment

- Why is a UNION ALL faster than a UNION?
- What are some advantages to using Oracle’s CREATE DATABASE statement to create a new database manually?
- What are three rules of thumb to create good passwords? How would a DBA enforce those rules in Oracle? What business challenges might you encounter?
- Describe the Oracle Wait Interface, how it works, and what it provides. What are some limitations? What do the db_file_sequential_read and db_file_scattered_read events indicate?
- How do you return the top-N results of a query in Oracle? Why doesn’t the obvious method work?
- Can Oracle’s Data Guard be used on Standard Edition, and if so how? How can you test that the standby database is in sync?
- What is a database link? What is the difference between a public and a private database link? What is a fixed user database link?The database interview answers are all listed on Database Journal Web site.

Share/Save/Bookmark

 

Introduction to Java Access Modifiers

Category: JAVA Questions    |    5 views    |    Add a Comment

Java Access Specifiers

    The access to classes, constructors, methods and fields are regulated using access modifiers i.e. a class can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible.

Java provides a number  of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes. A member has package or default accessibility when no accessibility modifier is specified.

Access Modifiers

1. private2. protected

3. default

4. public

public access modifier

   Fields, methods and constructors declared public (least restrictive) within a public class are visible to any class in the Java program, whether these classes are in the same package or in another package.

private access modifier

   The private (most restrictive) fields or methods cannot be used for classes and Interfaces. It also cannot be used for fields and methods within an interface. Fields, methods or constructors declared private are strictly controlled, which means they cannot be accesses by anywhere outside the enclosing class. A standard design strategy is to make all fields private and provide public getter methods for them.

protected access modifier

   The protected fields or methods cannot be used for classes and Interfaces. It also cannot be used for fields and methods within an interface. Fields, methods and constructors declared protected in a superclass can be accessed only by subclasses in other packages. Classes in the same package can also access protected fields, methods and constructors as well, even if they are not a subclass of the protected member’s class.

default access modifier

   Java provides a default specifier which is used when no access modifier is present. Any class, field, method or constructor that has no declared access modifier is accessible only by classes in the same package. The default modifier is not used for fields and methods within an interface.

      Below is a program to demonstrate the use of public, private, protected and default access modifiers while accessing fields and methods. The output of each of these java files depict the Java access specifiers.

      The first class is SubclassInSamePackage.java which is present in pckage1 package. This java file contains the Base class and a subclass within the enclosing class that belongs to the same class as shown below.

Output

Value of x is : 10

Value of x is : 20

Value of z is : 10

Value of z is : 30

Value of x is : 10

Value of x is : 20

      The second class is SubClassInDifferentPackage.java which is present in a different package then the first one. This java class extends First class (SubclassInSamePackage.java).

Output

Value of x is : 10

Value of x is : 30

Value of z is : 10

      The third class is ClassInDifferentPackage.java which is present in a different package then the first one.

Output

Value of x is : 10

Value of x is : 30

Share/Save/Bookmark