+ All Categories
Home > Documents > 7111095-Java-Interview-Questions-6

7111095-Java-Interview-Questions-6

Date post: 09-Apr-2018
Category:
Upload: sunil-soni
View: 218 times
Download: 0 times
Share this document with a friend
36
JAVA Questions 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? Y ou can’t force GC, but could request it by calling S ystem.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 .
Transcript
Page 1: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 1/36

JAVA Questions

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 thevariable err that represents the standard error device. By default, they both pointat the system console. This how the standard output could be re-directed:

Stream st =new Stream (newFileOutputStream ("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 aninterface. With abstract classes, you have to inherit your class from it and Javadoes not allow multiple inheritance. On the other hand, you can implementmultiple 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 beserialized 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 notguarantee 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 needto 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.

Page 2: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 2/36

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

The code sleep(1000); puts thread aside for exactly one second. The codewait(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 alsohelps resolve naming conflicts when different packages have classes with thesame 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 theCLASSPATH 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 classcontains the method main(), you could test it from a command prompt window asfollows:

c:\>java com.xyz.hr.Employee13. 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()?

Page 3: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 3/36

I’d use the method equals() to compare the values of the Strings and the = = tocheck 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:18.String a=null;19.if (a!=null && a.length()>10)

{...}

A single ampersand here would lead to a NullPointerException.

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

Java Vector class is internally synchronized and ArrayList is not.

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

This method is used to ensure that Swing components are updated through the

event-dispatching thread.

22. 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 thesuperclass, just write super(); in the first line of the subclass’s constructor.

23. 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.

24. You can create an abstract class that contains only abstract methods. On theother 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 casethe interface is your only option.

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

Page 4: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 4/36

Garbage collection.

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

Object cloning.

27. If you’re overriding the method equals() of an object, which other method

you might also consider?

hashCode()

28. 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

29. 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().

30. How can you minimize the need of garbage collection and make the memory

use more effective?

Use object pooling and weak object references.

31. 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 classesyou can use the Observer interface.

32. 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 packageaccess level.

Page 5: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 5/36

SQL Database interview questions

SQLSQL is an English like language consisting of commands to store, retrieve, maintain &regulate access to your database.

SQL*PlusSQL*Plus is an application that recognizes & executes SQL commands & specializedSQL*Plus commands that can customize reports, provide help & edit facility & maintainsystem variables.

 NVL NVL : Null value function converts a null value to a non-null value for the purpose of evaluating an expression. Numeric Functions accept numeric I/P & return numericvalues. They are MOD, SQRT, ROUND, TRUNC & POWER.

Date FunctionsDate Functions are ADD_MONTHS, LAST_DAY, NEXT_DAY, MONTHS_BETWEEN& SYSDATE.

Character Functions

Character Functions are INITCAP, UPPER, LOWER, SUBSTR & LENGTH. Additionalfunctions are GREATEST & LEAST. Group Functions returns results based upon groupsof rows rather than one result per row, use group functions. They are AVG, COUNT,MAX, MIN & SUM.

TTITLE & BTITLETTITLE & BTITLE are commands to control report headings & footers.

COLUMNCOLUMN command define column headings & format data values.

BREAK BREAK command clarify reports by suppressing repeated values, skipping lines &allowing for controlled break points.

COMPUTEcommand control computations on subsets created by the BREAK command.

Page 6: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 6/36

SETSET command changes the system variables affecting the report environment.

SPOOLSPOOL command creates a print file of the report.

JOINJOIN is the form of SELECT command that combines info from two or more tables.Types of Joins are Simple (Equijoin & Non-Equijoin), Outer & Self join.Equijoin returns rows from two or more tables joined together based upon a equalitycondition in the WHERE clause. Non-Equijoin returns rows from two or more tables based upon a relationship other thanthe equality condition in the WHERE clause.Outer Join combines two or more tables returning those rows from one table that have no

direct match in the other table.Self Join joins a table to itself as though it were two separate tables.

UnionUnion is the product of two or more tables.

IntersectIntersect is the product of two tables listing only the matching rows.

MinusMinus is the product of two tables listing only the non-matching rows.

Correlated SubqueryCorrelated Subquery is a subquery that is evaluated once for each row processed by the parent statement. Parent statement can be Select, Update or Delete. Use CRSQ to answer multipart questions whose answer depends on the value in each row processed by parentstatement.

Multiple columnsMultiple columns can be returned from a Nested Subquery.

Sequences

Sequences are used for generating sequence numbers without any overhead of locking.Drawback is that after generating a sequence number if the transaction is rolled back,then that sequence number is lost.

SynonymsSynonyms is the alias name for table, views, sequences & procedures and are created for reasons of Security and Convenience.Two levels are Public - created by DBA & accessible to all the users. Private - Accessible

Page 7: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 7/36

to creator only. Advantages are referencing without specifying the owner and Flexibilityto customize a more meaningful naming convention.

IndexesIndexes are optional structures associated with tables used to speed query execution

and/or guarantee uniqueness. Create an index if there are frequent retrieval of fewer than10-15% of the rows in a large table and columns are referenced frequently in the WHEREclause. Implied tradeoff is query speed vs. update speed. Oracle automatically updateindexes. Concatenated index max. is 16 columns.

Data typesMax. columns in a table is 255. Max. Char size is 255, Long is 64K & Number is 38digits.Cannot Query on a long column.Char, Varchar2 Max. size is 2000 & default is 1 byte. Number(p,s) p is precision range 1 to 38, s is scale -84 to 127.

Long Character data of variable length upto 2GB.Date Range from Jan 4712 BC to Dec 4712 AD.Raw Stores Binary data (Graphics Image & Digitized Sound). Max. is 255 bytes.Mslabel Binary format of an OS label. Used primarily with Trusted Oracle.

Order of SQL statement executionWhere clause, Group By clause, Having clause, Order By clause & Select.

TransactionTransaction is defined as all changes made to the database between successive commits.

CommitCommit is an event that attempts to make data in the database identical to the data in theform. It involves writing or posting data to the database and committing data to thedatabase. Forms check the validity of the data in fields and records during a commit.Validity check are uniqueness, consistency and db restrictions.

PostingPosting is an event that writes Inserts, Updates & Deletes in the forms to the database butnot committing these transactions to the database.

Rollback 

Rollback causes work in the current transaction to be undone.SavepointSavepoint is a point within a particular transaction to which you may rollback withoutrolling back the entire transaction.

Set TransactionSet Transaction is to establish properties for the current transaction.

Page 8: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 8/36

LockingLocking are mechanisms intended to prevent destructive interaction between usersaccessing data. Locks are used to achieve.

Consistency

Consistency : Assures users that the data they are changing or viewing is not changeduntil the are thro’ with it.

IntegrityAssures database data and structures reflects all changes made to them in the correctsequence. Locks ensure data integrity and maximum concurrent access to data. Commitstatement releases all locks. Types of locks are given below.Data Locks protects data i.e. Table or Row lock.Dictionary Locks protects the structure of database object i.e. ensures table’s structuredoes not change for the duration of the transaction.Internal Locks & Latches protects the internal database structures. They are automatic.

Exclusive Lock allows queries on locked table but no other activity is allowed.Share Lock allows concurrent queries but prohibits updates to the locked tables.Row Share allows concurrent access to the locked table but prohibits for a exclusive tablelock.Row Exclusive same as Row Share but prohibits locking in shared mode.Shared Row Exclusive locks the whole table and allows users to look at rows in the table but prohibit others from locking the table in share or updating them.Share Update are synonymous with Row Share.

Deadlock Deadlock is a unique situation in a multi user system that causes two or more users to

wait indefinitely for a locked resource. First user needs a resource locked by the seconduser and the second user needs a resource locked by the first user. To avoid dead locks,avoid using exclusive table lock and if using, use it in the same sequence and use Commitfrequently to release locks.

Mutating TableMutating Table is a table that is currently being modified by an Insert, Update or Deletestatement. Constraining Table is a table that a triggering statement might need to readeither directly for a SQL statement or indirectly for a declarative Referential Integrityconstraints. Pseudo Columns behaves like a column in a table but are not actually storedin the table. E.g. Currval, Nextval, Rowid, Rownum, Level etc.

SQL*Loader SQL*Loader is a product for moving data in external files into tables in an Oracledatabase. To load data from external files into an Oracle database, two types of inputmust be provided to SQL*Loader : the data itself and the control file. The control filedescribes the data to be loaded. It describes the Names and format of the data files,Specifications for loading data and the Data to be loaded (optional). Invoking the loader sqlload username/password controlfilename.

Page 9: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 9/36

HR Questions

1.  What is more important to you: the money or the work? Subscribe 

Money is always important, but the work is the most important. There is no better answer.

Latest Answer: I think Money is more important than Work, All are satisfied when getMore Money for Less work, But...Last Updated By Prasad  on June 23, 2007   (Answers: 12) Read / Answer

2.  What would your previous supervisor say your strongest point is? Subscribe 

There are numerous good possibilities: Loyalty, Energy, Positive attitude, Leadership,Team player, Expertise, Initiative, Patience, Hard work, Creativity, Problem solver 

Latest Answer: Dedication: willingness to go the extra mile to achieve excellence...Last Updated By Riya on August 25, 2006   (Answers: 2) Read / Answer

3.  Tell me about a problem you had with a supervisor? Subscribe Biggest trap of all. This is a test to see if you will speak ill of your boss. If you fall for itand tell about a problem with a former boss, you may well below the interview rightthere. Stay positi

Latest Answer: Hi,To add up a little humour, sayActually, it was he who was having problem's. I was just constantly...Last Updated By Bhaskar  on April 25, 2006   (Answers: 2) Read / Answer

4.  What has disappointed you about a job? Subscribe 

Don't get trivial or negative. Safe areas are few but can include: Not enough of achallenge. You were laid off in a reduction Company did not win a contract, which wouldhave given you more responsib

Read / Answer 

5.  Tell me about your ability to work under pressure? Subscribe 

You may say that you thrive under certain types of pressure. Give an example that relatesto the type of position applied for.

Latest Answer: It is one's personal tolerence power to handle the tens condition. To solveit or say handle it,you ...

Page 10: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 10/36

Last Updated By ganju on June 08, 2007   (Answers: 5) Read / Answer

6.  Do your skills match this job or another job more closely? Subscribe 

Probably this one. Do not give fuel to the suspicion that you may want another job morethan this one.

Latest Answer: I would try to utilise my skills according to the job given to me......Last Updated By kana on April 12, 2006   (Answers: 1) Read / Answer

7.  What motivates you to do your best on the job? Subscribe 

This is a personal trait that only you can say, but good examples are: Challenge,Achievement, Recognition

Latest Answer: perfection,confidence,patience are the thing me to motivate on the job...Last Updated By karthick  on May 12, 2006   (Answers: 3) Read / Answer

8.  Are you willing to work overtime? Nights? Weekends? Subscribe 

This is up to you. Be totally honest. How would you know you were successful on this job?

Latest Answer: If the project deadlined demand then yes. Do not show that its your culture to work overnights....Last Updated By Rahul  on January 14,

2007  (Answers: 2) Read / Answer

9.  Would you be willing to relocate if required? Subscribe 

You should be clear on this with your family prior to the interview if you think there is achance it may come up. Do not say yes just to get the job if the real answer is no. This cancreate a lot o

Latest Answer: yes of course....i would like to work in a different environment and after a couple of years i'l...

Last Updated By karthic on July 05, 2007   (Answers: 3) Read / Answer10.  Are you willing to put the interests of the organization ahead of 

your own?

Subscribe 

This is a straight loyalty and dedication question. Do not worry about the deep ethical and philosophical implications. Just say yes.

Latest Answer: : Yes, but in return I would expect the organization to take care of myneeds as an individual...Last Updated By Deepali on January 25,

2007  (Answers: 1) Read / Answer

Page 11: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 11/36

ORACLE Questions

RE: Which one is faster DELETE/TRUNCATE? Why?

Truncate table------------------1) Truncate table is DDL and can be run by the owner of the table.2) Can't Rollback the truncate table command.3) It release the space and re-set the high water mark in the segment.4) Selective record deletion is not possible with truncate table . i.e you can notspecifiy where condition in truncate table command.

Delete--------1) User with delete permission can delete records from the table.

