Tamil cinema News,Videos,Songs,Photos and Tailers :: Tamil Cinema Bazaar

Pages

Infolinks In Text Ads

Showing posts with label QandA. Show all posts
Showing posts with label QandA. Show all posts

Wednesday, 28 December 2011

Freshers Walk-In at DCKAP Technologies Chennai - BE / B.Tech / MCA : 2009 / 2010 / 2011 Passout

DCKAP Technologies (www.dckap.com)

(Freshers) Walk-In : BE / B.Tech / MCA : 2009 / 2010 / 2011 Passout @ Chennai

Job Position : Software Engineer - Trainee

Job Category : IT / Software

Walk-In Location : Chennai, Tamilnadu

Job Location : Chennai, Tamilnadu

Desired Qualification :
• BE / B.Tech / MCA
• 2009/2010/2011 passouts
• Aggregate of 65%

Desired Experience : 0 Years

Job Description :

• DCKAP is on the lookout for bright engineering graduates/postgraduates for "Software Engineer-Trainee" position.
• Yes! We are recruiting fresh talents and the talent acquisition team at DCKAP is calling new talents.
• BE/B.TECH/M.C.A Freshers (2009/2010/2011 passouts) with an aggregate of 65% may WALK IN WITH A COPY OF THE RESUME and we will walk you through the process!
• Selected candidates will be trained in latest technologies and deployed to work for our international projects.
• So come and join us to discover your skills and make a grand entry into the IT industry.

Please Carry (mandatory) :

• Updated Resume Copy
• A printout of this ChetanaS job posting
• Photo ID proof

Note: You can mention the reference as 'ChetanaS'.

Walk-In Date : On 7th & 8th January 2012 : 10.00 AM to 3.30 PM

Walk-In Venue :
DCKAP Technologies,
L-76 A, L Block, 21st Street,
Anna Nagar (East)
Chennai

How to reach: Anna Nagar Chinthamani Signal->Towards Valiammal School gate/Balaji Bhavan hotel->Move further straight ->Spencer’s daily to your left->Take the road to the opposite of Spencer’s daily ->End of the road to your left you see Kala’s Kalalaya/Mervin Nook Building->Take the left adjacent road and to your right you see DCKAP Technologies

Contact Person : Gowthami S (HR)

Contact Number : +91-44-26633535

Friday, 4 November 2011

Partial Classes, Structs and Methods in C# | Place 4 Search

C# Interview Questions on partial classes, structs and methods. 

 Place 4 Search
What is a partial class. Give an example?
A partial class is a class whose definition is present in 2 or more files. Each source file contains a section of the class, and all parts are combined when the application is compiled. To split a class definition, use the partial keyword as shown in the example below. Student class is split into 2 parts. The first part defines the study() method and the second part defines the Play() method. When we compile this program both the parts will be combined and compiled. Note that both the parts uses partial keyword and public access modifier.
Place 4 Search
using System;
namespace PartialClass
{
  public partial class Student
  {
    public void Study()
    {
      Console.WriteLine("I am studying");
    }
  }
  public partial class Student
  {
    public void Play()
    {
      Console.WriteLine("I am Playing");
    }
  }
  public class Demo
  {
    public static void Main()
    {
      Student StudentObject = new Student();
      StudentObject.Study();
      StudentObject.Play();
    }
  }
}

Place 4 Search
It is very important to keep the following points in mind when creating partial classes.
1. All the parts must use the partial keyword.
2. All the parts must be available at compile time to form the final class.
3. All the parts must have the same access modifiers - public, private, protected etc.
4. Any class members declared in a partial definition are available to all the other parts.
5. The final class is the combination of all the parts at compile time.
Place 4 Search
What are the advantages of using partial classes?
1. When working on large projects, spreading a class over separate files enables multiple programmers to work on it at the same time.
Place 4 Search
2. When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when it creates Windows Forms, Web service wrapper code, and so on. You can create code that uses these classes without having to modify the file created by Visual Studio.
Place 4 Search
Is it possible to create partial structs, interfaces and methods?
Yes, it is possible to create partial structs, interfaces and methods. We can create partial structs, interfaces and methods the same way as we create partial classes.
Place 4 Search
Will the following code compile?
using System;
namespace PartialClass
{
  public partial class Student
  {
    public void Study()
    {
      Console.WriteLine("I am studying");
    }
  }
  public abstract partial class Student
  {
    public void Play()
    {
      Console.WriteLine("I am Playing");
    }
  }
  public class Demo
  {
    public static void Main()
    {
      Student StudentObject = new Student();
    }
  }
}