2) Delete can be rollback.3) Does not release the occupied space in the segment.4) We can specifiy selective record deletion in delete i.e. delete from <table_name>where <condition>

 RE: difference between oracle 8i and 9i ?

 

There are many differences between oracle 8i and oracle 9i

(1) In oracle 8i default tablespace is dictonary managed while in 9i it is locally managed.

(2)Oracle 9i can support 512 PetaByte of data.

(3)Oracle can supprt 10,000 concurrent users.

(4)oracle 9i provides auto undo segment management.

and there a lot difference in oracle 9i and 8i as 9i Support RAC Concept.

Page 12: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 12/36

1. Undo Retention

2. Incremental level backup using export and import is not there in Oracle 9i

3. Lot of simplified scripts for RMAN backup and Recovery when compared to Oracle 8i

4. In Oracle 9i Rollback segments (undo) is managed automatically by Oracle.

: what is the difference between primary key, unique key, sorrougate key?

To answer your question its sufficient enough to understand their definitions.

Primary Key: A column in a table whose values uniquely identify the rows in thetable. A primary key value cannot be NULL.

Unique Key: Unique Keys are used to uniquely identify each row in an Oracle table.There can be one and only one row for each unique key value.

Surrogate Key: A system generated key with no business value. Usually implementedwith database generated sequences.

Primay Key Unique key

----------- ------------------

1.There is only one there may be more than 1Primary key for Unique Key in table1 table

2.It can contain It Can contain Null Value Null value

RE: What is stucture of Database

 

Oracle database usually contains one database and a single instance. But, Oracle 9i,10g RAC (Real Application Clusters) can have multiple instances to interact with a singledatabase for high availability.

Instance is non-persistent, memory based background processes and structures.

Database is persistent, disk based, data and control files

Page 13: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 13/36

what is normalization? what is the advantage of normalization (briefly)

The process of separating data into distinct, unique sets is called normalization. Thisis implemented to imorove the performance of the RDBMS, such as reduceces

redunbdancy of data and data inconsistency.

 Normalization is the process of removing redundant data from your tables in order toimprove storage efficiency, data integrity and scalability

Database normalization is a series of steps followed to obtain a database design thatallows for consistent storage and efficient access of data in a relational database.These steps reduce data redundancy and the risk of data becoming inconsistent

 Normalization is the process used to reduce the unnecessary repetetion of data i.e,redundant data.It is performed on the data which is redundant and makes the data in a

normalized format.It is of step-by-step processIstNotmal FormIIndNormalformIIIrdNormalformIVth Normalform or BoyceCodd Normal formBy perofmringthis we will get the data in the Normalized formati.,e from DBMS to RDBMS.

 Normalization is the process of organizing data in a database. This includes creatingtables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating twofactors: redundancy and inconsistent dependency.Redundant data wastes disk space and creates maintenance problems. If data that exists in

more than one place must be changed, the data must be changed in exactly the same wayin all locations. A customer address change is much easier to implement if that data isstored only in the Customers table and nowhere else in the database.What is an "inconsistent dependency"? While it is intuitive for a user to look in theCustomers table for the address of a particular customer, it may not make sense to look there for the salary of the employee who calls on that customer. The employee's salary isrelated to, or dependent on, the employee and thus should be moved to the Employeestable. Inconsistent dependencies can make data difficult to access; the path to find thedata may be missing or broken.There are a few rules for database normalization. Each rule is called a "normal form." If the first rule is observed, the database is said to be in "first normal form." If the first three

rules are observed, the database is considered to be in "third normal form." Althoughother levels of normalization are possible, third normal form is considered the highestlevel necessary for most applications.As with many formal rules and specifications, real world scenarios do not always allowfor perfect compliance. In general, normalization requires additional tables and somecustomers find this cumbersome. If you decide to violate one of the first three rules of normalization, make sure that your application anticipates any problems that could occur,such as redundant data and inconsistent dependencies.

Page 14: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 14/36

NOTE: The following descriptions include examples.

First Normal Form

Eliminate repeating groups in individual tables.• Create a separate table for each set of related data.• Identify each set of related data with a primary key.

Do not use multiple fields in a single table to store similar data. For example, to track aninventory item that may come from two possible sources, an inventory record maycontain fields for Vendor Code 1 and Vendor Code 2.But what happens when you add a third vendor? Adding a field is not the answer; itrequires program and table modifications and does not smoothly accommodate a dynamicnumber of vendors. Instead, place all vendor information in a separate table calledVendors, then link inventory to vendors with an item number key, or vendors to inventory

with a vendor code key.

 Second Normal Form

• Create separate tables for sets of values that apply to multiple records.• Relate these tables with a foreign key.

Records should not depend on anything other than a table's primary key (a compoundkey, if necessary). For example, consider a customer's address in an accounting system.The address is needed by the Customers table, but also by the Orders, Shipping, Invoices,Accounts Receivable, and Collections tables. Instead of storing the customer's address as

a separate entry in each of these tables, store it in one place, either in the Customers tableor in a separate Addresses table.

Third Normal Form

• Eliminate fields that do not depend on the key.

Values in a record that are not part of that record's key do not belong in the table. Ingeneral, any time the contents of a group of fields may apply to more than a single recordin the table, consider placing those fields in a separate table.For example, in an Employee Recruitment table, a candidate's university name and