Place 4 Search
No, a compile time error will be generated stating "Cannot create an instance of the abstract class or interface "PartialClass.Student". This is because, if any part is declared abstract, then the whole class becomes abstract. Similarly if any part is declared sealed, then the whole class becomes sealed and if any part declares a base class, then the whole class inherits that base class.

Can you create partial delegates and enumerations?
No, you cannot create partial delegates and enumerations.

Can different parts of a partial class inherit from different interfaces?
Yes, different parts of a partial class can inherit from different interfaces.
Place 4 Search
Can you specify nested classes as partial classes?
Yes, nested classes can be specified as partial classes even if the containing class is not partial. An example is shown below.
Place 4 Search
class ContainerClass
{
  public partial class Nested
  {
    void Test1() { }
  }
  public partial class Nested
  {
    void Test2() { }
  }
}

Place 4 Search
How do you create partial methods?
To create a partial method we create the declaration of the method in one part of the partial class and implementation in the other part of the partial class. The implementation is optional. If the implementation is not provided, then the method and all the calls to the method are removed at compile time. Therefore, any code in the partial class can freely use a partial method, even if the implementation is not supplied. No compile-time or run-time errors will result if the method is called but not implemented. In summary a partial method declaration consists of two parts. The definition, and the implementation. These may be in separate parts of a partial class, or in the same part. If there is no implementation declaration, then the compiler optimizes away both the defining declaration and all calls to the method.
Place 4 Search
The following are the points to keep in mind when creating partial methods.
1. Partial method declarations must begin partial keyword.
2. The return type of a partial method must be void.
3. Partial methods can have ref but not out parameters.
4. Partial methods are implicitly private, and therefore they cannot be virtual.
5. Partial methods cannot be extern, because the presence of the body determines whether they are defining or implementing.
Place 4 Search
What is the use of partial methods?
Partial methods can be used to customize generated code. They allow for a method name and signature to be reserved, so that generated code can call the method but the developer can decide whether to implement the method. Much like partial classes, partial methods enable code created by a code generator and code created by a human developer to work together without run-time costs.
Place 4 Search

Difference between EXE and DLL | Place 4 Search

Difference between EXE and DLL

 Place 4 Search
1. .EXE is an executable file and can run by itself as an application, where as .DLL is usullay consumed by a .EXE or by another .DLL and we cannot run or execute .DLL directly.

2. For example, In .NET, compiling a Console Application or a Windows Application generates .EXE, where as compiling a Class Library Project or an ASP.NET web application generates .DLL. In .NET framework, both .EXE and .DLL are called as assemblies.

3. .DLL's can be reused, where as .EXE's cannot be reused.

4. .EXE stands for executable, and .DLL stands for Dynamic Link Library
 

Place 4 Search

New Features Introduced in c# 4.0 | Place 4 Search

What are the new features introduced in c# 4.0?
Place 4 Search
This is very commonly asked c# interview question. This question is basically asked to check, if you are passionate about catching up with latest technological advancements. The list below shows a few of the new features introduced in c# 4.0. If you are aware of any other new features, please submit those using the from at the end of this post.

1. Optional and Named Parameters
2. COM Interoperability Enhancements
3. Covariance and Contravariance
4. Dynamic Type Introduction

Place 4 Search

Monday, 26 September 2011

Basic and Important Dot .Net Interview Questions and Answers