address may be included. But you need a complete list of universities for group mailings.If university information is stored in the Candidates table, there is no way to listuniversities with no current candidates. Create a separate Universities table and link it tothe Candidates table with a university code key.EXCEPTION: Adhering to the third normal form, while theoretically desirable, is notalways practical. If you have a Customers table and you want to eliminate all possibleinterfield dependencies, you must create separate tables for cities, ZIP codes, salesrepresentatives, customer classes, and any other factor that may be duplicated in multiple

Page 15: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 15/36

records. In theory, normalization is worth pursuing; however, many small tables maydegrade performance or exceed open file and memory capacities.It may be more feasible to apply third normal form only to data that changes frequently.If some dependent fields remain, design your application to require the user to verify allrelated fields when any one is changed.

Other Normalization Forms

Fourth normal form, also called Boyce Codd Normal Form (BCNF), and fifth normalform do exist, but are rarely considered in practical design. Disregarding these rules mayresult in less than perfect database design, but should not affect functionality.

**********************************Examples of Normalized Tables********************************** Normalization Examples: Unnormalizedtable: Student# Advisor Adv-Room Class1 Class2 Class3------------------------------------------------------- 1022

Jones 412 101-07 143-01 159-02 4123 Smith216 201-01 211-02 214-01

1. First Normal Form: NO REPEATING GROUPSTables should have only two dimensions. Since one student has several classes,these classes should be listed in a separate table. Fields Class1, Class2, & Class3in the above record are indications of design trouble.Spreadsheets often use the third dimension, but tables should not. Another way tolook at this problem: with a one-to-many relationship, do not put the one side andthe many side in the same table. Instead, create another table in first normal form by eliminating the repeating group (Class#), as shown below:

Student# Advisor Adv-Room Class#--------------------------------------- 1022 Jones412 101-07 1022 Jones 412 143-011022 Jones 412 159-02 4123 Smith216 201-01 4123 Smith 216 211-024123 Smith 216 214-01

2. Second Normal Form: ELIMINATE REDUNDANT DATA Note the multiple Class# values for each Student# value in the above table. Class#is not functionally dependent on Student# (primary key), so this relationship is notin second normal form.The following two tables demonstrate second normal form:

Students: Student# Advisor Adv-Room------------------------------ 1022 Jones412 4123 Smith 216 Registration:Student# Class# ------------------1022 101-07 1022 143-011022 159-02 4123 201-014123 211-02 4123 214-01

Page 16: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 16/36

3. Third Normal Form: ELIMINATE DATA NOT DEPENDENT ON KEYIn the last example, Adv-Room (the advisor's office number) is functionallydependent on the Advisor attribute. The solution is to move that attribute from theStudents table to the Faculty table, as shown below:

Students: Student# Advisor------------------- 1022 Jones4123 Smith Faculty: Name Room Dept-------------------- Jones 412 42Smith 216 42

 RE: In Oracle varchar2 takes dynamic space for storage...

 

The mejor defference between varchar2 and char is fixed length and variable length .varchar2 have varible length mean if we declare as 20 space and its use only 5 space thememory asigne only 5 . but in char takes daclare space while use any number space lessthan declare .

char is used if we know that the length wont exceed the specified range while varchar isused for varying range.

If we want any string not exceeding 6, we use char(6),because we can put a constraint if someone is trying to enter more or less than 6.

When we export external data then we used fixed lenght of record this is possible by char or second reson is whenever we use varchar it stores its width which occupies memory.so here two reson is sufficient for char.

Third reason is performance .

char is of fied length search operation becomes faster since oracle engine has to look for  predetermined length of characters.

what is the diffrence between and constraints and triggers

Constraints are used to maintain the integrity and atomicity of database .in other wordsit can be said they are used to prevent invalid data entry . the main 5 constraints are NOT NULL,PRIMARY KEY,FOREIGN KEY,UNIQUE KEY and CHECK 

Triggers are bascically stored procedures which automaticallly fired when anyinsert,update or delete is issued on table.

Another most imp. deff. is that trigger effected only those row after which trigger applied but constraint effected all row of table .

Triggers are used to carry out tasks which cant be done using constraints.

Page 17: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 17/36

For eg:-A change in the "sal" column of a table should change the "tax" column inanother table.This cant be done using constraints.It has to be done using triggers.Thatswhere the importance of triggers lie.

 RE: What is the difference between "NULL in C" and "NU...

The NULL in C treated as Zero or void. but in SQL NULL value is Non or blank represented it can't manuplated.

 NULL in SQL in an unknown value. It neither zero nor any valid value. It cannot bemapulated, but it can only be compared.

With reference from the Oracle book,NULL is a undetermined value and will lead toinfinite process (loop). NULL must be handled carefully to avoid ambiguity.Tounderstand the difference, ZERO is a numeric value and BLANK is a specialcharacter.All the best!!!

RE: What is difference between varchar and varchar2

 

Varchar and Varchar2 are both same except for varchar2 supports upto 2000 char 

hi... in oracle name varchar(10)-in this declaration it allocate 10 spaces in memory.if suppose ur using 4 charecter the extra space wasted. name varcher2(10)-in thisdeclaration the extra space used by other operations automatically.

Both varchar and varchar2 are same which is of variable length characters but

in varchar maximum chars are 2000 and in later one is 4000 bytes.

There are how many maximum no of colimns in atabl...

 

Final Answer : 1000 columns/table.

E: What is the Difference between Replace and Transla... 

Both Replace and Translate are single row functions in Oracle 9i.

The Replace Function replaces single character with multiple characters.

But in Translate Function replaces sinlge character with sinlge character only.

Page 18: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 18/36

what is the difference between rownum,rowid

 

Rownum is just the serial No of your output while Rowid is automaticallygenerated unique id of a row an it is generated at the time of insertion of row.

Rownum is numeric and rowid is 16 bit hexadecimal no.

rowid has a physical significance i.e you can read a row if you know rowid. It is complete physical address of a row.

While rownum is temporary serial number allocated to each returned row during queryexecution.

RE: What is the difference between cold backup and hot...

Cold Backup- We can take the Backup while DB(eg. Oracle) is down.Hot Backup-We can take the Backup while DB(eg. Oracle) is running.

Cold backup is a physical backup. During a cold backup the database is closed andnot available to users. All files of the database are copied (image copy). Thedatafiles do not change during the copy so the database is in sync upon restore.Used when:Service level allows for some down time for backupHot backup is a physical backup. In a hot backup the database remains open andavailable to users. All files of the database are copied (image copy). There may bechanges to the database as the copy is made and so all log files of changes beingmade during the backup must be saved too. Upon a restore, the changes in the logfiles are reapplied to bring the database in sync. Used when:A full backup of a

database is neededService level allows no down time for the backup.

Page 19: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 19/36

 JAVA Questions

How to define an Abstract class?Answer: A class containing abstract method is called Abstract class. An Abstract classcan't be instantiated.Example of Abstract class:abstract class testAbstractClass {

 protected String myString; public String getMyString() {

return myString;}

 public abstract string anyAbstractFunction();} 

Question: How to define an Interface?Answer: In Java Interface defines the methods but does not implement them. Interfacecan include constants. A class that implements the interfaces is bound to implement allthe methods defined in Interface.Emaple of Interface:

 public interface sampleInterface {public void functionOne();

public long CONSTANT_ONE = 1000;} 

Question: Explain the user defined Exceptions?Answer: User defined Exceptions are the separate Exception classes defined by the user 

Page 20: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 20/36

for specific purposed. An user defined can created by simply sub-classing it to theException class. This allows custom exceptions to be generated (using throw) and caughtin the same way as normal exceptions.Example:class myCustomException extends Exception {

// The class simply has to exist to be an exception}

Question: Explain the new Features of JDBC 2.0 Core API?Answer: The JDBC 2.0 API includes the complete JDBC API, which includes both coreand Optional Package API, and provides inductrial-strength database computingcapabilities. New Features in JDBC 2.0 Core API:

• Scrollable result sets- using new methods in the ResultSet interface allows

 programmatically move the to particular row or to a position relative to its current position • JDBC 2.0 Core API provides the Batch Updates functionality to the java

applications.• Java applications can now use the ResultSet.updateXXX methods.•  New data types - interfaces mapping the SQL3 data types• Custom mapping of user-defined types (UTDs)• Miscellaneous features, including performance hints, the use of character streams,

full precision for java.math.BigDecimal values, additional security, and supportfor time zones in date, time, and timestamp values.

Question: Explain garbage collection?Answer: Garbage collection is one of the most important feature of Java. Garbagecollection is also called automatic memory management as JVM automatically removesthe unused variables/objects (value is null) from the memory. User program cann'tdirectly free the object from memory, instead it is the job of the garbage collector toautomatically free the objects that are no longer referenced by a program. Every classinherits finalize() method from java.lang.Object, the finalize() method is called bygarbage collector when it determines no more references to the object exists. In Java, it isgood idea to explicitly assign null into a variable when no more in use. I Java on calling

System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is noguarantee when all the objects will garbage collected.

Question: How you can force the garbage collection?Answer: Garbage collection automatic process and can't be forced.

Page 21: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 21/36

Question: What is OOPS?Answer: OOP is the common abbreviation for Object-Oriented Programming.

Question: Describe the principles of OOPS.

Answer: There are three main principals of oops which are called Polymorphism,Inheritance and Encapsulation.

Question: Explain the Encapsulation principle.Answer: Encapsulation is a process of binding or wrapping the data and the codes thatoperates on the data into a single entity. This keeps the data safe from outside interfaceand misuse. One way to think about encapsulation is as a protective wrapper that preventscode and data from being arbitrarily accessed by other code defined outside the wrapper.

Question: Explain the Inheritance principle.Answer: Inheritance is the process by which one object acquires the properties of another object.

Question: Explain the Polymorphism principle.Answer: The meaning of Polymorphism is something like one name many forms.Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. Theconcept of polymorphism can be explained as "one interface, multiple methods".

Question: Explain the different forms of Polymorphism.Answer: From a practical programming viewpoint, polymorphism exists in three distinctforms in Java:

• Method overloading• Method overriding through inheritance• Method overriding through the Java interface

 

Question: What are Access Specifiers available in Java?Answer: Access specifiers are keywords that determines the type of access to themember of a class. These are:

• Public• Protected• Private

Page 22: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 22/36

• Defaults

What are the contents of web module?Answer: A web module may contain:a) JSP files

 b) Java classesc) gif and html files andd) web component deployment descriptors

What is the difference between Session Bean and Entity Bean?Answer: Session Bean: Session is one of the EJBs and it represents a single client inside theApplication Server. Stateless session is easy to develop and its efficient. As compare toentity beans session beans require few server resources.

A session bean is similar to an interactive session and is not shared; it can have only one

client, in the same way that an interactive session can have only one user. A session beanis not persistent and it is destroyed once the session terminates.

Entity Bean: An entity bean represents persistent global data from the database. Entity beans data are stored into database.What are types of J2EE clients?Answer: J2EE clients are the software that access the services components installed onthe J2EE container. Following are the J2EE clients:a) Applets b) Java-Web Start clientsc) Wireless clients

d) Web applicationsWhat are the services provided by a container?Answer: The services provided by container are as follows:a) Transaction management for the bean b) Security for the beanc) Persistence of the beand) Remote access to the beane) Lifecycle management of the beanf) Database-connection poolingg) Instance pooling for the beanWhat is Deployment Descriptor?Answer: A deployment descriptor is simply an XML(Extensible Markup Language) filewith the extension of .xml. Deployment descriptor describes the component deploymentsettings. Application servers reads the deployment descriptor to deploy the componentscontained in the deployment unit. For example ejb-jar.xml file is used to describe thesetting of the EJBs.What is difference between Java Bean and Enterprise Java Bean?Answer: Java Bean as is a plain java class with member variables and getter setter 

Page 23: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 23/36

methods. Java Beans are defined under JavaBeans specification as Java-Based softwarecomponent model which includes the features like introspection, customization, events,  properties and persistence.Enterprise JavaBeans or EJBs for short are Java-based software components that complywith Java's EJB specification. EJBs are delpoyed on the EJB container and executes in