Basic and Important Dot .Net Interview Questions and Answers
  1. What is an application server?
    As defined in Wikipedia, an application server is a software engine that delivers applications to client computers or devices. The application server runs your server code. Some well known application servers are IIS (Microsoft), WebLogic Server (BEA), JBoss (Red Hat), WebSphere (IBM).
  2. What is a base class and derived class?
    A class is a template for creating an object. The class from which other classes derive fundamental functionality is called a base class. For e.g. If Class Y derives from Class X, then Class X is a base class.

    The class which derives functionality from a base class is called a derived class. If Class Y derives from Class X, then Class Y is a derived class.
  3. What is an extender class?
    An extender class allows you to extend the functionality of an existing control. It is used in Windows forms applications to add properties to controls.

    A demonstration of extender classes can be found over here.
  4. What is inheritance?
    Inheritance represents the relationship between two classes where one type derives functionality from a second type and then extends it by adding new methods, properties, events, fields and constants.

    C# support two types of inheritance:
    · Implementation inheritance
    · Interface inheritance
  5. What is implementation and interface inheritance?
    When a class (type) is derived from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance.

    When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance.

    In general Classes can be derived from another class, hence support Implementation inheritance. At the same time Classes can also be derived from one or more interfaces. Hence they support Interface inheritance.
    Source: Exforsys.
  6. What is inheritance hierarchy?
    The class which derives functionality from a base class is called a derived class. A derived class can also act as a base class for another class. Thus it is possible to create a tree-like structure that illustrates the relationship between all related classes. This structure is known as the inheritance hierarchy.
  7. How do you prevent a class from being inherited?
    In VB.NET you use the NotInheritable modifier to prevent programmers from using the class as a base class. In C#, use the sealed keyword.
  8. When should you use inheritance?