the EJB container. EJB is not that simple, it is used for building distributed applications.Examples of EJB are Session Bean, Entity Bean and Message Driven Bean. EJB is usedfor server side programming whereas java bean is a client side. Bean is only development but the EJB is developed and then deploy on EJB Container.What are the call back methods in Session bean?Answer: Callback methods are called by the container to notify the important events tothe beans in its life cycle. The callback methods are defined in the javax.ejb.EntityBeaninterface.The callback methods example are ejbCreate(), ejbPassivate(), andejbActivate().Can a private method of a superclass be declared within a subclass?Answer: Sure. A private field or method or inner class belongs to its declared class and

hides from its subclasses. There is no way for private stuff to have a runtime overloadingor overriding (polymorphism) features.

Why Java does not support multiple inheritence ?Answer: Java DOES support multiple inheritance via interface implementation. 

Question:What is the difference between final, finally and finalize?Answer: o final - declare constant  o finally - handles exception  o finalize - helps in garbage collection

 Question: Where and how can you use a private constructor.Answer: Private constructor can be used if you do not want any other class to instanstiatethe object , the instantiation is done from a static public method, this method is usedwhen dealing with the factory method pattern when the designer wants only onecontroller (fatory method ) to create the object. 

Question: In System.out.println(),what is System,out and println,pls explain?Answer: System is a predefined final class,out is a PrintStream object and println is a

 built-in overloaded method in the out object. 

Question: What is meant by "Abstract Interface"?Answer: First, an interface is abstract. That means you cannot have any implementationin an interface. All the methods declared in an interface are abstract methods or signatures of the methods.

What is the difference between Swing and AWT components?

Page 24: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 24/36

Answer: AWT components are heavy-weight, whereas Swing components arelightweight. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button.

Question: Why Java does not support pointers?Answer: Because pointers are unsafe. Java uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. This is why Javaand C# shine.

hat is a platform?Answer: A platform is the hardware or software environment in which a program runs.Most platforms can be described as a combination of the operating system and hardware,like Windows 2000/XP, Linux, Solaris, and MacOS.

What is the Java API?

Answer: The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

Question: What is the package?Answer: The package is a Java namespace or part of Java libraries. The Java API isgrouped into libraries of related classes and interfaces; these libraries are known as packages.

Question: What is native code?Answer: The native code is code that after you compile it, the compiled code runs on aspecific hardware platform.

What is the serialization?Answer: The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored toand from storage.

Question: How to make a class or a bean serializable?Answer: By implementing either the java.io.Serializable interface, or the java.io.Externalizable interface. As long as one class in a class's inheritance hierarchyimplements Serializable or Externalizable, that class is serializable.

How many methods in the Serializable interface?Answer:There is no method in the Serializable interface. The Serializable interface actsas a marker, telling the object serialization tools that your class is serializable.

Page 25: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 25/36

Question: . How many methods in the Externalizable interface?Answer: There are two methods in the Externalizable interface. You have to implementthese two methods in order to make your class externalizable. These two methods arereadExternal() and writeExternal().

Question: What is the difference between Serializalble and Externalizable interface?Answer: When you use Serializable interface, your class is serialized automatically bydefault. But you can override writeObject() and readObject() two methods to controlmore complex object serailization process. When you use Externalizable interface, youhave a complete control over your class's serialization process.

Question: What is a transient variable?Answer: A transient variable is a variable that may not be serialized. If you don't wantsome field to be serialized, you can mark that field transient or static.

Question: Which containers use a border layout as their default layout?

Answer: The Window, Frame and Dialog classes use a border layout as their defaultlayout. 

What is synchronization and why is it important?Answer: With respect to multithreading, synchronization is the capability to control theaccess 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 causes dirty data and leads to significant errors.

What are synchronized methods and synchronized statements?

Answer: 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 themethod's object or class. Synchronized statements are similar to synchronized methods. Asynchronized statement can only be executed after a thread has acquired the lock for theobject or class referenced in the synchronized statement.What are three ways in which a thread can enter the waiting state?Answer: A thread can enter the waiting state by invoking its sleep() method, by blockingon I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking anobject's wait() method. It can also enter the waiting state by invoking its (deprecated)suspend() method.

What method is used to specify a container's layout?Answer: The setLayout() method is used to specify a container's layout.

Question: Which containers use a FlowLayout as their default layout?Answer: The Panel and Applet classes use the FlowLayout as their default layout.

Question: What is thread?Answer: A thread is an independent path of execution in a system.

Page 26: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 26/36

Question: What is multithreading?Answer: Multithreading means various threads that run in a system.

Question: How does multithreading take place on a computer with a single CPU?Answer: The operating system's task scheduler allocates execution time to multiple tasks.

By quickly switching between executing tasks, it creates the impression that tasksexecute sequentially.

How to create multithread in a program?Answer: You have two ways to do so. First, making your class "extends" Thread class.Second, making your class "implements" Runnable interface. Put jobs in a run() methodand call start() method to start the thread.

Question: Can Java object be locked down for exclusive use by a given thread?Answer: Yes. You can lock an object by putting it in a "synchronized" block. The lockedobject is inaccessible to any thread other than the one that explicitly claimed it

Question: Can each Java object keep track of all the threads that want to exclusivelyaccess to it?Answer: Yes

Question: What state does a thread enter when it terminates its processing?Answer: When a thread terminates its processing, it enters the dead state.

Question: What invokes a thread's run() method?Answer: After a thread is started, via its start() method of the Thread class, the JVMinvokes the thread's run() method when the thread is initially executed. 

Question: What is the purpose of the wait(), notify(), and notifyAll() methods?Answer: The wait(),notify(), and notifyAll() methods are used to provide an efficientway for threads to communicate each other.

Question: What are the high-level thread states?Answer: The high-level thread states are ready, running, waiting, and dead.

Question: What is the Collections API?Answer: The Collections API is a set of classes and interfaces that support operations oncollections of objects.

Question: What is the List interface?Answer: The List interface provides support for ordered collections of objects.

Page 27: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 27/36

Question: How does Java handle integer overflows and underflows?Answer: It uses those low order bytes of the result that can fit into the size of the typeallowed by the operation.

What is the Vector class?

Answer: The Vector class provides the capability to implement a growable array of objects What modifiers may be used with an inner class that is a member of an outer class? A (non-local) inner class may be declared as public, protected, private, static, final,or abstract.

Question: If a method is declared as protected, where may the method be accessed?Answer: A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Is sizeof a keyword?Answer: The sizeof operator is not a keyword. 

How can you write a loop indefinitely?Answer: for(;;)--for loop; while(true)--always true, etc.

Question: . Can an anonymous class be declared as implementing an interface andextending a class?Answer: An anonymous class may implement an interface or extend a superclass, butmay not be declared to do both.

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

Question: Which class is the superclass for every class.Answer: Object.

Question: What is the difference between the Boolean & operator and the && operator?Answer: If an expression involving the Boolean & operator is evaluated, both operandsare evaluated. Then the & operator is applied to the operand. When an expressioninvolving the && operator is evaluated, the first operand is evaluated. If the first operandreturns a value of true then the second operand is evaluated. The && operator is thenapplied to the first and second operands. If the first operand evaluates to false, theevaluation of the second operand is skipped.Operator & has no chance to skip both sides evaluation and && operator does. If askedwhy, give details as above. 

Page 28: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 28/36

What is the purpose of the System class?Answer:The purpose of the System class is to provide access to system resources.

What is the purpose of the finally clause of a try-catch-finally statement?Answer: The finally clause is used to provide the capability to execute code no matter 

whether or not an exception is thrown or caught.

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

Question: What must a class do to implement an interface?Answer: It must provide all of the methods in the interface and identify the interface inits implements clause.

Question: What is an abstract method?Answer: An abstract method is a method whose implementation is deferred to a subclass.Or, a method that has no implementation (an interface of a method).

Question: What is a static method?Answer: A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated. 

Question: What is a protected method?Answer: A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.

Question: What is the difference between a static and a non-static inner class?Answer: A non-static inner class may have object instances that are associated withinstances of the class's outer class. A static inner class does not have any object instances.

Which package has light weight components?Answer: javax.Swing package. All components in Swing, except JApplet, JDialog,JFrame and JWindow are lightweight components.

Question: What are peerless components?Answer: The peerless components are called light weight components.

What is the difference between throw and throws keywords?Answer: The throw keyword denotes a statement that causes an exception to be initiated.

Page 29: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 29/36

It takes the Exception object to be thrown as argument. The exception will be caught byan immediately encompassing try-catch construction or propagated further up the callinghierarchy. The throws keyword is a modifier of a method that designates that exceptionsmay come out of the mehtod, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw.

Question: If a class is declared without any access modifiers, where may the class beaccessed?Answer: A class that is declared without any access modifiers is said to have package or friendly access. This means that the class can only be accessed by other classes andinterfaces that are defined within the same package.

Does a class inherit the constructors of its superclass?Answer: A class does not inherit constructors from any of its superclasses.

Question: Name primitive Java types.

Answer: The primitive types are byte, char, short, int, long, float, double, and boolean.What is the difference between static and non-static variables?Answer: A static variable is associated with the class as a whole rather than with specificinstances of a class. Non-static variables take on unique values with each object instance.

Question: What is the difference between the paint() and repaint() methods?Answer: The paint() method supports painting via a Graphics object. The repaint()method is used to cause paint() to be invoked by the AWT painting thread.

What restrictions are placed on method overloading?

Answer: Two methods may not have the same name and argument list but differentreturn types.

Question: What restrictions are placed on method overriding?Answer: Overridden methods must have the same name, argument list, and return type.The overriding method may not limit the access of the method it overrides. Theoverriding method may not throw any exceptions that may not be thrown by theoverridden method.

Question: What is casting?Answer: There are two types of casting, casting between primitive numeric types and

casting between object references. Casting between numeric types is used to convertlarger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

Question: Name Container classes.Answer: Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane

Page 30: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 30/36

How are this() and super() used with constructors?Answer: this() is used to invoke a constructor of the same class. super() is used to invokea superclass constructor.

What is Serialization and deserialization?

Answer: Serialization is the process of writing the state of an object to a byte stream.Deserialization is the process of restoring these objects.

Question: what is tunnelling?Answer: Tunnelling is a route to somewhere. For example, RMI tunnelling is a way tomake RMI application get through firewall. In CS world, tunnelling means a way totransfer data

What is polymorphism?Answer: Polymorphism allows methods to be written that needn't be concerned about thespecifics of the objects they will be applied to. That is, the method can be specified at a

higher level of abstraction and can be counted on to work even on objects of yetunconceived classes.

What is the difference between interface and abstract class?Answer: 

o interface contains methods that must be abstract; abstract class may contain concretemethods.

o interface contains variables that must be static and final; abstract class may containnon-final and final variables.

o members in an interface are public by default, abstract class may contain non-publicmembers.

o interface is used to "implements"; whereas abstract class is used to "extends".

o interface can be used to achieve multiple inheritance; abstract class can be used as asingle inheritance.

o interface can "extends" another interface, abstract class can "extends" another class and"implements" multiple interfaces.

o interface is absolutely abstract; abstract class can be invoked if a main() exists.

o interface is more flexible than abstract class because one class can only "extends" onesuper class, but "implements" multiple interfaces.

o If given a choice, use interface instead of abstract class.

Page 31: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 31/36

What are the primitive types in Java

 Type Size Value

 __________________________   boolean 1 bit true/falsechar 2 Bytes Unicode (Extended ASCII)  byte 1 Byteshort 2 Bytesint 4 Byteslong 8 Bytesfloat 4 Bytesdouble 8 Bytes

How do you declare constant values in java 