Inheritance is a useful programming concept, but it is easy to use inappropriately. Often interfaces do the job better. This topic and When to Use Interfaces help you understand when each approach should be used.Inheritance is a good choice when:
                                                               i.      Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship.
                                                             ii.      You can reuse code from the base classes.
                                                            iii.      You need to apply the same class and methods to different data types.
                                                           iv.      The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels.
                                                            v.      You want to make global changes to derived classes by changing a base class.
  1. Define Overriding?
    Overriding is a concept where a method in a derived class uses the same name, return type, and arguments as a method in its base class. In other words, if the derived class contains its own implementation of the method rather than using the method in the base class, the process is called overriding.
  2. Can you use multiple inheritance in .NET?
    .NET supports only single inheritance. However the purpose is accomplished using multiple interfaces.
  3. Why don’t we have multiple inheritance in .NET?
    There are several reasons for this. In simple words, the efforts are more, benefits are less. Different languages have different implementation requirements of multiple inheritance. So in order to implement multiple inheritance, we need to study the implementation aspects of all the languages that are CLR compliant and then implement a common methodology of implementing it. This is too much of efforts. Moreover multiple interface inheritance very much covers the benefits that multiple inheritance has.
  4. What is an Interface?
    An interface is a standard or contract that contains only the signatures of methods or events. The implementation is done in the class that inherits from this interface. Interfaces are primarily used to set a common standard or contract.
  5. When should you use abstract class vs interface or What is the difference between an abstract class and interface?
    I would suggest you to read this. There is a good comparison given over here.
  6. What are events and delegates?
    An event is a message sent by a control to notify the occurrence of an action. However it is not known which object receives the event. For this reason, .NET provides a special type called Delegate which acts as an intermediary between the sender object and receiver object.
  7. What is business logic?
    It is the functionality which handles the exchange of information between database and a user interface.
  8. What is a component?
    Component is a group of logically related classes and methods. A component is a class that implements the IComponent interface or uses a class that implements IComponent interface.
  9. What is a control?
    A control is a component that provides user-interface (UI) capabilities.
  10. What are the differences between a control and a component?
    The differences can be studied over here.
  11. What are design patterns?
    Design patterns are common solutions to common design problems.
  12. What is a connection pool?
    A connection pool is a ‘collection of connections’ which are shared between the clients requesting one. Once the connection is closed, it returns back to the pool. This allows the connections to be reused.
  13. What is a flat file?
    A flat file is the name given to text, which can be read or written only sequentially.
  14. What are functional and non-functional requirements?
    Functional requirements defines the behavior of a system whereas non-functional requirements specify how the system should behave; in other words they specify the quality requirements and judge the behavior of a system.
    E.g.
    Functional - Display a chart which shows the maximum number of products sold in a region.
    Non-functional – The data presented in the chart must be updated every 5 minutes.
  15. What is the global assembly cache (GAC)?
    GAC is a machine-wide cache of assemblies that allows .NET applications to share libraries. GAC solves some of the problems associated with dll’s (DLL Hell).
  16. What is a stack? What is a heap? Give the differences between the two?
    Stack is a place in the memory where value types are stored. Heap is a place in the memory where the reference types are stored. Check this link for the differences.
  17. What is instrumentation?
    It is the ability to monitor an application so that information about the application’s progress, performance and status can be captured and reported.
  18. What is code review?
    The process of examining the source code generally through a peer, to verify it against best practices.
  19. What is logging?
    Logging is the process of persisting information about the status of an application.
  20. What are mock-ups?
    Mock-ups are a set of designs in the form of screens, diagrams, snapshots etc., that helps verify the design and acquire feedback about the application’s requirements and use cases, at an early stage of the design process.
  21. What is a Form?
    A form is a representation of any window displayed in your application. Form can be used to create standard, borderless, floating, modal windows.
  22. What is a multiple-document interface(MDI)?
    A user interface container that enables a user to work with more than one document at a time. E.g. Microsoft Excel.
  23. What is a single-document interface (SDI) ?
    A user interface that is created to manage graphical user interfaces and controls into single windows. E.g. Microsoft Word
  24. What is BLOB ?
    A BLOB (binary large object) is a large item such as an image or an exe represented in binary form.
  25. What is ClickOnce?
    ClickOnce is a new deployment technology that allows you to create and publish self-updating applications that can be installed and run with minimal user interaction.
  26. What is object role modeling (ORM) ?
    It is a logical model for designing and querying database models. There are various ORM tools in the market like CaseTalk, Microsoft Visio for Enterprise Architects, Infagon etc.
  27. What is a private assembly?
    A private assembly is local to the installation directory of an application and is used only by that application.
  28. What is a shared assembly?
    A shared assembly is kept in the global assembly cache (GAC) and can be used by one or more applications on a machine.
  29. What is the difference between user and custom controls?
    User controls are easier to create whereas custom controls require extra effort.
    User controls are used when the layout is static whereas custom controls are used in dynamic layouts.
    A user control cannot be added to the toolbox whereas a custom control can be.
    A separate copy of a user control is required in every application that uses it whereas since custom controls are stored in the GAC, only a single copy can be used by all applications.
  30. Where do custom controls reside?
    In the global assembly cache (GAC).
  31. What is a third-party control ?
    A third-party control is one that is not created by the owners of a project. They are usually used to save time and resources and reuse the functionality developed by others (third-party).
  32. What is a binary formatter?
    Binary formatter is used to serialize and deserialize an object in binary format.
  33. What is Boxing/Unboxing?
    Boxing is used to convert value types to object.
    E.g. int x = 1;
    object obj = x ;
    Unboxing is used to convert the object back to the value type.
    E.g. int y = (int)obj;
    Boxing/unboxing is quiet an expensive operation.
  34. What is a COM Callable Wrapper (CCW)?
    CCW is a wrapper created by the common language runtime(CLR) that enables COM components to access .NET objects.
  35. What is a Runtime Callable Wrapper (RCW)?
    RCW is a wrapper created by the common language runtime(CLR) to enable .NET components to call COM components.
  36. What is a digital signature?
    A digital signature is an electronic signature used to verify/gurantee the identity of the individual who is sending the message.
  37. What is garbage collection?
    Garbage collection is the process of managing the allocation and release of memory in your applications. Read this article for more information.
  38. What is globalization?
    Globalization is the process of customizing applications that support multiple cultures and regions.
  39. What is localization?
    Localization is the process of customizing applications that support a given culture and regions.

Sunday, 25 September 2011

Basic Java - Interview Questions and Answers - (1 - 20 of 80)


1. What is the difference between a constructor and a method?

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

2. What is the purpose of garbage collection in Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

3. Describe synchronization in respect to multithreading.

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources.
Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

4. What is an abstract class?

Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie. you may not call its constructor), abstract class may contain static data.
Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.


5. What is the difference between an Interface and an Abstract class?

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.
An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

6. Explain different way of using thread?

The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance, the only interface can help.

7. What is an Iterator?

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn.
Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.

8. State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.

public: Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature. This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
What you get by default ie, without any access modifier (ie, public private or protected). It means that it is visible to all within a particular package.

9. What is static in java?

Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object.
A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.


10. What is final class?

A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

11. What if the main() method is declared as private?

The program compiles properly but at runtime it will give "main() method not public." message.


12. What if the static modifier is removed from the signature of the main() method?

Program compiles. But at runtime throws an error "NoSuchMethodError".

13. What if I write static public void instead of public static void?

Program compiles and runs properly.


14. What if I do not provide the String array as the argument to the method?

Program compiles but throws a runtime error "NoSuchMethodError".

15. What is the first argument of the String array in main() method?

The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.

16. If I do not provide any arguments on the command line, then the String array of main() method will be empty or null?

It is empty. But not null.

17. How can one prove that the array is not null but empty using one line of code?

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.

18. What environment variables do I need to set on my machine in order to be able to run Java programs?

CLASSPATH and PATH are the two variables.

19. Can an application have multiple classes having main() method?

Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned.
Hence there is not conflict amongst the multiple classes having main() method.

20. Can I have multiple main() methods in the same class?

No the program fails to compile. The compiler says that the main() method is already defined in the class.

Basic Java - Interview Questions and Answers - (21 - 40 of 80)


21. Do I need to import java.lang package any time? Why ?

No. It is by default loaded internally by the JVM.

22. Can I import same package/class twice? Will the JVM load the package twice at runtime?

One can import the same package or same class multiple times. Neither compiler nor JVM complains about it. And the JVM will internally load the class only once no matter how many times you import the same class.

23. What are Checked and UnChecked Exception?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown.
Example: IOException thrown by java.io.FileInputStream's read() method·
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown.
Example: StringIndexOutOfBoundsException thrown by String's charAt() method· Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

24. What is Overriding?

When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.
When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

25. Are the imports checked for validity at compile time? Example: will the code containing an import such as java.lang.ABCD compile?

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying, can not resolve symbol
symbol : class ABCD
location: package io
import java.io.ABCD;

26. Does importing a package imports the subpackages as well? Example: Does importing com.MyTest.* also import com.MyTest.UnitTests.*?

No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.

27. What is the difference between declaring a variable and defining a variable?

In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.
Example: String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.

28. What is the default value of an object reference declared as an instance variable?

The default value will be null unless we define it explicitly.

29. Can a top level class be private or protected?

No. A top level class cannot be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.
If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.

30. What type of parameter passing does Java support?

In Java the arguments are always passed by value.

31. Primitive data types are passed by reference or pass by value?

Primitive data types are passed by value.


32. Objects are passed by value or by reference?

Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object.


33. What is serialization?

Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

34. How do I serialize an object to a file?

The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file.


35. Which methods of Serializable interface should I implement?

The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.

36. How can I customize the seralization process? i.e. how can one have a control over the serialization process?

Yes it is possible to have control over serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal.
You should implement these methods and write the logic for customizing the serialization process.

37. What is the common usage of serialization?

Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.

38. What is Externalizable interface?

Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism.
Thus if your class implements this interface, you can customize the serialization process by implementing these methods.

39. When you serialize an object, what happens to the object references included in the object?

The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process.
Thus when an object is serialized, all the included objects are also serialized alongwith the original obect.

40. What one should take care of while serializing the object?

One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.

Basic Java - Interview Questions and Answers - (41 - 60 of 80)


41. What happens to the static fields of a class during serialization?

There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are
1. Serialization ignores static fields, because they are not part of ay particular state state.
2. Base class fields are only hendled if the base class itself is serializable.
3. Transient fields.


42. Does Java provide any construct to find out the size of an object?

No, there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java.


43. What are wrapper classes?

Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes.
They are example: Integer, Character, Double etc.

44. Why do we need wrapper classes?

It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also.
Because of these resons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.


45. What are checked exceptions?

Checked exception are those which the Java compiler forces you to catch.
Example: IOException are checked exceptions.