A variable can be made constant only with the help of a final keyword. If you want tomake it to be accessible from other classes then you need static.

By declaring it with static final.

How all can you free memory

With the help of finalize() method.

f a programmer really wants to explicitly request a garbage collection at some point,System.gc() or Runtime.gc() can be invoked, which will fire off a garbage collection atthat time.

What are the different kinds of exceptions? How do you catch a Runtime exception

There are 2 types of exceptions.1. Checked exception2. Unchecked exception.

Checked exception is catched at the compile time while unchecked exception is checkedat run time.

RE: What is EJB

Hi,Enterprise Java bean is a server side component.it contains business logic and no system level programming and services like

Page 32: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 32/36

transactions,threading,persistence and security as EJB server provide all these for EJBcomponent.EJB component is inherently transactional,scalable and secure.it is wire-protocol neutral,any protocol can be used like IIOP,HTTP etc.

How is serialization implemented in Java 

serialization is implemented by java.lang.seriaizable interface it does not have anymethods so it is tagged interface.

it means transferring object in to the byte form for maintaing persistance within object.restoring the object is done by deseralization.

What are the differences between AWT and Swing

AWT - Heavy weight component. Every graphical units it will invoke native methods.SWING - Light weight component. It doesn't invoke native methods.

What are the differences between EJB and Java beans

hi

the main difference is Ejb componenets are distributed which means develop once andrun anywhere.

 java beans are not distributed. which means the beans cannot be shared .

What are STRUTS

Struts is a web development framework developed by Apache. It is based on MVCarchitecture. In Struts, JSP represents view, ActionServlet represents controller andAction represents model. 

Explain Servlet and JSP life cycle

 

JSP Lifecycle:

Translation Phase: JSP Page will be converted to Servlet.

Compilation Phase: The resulting servlet is compiled.

Instantiate and loading Phase: Instance will be created for the servlet ands it will beloaded to memory.

Page 33: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 33/36

Call jspinit():Perform Initialization process.

Call _jspService(): this will be called upon each request.

Call jspDestroy(): the instance will be destroyed when not needed any more.

Servlet Life Cycle:

Call init(): servlet will be initialized using web.xml

Call service(): this will be called upon each request which in turn calls doXXX()methods.

call destroy(): called when the servlet object is no longer needed.

 

Explain the keywords - native, transient, volatil...

 

native:when you want to get functionality from particular language like c/c++ native isused

Transient : it is state of which value doesnt persist

volatile : is an indication to the compiler that the value may be changed by the program

some where else

final: can be used for variable,method and for class. final variables acts as constant. finalmethods can not be overridden. final class can not have sub class.

Differences between HashList and HashMap, Set an...

 

HashList is a data structure storing objects in a hash table and a list.it is a combination of hashmap and doubly linked list. acess will be faster. HashMap is hash tableimplementation of map interface it is same as HashTable except that it is unsynchronized

and allow null values. List is an ordered collection and it allow nulls and duplicates init. positional acess is possible. Set is a collection thatdoesn't allow duplicates, it may allow at most one null element. same as our mathematical set.

What are the differences between C++ and Java

Page 34: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 34/36

Java interprets codes, codes written in Java are portable between platforms, but C++compiles codes, codes written in C++ are MUCH faster.

ow can you do multiple inheritance in Java

 

hi,

To achieve multiple Inheritance in java we must use Interface.

What is data encapsulation? What does it buy you

 

encapsulation mean data hiding.data correspond to varibles and methods of the class.Data hiding mean: when u make different objects of the same class. The data stored inone object is unaware of the data for other object of the same class. In, this way it gives

secure data.

What is MVC architecture

MVC is an approach for developing interactive applications ie it results in eventsthrough user interaction.MVC stands for Model View Controller.Model is responsible for holding the application state,view is for displaying the current model and controller handles the events.

What are the differences between ArrayList and a Vector

1) Arraylist is not synchronized while vector is.2. Arraylist has no default size while vector has a default size of 10.

 Note: Methods in Vector are synchronised which means they are thread-safe and thus preclude access to the Vector elements by concurrent threads.Bu this imposes additionaloverhead on the JVM as it has to acquire and release locks on the vector objects under consideration.

This is not possible in ArrayList since those methods are not synchronised and hence arefaster in performance.

Use Vector only if it will be accessed by multiple threads at a time else ArrayList isalways better.In ArrayList we can store similar data types

 but in Vectror we can store different types of data.

How does serialization work 

 

Page 35: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 35/36

serialization means writing object to secondary storage device

lets write one as follows.

class a{

String s;

a(){

s="hi";

}

}

now

create objectoutputstream object and give it to fileoutputstream with file name say "a.ser"(use writeObject() method)

if u check, the object state is written in this file.

now create object Inputstream object and give it to fileinputstream with file same name"a.ser"(use readObject() method)

same object will be sent from device to console.

chow.

How would you keep track of a session

 

use session varaible accross application

String vijay=request.getParameter("vijay");

HttpSession createobject name as hs

HttpSesssion hs=request.getSession("true");

this create session object

then call

object.setAttribute("value which we will retrive later",value);

Page 36: 7111095-Java-Interview-Questions-6

8/8/2019 7111095-Java-Interview-Questions-6

http://slidepdf.com/reader/full/7111095-java-interview-questions-6 36/36

means

hs.setAttribute("sessionobject",vijay);

now on second form

we call as

String name=(String)request.getAttribute("sessionobject");

out.println("name");

in this way we can maintain session with diffrent

isNew() check wether session is new

while invalidating use session.invalidate()

In servlets, session can be tracked usinga) URL rewriting b) Hiddin FormFieldc) cookiesandd) HttpSession API

In EJB to maintain session go for stateful session beans.

Session tracking is a mechanism that servlets use to maintain state about a series of requests from the same user (that is, requests originating from the same browser) acrosssome period of time.

Sessions are shared among the servlets accessed by a client. This is convenient for applications made up of multiple servlets. For example, Duke's Bookstore uses session


Recommended