46. What are runtime exceptions?

Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.

47. What is the difference between error and an exception?

An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error.
These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. Example: FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference.
In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).

48. How to create custom exceptions?

Your class should extend class Exception, or some more specific type thereof.

49. If I want an object of my class to be thrown as an exception object, what should I do?

The class should extend from Exception class. Or you can extend your class from some more precise exception type also.

50. If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?

One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.

51. How does an exception permeate through the code?

An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapped in a try block followed by one or more catch blocks, a search is made for matching catch block. If a matching type is found then that block will be invoked. If a matching type is not found then the exception moves up the method stack and reaches the caller method.
Same procedure is repeated if the caller method is included in a try catch block. This process continues until a catch block handling the appropriate type of exception is found. If it does not find such a block then finally the program terminates.

52. What are the different ways to handle exceptions?

There are two ways to handle exceptions,
1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and
2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions.


53. Is it necessary that each try block must be followed by a catch block?

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.

54. If I write return at the end of the try block, will the finally block still execute?

Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.

55. If I write System.exit(0); at the end of the try block, will the finally block still execute?

No. In this case the finally block will not execute because when you say System.exit(0); the control immediately goes out of the program, and thus finally never executes.

56. How are Observer and Observable used?

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.

57. What is synchronization and why is it important?

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources.
Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.


58. How does Java handle integer overflows and underflows?

It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

59. Does garbage collection guarantee that a program will not run out of memory?

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

60. What is the difference between preemptive scheduling and time slicing?

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence.
Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

Basic Java - Interview Questions and Answers - (61 - 80 of 80)


61. When a thread is created and started, what is its initial state?

A thread is in the ready state after it has been created and started.

62. What is the purpose of finalization?

The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

63. What is the Locale class?

The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

64. What is the difference between a while statement and a do statement?

A while statement checks at the beginning of a loop to see whether the next loop iteration should occur.
A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

65. What is the difference between static and non-static variables?

A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

66. How are this() and super() used with constructors?

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

67. What is daemon thread and which method is used to create the daemon thread?

Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system.setDaemon method is used to create a daemon thread.

68. Can applets communicate with each other?

At this point in time applets may communicate with other applets running in the same virtual machine. If the applets are of the same class, they can communicate via shared static variables. If the applets are of different classes, then each will need a reference to the same class with static variables. In any case the basic idea is to pass the information back and forth through a static variable.
An applet can also get references to all other applets on the same page using the getApplets() method of java.applet.AppletContext. Once you get the reference to an applet, you can communicate with it by using its public members.
It is conceivable to have applets in different virtual machines that talk to a server somewhere on the Internet and store any data that needs to be serialized there. Then, when another applet needs this data, it could connect to this same server. Implementing this is non-trivial.

69. What are the steps in the JDBC connection?

While making a JDBC connection we go through the following steps :

Step 1 : Register the database driver by using :
Class.forName(\" driver classs for that specific database\" );
Step 2 : Now create a database connection using :
Connection con = DriverManager.getConnection(url,username,password);
Step 3: Now Create a query using :
Statement stmt = Connection.Statement(\"select * from TABLE NAME\");
Step 4 : Exceute the query :
stmt.exceuteUpdate();
 
70. How does a try statement determine which catch clause should be used to handle an exception?

When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exceptionis executed. The remaining catch clauses are ignored.

71. Can an unreachable object become reachable again?

An unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.

72. What method must be implemented by all threads?

All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.

73. What are synchronized methods and synchronized statements?

Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class.
Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

74. What is Externalizable?

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in).

75. What modifiers are allowed for methods in an Interface?

Only public and abstract modifiers are allowed for methods in interfaces.

76. What are some alternatives to inheritance?

Delegation is an alternative to inheritance.
Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn't force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

77. What does it mean that a method or field is "static"?

Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class.
Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System.out.println() work out is a static field in the java.lang.System class.

78. What is the difference between preemptive scheduling and time slicing?

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks.
The scheduler then determines which task should execute next, based on priority and other factors.

79. What is the catch or declare rule for method declarations?

If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.

80. Is Empty .java file a valid source file?

Yes. An empty .java file is a perfectly valid source file.

Blog Archive