<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-174827211062086979</id><updated>2011-11-27T17:05:43.118-08:00</updated><category term='JAVA FAQS'/><title type='text'>Java FAQS</title><subtitle type='html'>A collection of FAQs and Tutorials for learning Java Programming with syntax , code ,defination and other example</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-174827211062086979.post-7115846304096323568</id><published>2007-09-15T03:09:00.000-07:00</published><updated>2007-09-15T03:23:20.117-07:00</updated><title type='text'>Database Design</title><content type='html'>&lt;strong&gt;Database Design Considerations&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Designing a database requires an understanding of both the business functions you want to model and the database concepts and features used to represent those business functions.&lt;br /&gt;&lt;br /&gt;It is important to accurately design a database to model the business because it can be time consuming to change the design of a database significantly once implemented. A well-designed database also performs better.&lt;br /&gt;When designing a database, consider:&lt;br /&gt;&lt;br /&gt;1) The purpose of the database and how it affects the design. Create a database plan to fit your purpose.&lt;br /&gt;2) Database normalization rules that prevent mistakes in the database design.&lt;br /&gt;Protection of your data integrity.&lt;br /&gt;3) Security requirements of the database and user permissions.&lt;br /&gt;4 ) Performance needs of the application. You must ensure that the database design takes advantage of Microsoft® SQL Server™ 2000 features that improve performance.&lt;br /&gt;5) Achieving a balance between the size of the database and the hardware configuration is also important for performance.&lt;br /&gt;6 ) Maintenance.&lt;br /&gt;7) Estimating the size of a database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating a Database Plan&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The first step in creating a database is creating a plan that serves both as a guide to be used when implementing the database and as a functional specification for the database after it has been implemented. The complexity and detail of a database design is dictated by the complexity and size of the database application as well as the user population.&lt;br /&gt;The nature and complexity of a database application, as well as the process of planning it, can vary greatly. A database can be relatively simple and designed for use by a single person, or it can be large and complex and designed, for example, to handle all the banking transactions for hundreds of thousands of clients. In the first case, the database design may be little more than a few notes on some scratch paper. In the latter case, the design may be a formal document with hundreds of pages that contain every possible detail about the database.&lt;br /&gt;&lt;br /&gt;In planning the database, regardless of its size and complexity, use these basic steps:&lt;br /&gt;1) Gather information.&lt;br /&gt;2) Identify the objects.&lt;br /&gt;3) Model the objects.&lt;br /&gt;4) Identify the types of information for each object.&lt;br /&gt;5) Identify the relationships between objects.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt; Gathering Information&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Before creating a database, you must have a good understanding of the job the database is expected to perform. If the database is to replace a paper-based or manually performed information system, the existing system will give you most of the information you need. It is important to interview everyone involved in the system to find out what they do and what they need from the database. It is also important to identify what they want the new system to do, as well as to identify the problems, limitations, and bottlenecks of any existing system. Collect copies of customer statements, inventory lists, management reports, and any other documents that are part of the existing system, because these will be useful to you in designing the database and the interfaces.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Identifying the Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;During the process of gathering information, you must identify the key objects or entities that will be managed by the database. The object can be a tangible thing, such as a person or a product, or it can be a more intangible item, such as a business transaction, a department in a company, or a payroll period. There are usually a few primary objects, and after these are identified, the related items become apparent. Each distinct item in your database should have a corresponding table.&lt;br /&gt;The primary object in the pubs sample database included with Microsoft® SQL Server™ 2000 is a book. The objects related to books within this company's business are the authors who write the books, the publishers who manufacture the books, the stores which sell them, and the sales transactions performed with the stores. Each of these objects is a table in the database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Modeling the Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;As the objects in the system are identified, it is important to record them in a way that represents the system visually. You can use your database model as a reference during implementation of the database.&lt;br /&gt;For this purpose, database developers use tools that range in technical complexity from pencils and scratch paper to word processing or spreadsheet programs, and even to software programs specifically dedicated to the job of data modeling for database designs. Whatever tool you decide to use, it is important that you keep it up-to-date.&lt;br /&gt;SQL Server Enterprise Manager includes visual design tools such as the Database Designer that can be used to design and create objects in the database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Identifying the Types of Information for Each Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;After the primary objects in the database have been identified as candidates for tables, the next step is to identify the types of information that must be stored for each object. These are the columns in the object's table. The columns in a database table contain a few common types of information:&lt;br /&gt;&lt;br /&gt;1)&lt;em&gt; Raw data columns&lt;/em&gt; &lt;br /&gt;These columns store tangible pieces of information, such as names, determined by a source external to the database.&lt;br /&gt;&lt;br /&gt;2)&lt;em&gt; Categorical columns&lt;/em&gt;&lt;br /&gt;These columns classify or group the data and store a limited selection of data such as true/false, married/single, VP/Director/Group Manager, and so on.&lt;br /&gt;&lt;br /&gt;3)&lt;em&gt; Identifier columns&lt;/em&gt;&lt;br /&gt;These columns provide a mechanism to identify each item stored in the table. These columns often have id or number in their names (for example, employee_id, invoice_number, and publisher_id). The identifier column is the primary component used by both users and internal database processing for gaining access to a row of data in the table. Sometimes the object has a tangible form of ID used in the table (for example, a social security number), but in most situations you can define the table so that a reliable, artificial ID can be created for the row.&lt;br /&gt;&lt;br /&gt;4)&lt;em&gt;Relational or referential columns&lt;/em&gt;&lt;br /&gt;These columns establish a link between information in one table and related information in another table. For example, a table that tracks sales transactions will commonly have a link to the customers table so that the complete customer information can be associated with the sales transaction.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Identifying the Relationships Between Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;One of the strengths of a relational database is the ability to relate or associate information about various items in the database. Isolated types of information can be stored separately, but the database engine can combine data when necessary. Identifying the relationships between objects in the design process requires looking at the tables, determining how they are logically related, and adding relational columns that establish a link from one table to another.&lt;br /&gt;&lt;br /&gt;For example, the designer of the pubs database has created tables for titles and publishers in the database. The titles table contains information for each book: an identifier column named title_id; raw data columns for the title, the price of the book, and the publishing date; and some columns with sales information for the book. The table contains a categorical column named type, which allows the books to be grouped by the type of content in the book. Each book also has a publisher, but the publisher information is in another table; therefore, the titles table has a pub_id column to store just the ID of the publisher. When a row of data is added for a book, the publisher ID is stored with the rest of the book information.&lt;br /&gt;Online Transaction Processing vs. Decision Support&lt;br /&gt;&lt;br /&gt;Many applications fall into two main categories of database applications:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Online transaction processing (OLTP)Decision support&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The characteristics of these application types have a dramatic effect on the design considerations for a database.&lt;br /&gt;Online Transaction Processing&lt;br /&gt;Online Transaction processing database applications are optimal for managing changing data, and usually have a large number of users who will be simultaneously performing transactions that change real-time data. Although individual requests by users for data tend to reference few records, many of these requests are being made at the same time. Common examples of these types of databases are airline ticketing systems and banking transaction systems. The primary concerns in this type of application are concurrency and atomicity.&lt;br /&gt;Concurrency controls in a database system ensure that two users cannot change the same data, or that one user cannot change a piece of data before another user is done with it. For example, if you are talking to an airline ticket agent to reserve the last available seat on a flight and the agent begins the process of reserving the seat in your name, another agent should not be able to tell another passenger that the seat is available.&lt;br /&gt;Atomicity ensures that all of the steps involved in a transaction complete successfully as a group. If any step fails, no other steps should be completed. For example, a banking transaction may involve two steps: taking funds out of your checking account and placing them into your savings account. If the step that removes the funds from your checking account succeeds, you want to make sure that the funds are placed into your savings account or put back into your checking account.&lt;br /&gt;&lt;strong&gt;Online Transaction Processing Design Considerations&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Transaction processing system databases should be designed to promote:&lt;br /&gt;Good data placement.&lt;br /&gt;I/O bottlenecks are a big concern for OLTP systems due to the number of users modifying data all over the database. Determine the likely access patterns of the data and place frequently accessed data together. Use filegroups and RAID (redundant array of independent disks) systems to assist in this.&lt;br /&gt;Short transactions to minimize long-term locks and improve concurrency.&lt;br /&gt;Avoid user interaction during transactions. Whenever possible, execute a single stored procedure to process the entire transaction. The order in which you reference tables within your transactions can affect concurrency. Place references to frequently accessed tables at the end of the transaction to minimize the duration that locks are held.&lt;br /&gt;Online backup.&lt;br /&gt;OLTP systems are often characterized by continuous operations (24 hours a day, 7 days a week) for which downtime is kept to an absolute minimum. Although Microsoft® SQL Server™ 2000 can back up a database while it is being used, schedule the backup process to occur during times of low activity to minimize effects on users.&lt;br /&gt;High normalization of the database.&lt;br /&gt;&lt;br /&gt;Reduce redundant information as much as possible to increase the speed of updates and hence improve concurrency. Reducing data also improves the speed of backups because less data needs to be backed up.&lt;br /&gt;&lt;br /&gt;Little or no historical or aggregated data.&lt;br /&gt;&lt;br /&gt;Data that is rarely referenced can be archived into separate databases, or moved out of the heavily updated tables into tables containing only historical data. This keeps tables as small as possible, improving backup times and query performance.&lt;br /&gt;Careful use of indexes.&lt;br /&gt;Indexes must be updated each time a row is added or modified. To avoid over-indexing heavily updated tables, keep indexes narrow. Use the Index Tuning Wizard to design your indexes.&lt;br /&gt;Optimum hardware configuration to handle the large numbers of concurrent users and quick response times required by an OLTP system.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Decision Support&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Decision-support database applications are optimal for data queries that do not change data. For example, a company can periodically summarize its sales data by date, sales region, or product and store this information in a separate database to be used for analysis by senior management. To make business decisions, users need to be able to determine trends in sales quickly by querying the data based on various criteria. However, they do not need to change this data. The tables in a decision-support database are heavily indexed, and the raw data is often preprocessed and organized to support the various types of queries to be used. Because the users are not changing data, concurrency and atomicity issues are not a concern; the data is changed only by periodic, bulk updates made during off-hour, low-traffic times in the database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Decision Support Design Considerations&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Decision-support system databases should be designed to promote:&lt;br /&gt;Heavy indexing.&lt;br /&gt;Decision-support systems have low update requirements but large volumes of data. Use many indexes to improve query performance.&lt;br /&gt;Denormalization of the database.&lt;br /&gt;Introduce preaggregated or summarized data to satisfy common query requirements and improve query response times.&lt;br /&gt;Use of a star or snowflake schema to organize the data within the database.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Normalization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The logical design of the database, including the tables and the relationships between them, is the core of an optimized relational database. A good logical database design can lay the foundation for optimal database and application performance. A poor logical database design can impair the performance of the entire system.&lt;br /&gt;Normalizing a logical database design involves using formal methods to separate the data into multiple, related tables. A greater number of narrow tables (with fewer columns) is characteristic of a normalized database. A few wide tables (with more columns) is characteristic of an nonnomalized database.&lt;br /&gt;Reasonable normalization often improves performance. When useful indexes are available, the Microsoft® SQL Server™ 2000 query optimizer is efficient at selecting rapid, efficient joins between tables.&lt;br /&gt;1 Some of the benefits of normalization include:&lt;br /&gt;2 Faster sorting and index creation.&lt;br /&gt;3 A larger number of clustered indexes.&lt;br /&gt;4 Narrower and more compact indexes.&lt;br /&gt;5 Fewer indexes per table, which improves the performance of INSERT, UPDATE, and DELETE statements.&lt;br /&gt;&lt;br /&gt;Fewer null values and less opportunity for inconsistency, which increase database compactness.&lt;br /&gt;As normalization increases, so do the number and complexity of joins required to retrieve data. Too many complex relational joins between too many tables can hinder performance. Reasonable normalization often includes few regularly executed queries that use joins involving more than four tables.&lt;br /&gt;Sometimes the logical database design is already fixed and total redesign is not feasible. Even then, however, it might be possible to normalize a large table selectively into several smaller tables. If the database is accessed through stored procedures, this schema change could take place without affecting applications. If not, it might be possible to create a view that hides the schema change from the applications.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Achieving a Well-Designed Database&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In relational-database design theory, normalization rules identify certain attributes that must be present or absent in a well-designed database. A complete discussion of normalization rules goes well beyond the scope of this topic. However, there are a few rules that can help you achieve a sound database design:&lt;br /&gt;A table should have an identifier.&lt;br /&gt;&lt;br /&gt;The fundamental rule of database design theory is that each table should have a unique row identifier, a column or set of columns used to distinguish any single record from every other record in the table. Each table should have an ID column, and no two records can share the same ID value. The column or columns serving as the unique row identifier for a table is the primary key of the table.&lt;br /&gt;A table should store only data for a single type of entity.&lt;br /&gt;&lt;br /&gt;Attempting to store too much information in a table can prevent the efficient and reliable management of the data in the table. In the pubs database in SQL Server 2000, the titles and publishers information is stored in two separate tables. Although it is possible to have columns that contain information for both the book and the publisher in the titles table, this design leads to several problems. The publisher information must be added and stored redundantly for each book published by a publisher. This uses extra storage space in the database. If the address for the publisher changes, the change must be made for each book. And if the last book for a publisher is removed from the title table, the information for that publisher is lost.&lt;br /&gt;&lt;br /&gt;In the pubs database, with the information for books and publishers stored in the titles and publishers tables, the information about the publisher has to be entered only once and then linked to each book. Therefore, if the publisher information is changed, it must be changed in only one place, and the publisher information will be there even if the publisher has no books in the database.&lt;br /&gt;A table should avoid nullable columns.&lt;br /&gt;&lt;br /&gt;Tables can have columns defined to allow null values. A null value indicates that there is no value. Although it can be useful to allow null values in isolated cases, it is best to use them sparingly because they require special handling that increases the complexity of data operations. If you have a table with several nullable columns and several of the rows have null values in the columns, you should consider placing these columns in another table linked to the primary table. Storing the data in two separate tables allows the primary table to be simple in design but able to accommodate the occasional need for storing this information.&lt;br /&gt;A table should not have repeating values or columns.&lt;br /&gt;&lt;br /&gt;The table for an item in the database should not contain a list of values for a specific piece of information. For example, a book in the pubs database might be coauthored. If there is a column in the titles table for the name of the author, this presents a problem. One solution is to store the name of both authors in the column, but this makes it difficult to show a list of the individual authors. Another solution is to change the structure of the table to add another column for the name of the second author, but this accommodates only two authors. Yet another column must be added if a book has three authors.&lt;br /&gt;&lt;br /&gt;If you find that you need to store a list of values in a single column, or if you have multiple columns for a single piece of data (au_lname1, au_lname2, and so on), you should consider placing the duplicated data in another table with a link back to the primary table. The pubs database has a table for book information and another table that stores only the ID values for the books and the IDs of the authors of the books. This design allows any number of authors for a book without modifying the definition of the table and allocates no unused storage space for books with a single author.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Data Integrity&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Enforcing data integrity ensures the quality of the data in the database. For example, if an employee is entered with an employee_id value of 123, the database should not allow another employee to have an ID with the same value. If you have an employee_rating column intended to have values ranging from 1 to 5, the database should not accept a value of 6. If the table has a dept_id column that stores the department number for the employee, the database should allow only values that are valid for the department numbers in the company.&lt;br /&gt;&lt;br /&gt;Two important steps in planning tables are to identify valid values for a column and to decide how to enforce the integrity of the data in the column. Data integrity falls into these categories:&lt;br /&gt;&lt;br /&gt;1 Entity integrity&lt;br /&gt;2 Domain integrity&lt;br /&gt;3 Referential integrity&lt;br /&gt;4 User-defined integrity&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Entity Integrity&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Entity integrity defines a row as a unique entity for a particular table. Entity integrity enforces the integrity of the identifier column(s) or the primary key of a table (through indexes, UNIQUE constraints, PRIMARY KEY constraints, or IDENTITY properties).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Domain Integrity&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Domain integrity is the validity of entries for a given column. You can enforce domain integrity by restricting the type (through data types), the format (through CHECK constraints and rules), or the range of possible values (through FOREIGN KEY constraints, CHECK constraints, DEFAULT definitions, NOT NULL definitions, and rules).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Referential Integrity&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Referential integrity preserves the defined relationships between tables when records are entered or deleted. In Microsoft® SQL Server™ 2000, referential integrity is based on relationships between foreign keys and primary keys or between foreign keys and unique keys (through FOREIGN KEY and CHECK constraints). Referential integrity ensures that key values are consistent across tables. Such consistency requires that there be no references to nonexistent values and that if a key value changes, all references to it change consistently throughout the database.&lt;br /&gt;When you enforce referential integrity, SQL Server prevents users from:&lt;br /&gt;Adding records to a related table if there is no associated record in the primary table.&lt;br /&gt;Changing values in a primary table that result in orphaned records in a related table.&lt;br /&gt;Deleting records from a primary table if there are matching related records.&lt;br /&gt;For example, with the sales and titles tables in the pubs database, referential integrity is based on the relationship between the foreign key (title_id) in the sales table and the primary key (title_id) in the titles table.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;User-Defined Integrity&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;User-defined integrity allows you to define specific business rules that do not fall into one of the other integrity categories. All of the integrity categories support user-defined integrity (all column- and table-level constraints in CREATE TABLE, stored procedures, and triggers).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Database Performance&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When you design a database, you must ensure that the database performs all the important functions correctly and quickly. Some performance issues can be resolved after the database is in production, but other performance issues may be the result of a poor database design and can be addressed only by changing the structure and design of the database.&lt;br /&gt;&lt;br /&gt;When you design and implement a database, you should identify the large tables in the database and the more complex processes that the database will perform, and give special consideration to performance when designing these tables. Also consider the effect on performance of increasing the number of users who can access the database.&lt;br /&gt;Examples of design changes that improve performance include:&lt;br /&gt;If a table containing hundreds of thousands of rows must be summarized for a daily report, you can add a column or columns to the table that contains preaggregated data to be used only for the report.&lt;br /&gt;&lt;br /&gt;Databases can be overnormalized, which means the database is defined with numerous, small, interrelated tables. When the database is processing the data in these tables, it has to perform a great deal of extra work to combine the related data. This extra processing can reduce the performance of the database. In these situations, denormalizing the database slightly to simplify complex processes can improve performance.&lt;br /&gt;&lt;br /&gt;In conjunction with correct database design, correct use of indexes, RAID (redundant array of independent disks), and filegroups is important for achieving good performance.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Hardware Considerations&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Generally, the larger the database, the greater the hardware requirements. But there are other determining factors: the number of concurrent users/sessions, transaction throughput, and the types of operations within the database. For example, a database containing infrequently updated data for a school library would generally have lower hardware requirements than a 1-terabyte (TB) data warehouse containing frequently analyzed sales, product, and customer information of a large corporation. Aside from the disk storage requirements, more memory and faster processors would be needed for the data warehouse to enable more of the data to be cached in memory and queries referencing large amounts of data to be processed quickly.&lt;br /&gt;Maintenance&lt;br /&gt;&lt;br /&gt;After a database has been created and all objects and data have been added and are in use, there will be times when maintenance must be performed. For example, it is important to back up the database regularly. You may also need to create some new indexes to improve performance. These issues should be taken into consideration when you design the database to minimize the effect on users, the time taken to perform the task, and the effort involved.&lt;br /&gt;&lt;br /&gt;Maintenance design guidelines include:&lt;br /&gt;Designing the database to be as small as possible and to exclude redundant information.&lt;br /&gt;&lt;br /&gt;Normalizing your database can help you achieve this. For example, reducing the size of the database can help reduce the time taken to back up or, more importantly, restore a database. This is especially important during a restore operation because the database is unavailable while it is being restored.&lt;br /&gt;Designing partitioned tables rather than a single table, if the table will contain a large number of rows.&lt;br /&gt;For example, a table containing every credit card transaction received by a bank could be split into multiple tables, with each table holding data for a single month. This can ease index maintenance if new indexes would otherwise have to be added to improve query performance. It may be necessary to create the index only on data from the last three months because older data is no longer referenced. The larger the table, the longer it takes to create new indexes.&lt;br /&gt;Microsoft® SQL Server™ 2000 provides the Database Maintenance Plan Wizard for automating many of these tasks, thereby reducing or removing the work involved in database maintenance.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174827211062086979-7115846304096323568?l=javawebblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/7115846304096323568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=174827211062086979&amp;postID=7115846304096323568' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/7115846304096323568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/7115846304096323568'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/2007/09/database-design.html' title='Database Design'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174827211062086979.post-7863222684238248219</id><published>2007-08-24T12:27:00.000-07:00</published><updated>2007-08-24T12:43:05.499-07:00</updated><title type='text'>JAVA FAQS1</title><content type='html'>&lt;strong&gt;What is JAVA ? &lt;/strong&gt;&lt;br /&gt;Java is a pure object oriented programming language, which has derived C syntax and C++ object oriented programming features.&lt;br /&gt;Is a compiled and interpreted language and is platform independent and&lt;br /&gt;Can do graphics, networking, multithreading. It was initially called as OAK.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What r the four cornerstones of OOP ?&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Abstraction&lt;/strong&gt; : Can manage complexity through abstraction. Gives the complete overview of a particular task and the details are handled by its derived classes. Ex : Car.&lt;br /&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt; : Nothing but data hiding, like the variables declared under private of a particular class are accessed only in that class and cannot access in any other the class.&lt;br /&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; : Is the process in which one object acquires the properties of another object, ie., derived object.&lt;br /&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; : One method different forms, ie., method overriding and interfaces are the examples of polymorphism.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;what is downcasting ?&lt;/strong&gt;&lt;br /&gt;Doing a cast from a base class to a more specific class. The cast does not convert the object, just asserts it actually is a more specific extended object.&lt;br /&gt;e.g. Dalamatian d = (Dalmatian) aDog;&lt;br /&gt;Most people will stare blankly at you if you use the word downcast. Just use cast.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Java Interpreter ?&lt;/strong&gt;&lt;br /&gt;It is Java Virtual Machine. ie., a java program compiles the Unicode to intermediary code called as Bytecode which is not an executable code. that is executed by Java interpreter.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are Java Buzzwords ?&lt;br /&gt;&lt;/strong&gt;Simple : Easy to learn.&lt;br /&gt;Secure : Provided by firewalls between networked applications.&lt;br /&gt;Portable : Can be dynamically downloaded at various platforms connect to internet.&lt;br /&gt;OOP : Four Corner stones.&lt;br /&gt;Multithread : Can perform more than one task concurrently in a single program.&lt;br /&gt;Robust : overcomes problems of de-allocation of memory and exceptions.&lt;br /&gt;Interpreted : Convert into byte code and the executes by JVM.&lt;br /&gt;Distributed : Concept of RMI.&lt;br /&gt;Dynamic : Verifying and accessing objects at run time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are public static void main(String args[]) and System.out.println() ?&lt;br /&gt;&lt;/strong&gt;Public keyword is an access specifier.&lt;br /&gt;Static allows main() to be called without having to instantiate a particular instance of class.&lt;br /&gt;Void does not return any value.&lt;br /&gt;main() is the method where java application begins.&lt;br /&gt;String args[] receives any command line arguments during runtime.&lt;br /&gt;&lt;br /&gt;System is a predefined class that provides access to the system.&lt;br /&gt;out is output stream connected to console.&lt;br /&gt;println displays the output.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are identifiers and literals ?&lt;br /&gt;&lt;/strong&gt;Identifiers are the variables that are declared under particular datatype.&lt;br /&gt;Literals are the values assigned to the Identifiers.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Typed language ?&lt;br /&gt;&lt;/strong&gt;This means that the variables are at first must be declared by a particular datatype whereas this is not the case with javascript.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Scope and lifetime of variables ? &lt;/strong&gt;&lt;br /&gt;scope of variables is only to that particular block&lt;br /&gt;lifetime will be till the block ends.&lt;br /&gt;variables declared above the block within the class are valid to that inner block also.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Casting Incompatible types ?&lt;br /&gt;&lt;/strong&gt;Can be done either implicitly and explicitly. ie., int b = (int) c; where c is float.&lt;br /&gt;There are two types of castings related to classes : 1) unicast and 2)multicast.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Declaration of Arrays ? &lt;/strong&gt;&lt;br /&gt;int a[] = new int[10]; int a[][] = new int[2][2];&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does String define ?&lt;br /&gt;&lt;/strong&gt;String is an array of characters, but in java it defines an object.&lt;br /&gt;and the variable of type string can be assigned to another variable of type String.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Define class ?&lt;br /&gt;&lt;/strong&gt;A class is a one which defines new datatype, and is template of an object, and is a protoype.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Types of Constructors ? &lt;/strong&gt;&lt;br /&gt;Default Constructor, Parameterized Constructor, Copy Constructors&lt;br /&gt;Garbage collector takes the responsibility releasing the memory of object implicitly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Define this , finalize, and final( for variables, methods, classes ) ?&lt;br /&gt;&lt;/strong&gt;this is used inside any method to refer to the current object. and is mostly avoided.&lt;br /&gt;finalize method is used to perform the actions specified in this method just before an object is destroyed. ie just before garbage collector process.&lt;br /&gt;final with variables is we cant change the literals of the variables ie nothing but const.&lt;br /&gt;final with method means we cant override that method.&lt;br /&gt;final with class means we cannot have derived classes of that particular class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is passed by reference ? &lt;/strong&gt;&lt;br /&gt;Objects are passed by reference.&lt;br /&gt;In java we can create an object pointing to a particular location ie NULL location by specifying : &lt;class&gt;;&lt;br /&gt;and also can create object that allocates space for the variables declared in that particular class by specifying : = new &lt;class&gt;();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Explain about Static ?&lt;br /&gt;&lt;/strong&gt;When a member is declared as static it can be accessed before any objects of its class are created and without any reference to any object.&lt;br /&gt;these are global variables, no copy of these variables can be made.&lt;br /&gt;static can also be declared for methods. and cannot refer to this or super.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What r nested classes ? &lt;/strong&gt;&lt;br /&gt;There are two types : static and non-static.&lt;br /&gt;static class means the members in its enclosing class (class within class) can be accessed by creating an object and cannot be accessed directly without creating the object.&lt;br /&gt;non-static class means inner class and can be accessed directly with the object created for the outer class no need to create again an object like static class.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Briefly about super() ?&lt;br /&gt;&lt;/strong&gt;This is used to initialize constructor of base class from the derived class and also access the variables of base class like super.i = 10.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;method overloading :&lt;/strong&gt; same method name with different arguments.&lt;br /&gt;&lt;strong&gt;method overriding&lt;/strong&gt; : same method name and same number of arguments.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Dynamic Method Dispatch ?&lt;br /&gt;&lt;/strong&gt;this is the mechanism by which a call to an overridden function is resolved at runtime rather than at compile time. And this is how Java implements runtime polymorphism.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What r abstract classes ? &lt;/strong&gt;&lt;br /&gt;To create a superclass that only defines generalized form that will be shared by all its subclasses, leaving it to each subclass to fill in the details.&lt;br /&gt;• we cannot declare abstract constructors and abstract static methods.&lt;br /&gt;• An abstract class contains at least one abstract method.&lt;br /&gt;• And this abstract class is not directly instantiated with new operator.&lt;br /&gt;• Can create a reference to abstract class and can be point to subclass object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Object class and java.lang ?&lt;br /&gt;&lt;/strong&gt;Object class is the superclass of all the classes and means that reference variable of type object can refer to an object of any other class. and also defines methods like finalise,wait.&lt;br /&gt;java.lang contains all the basic language functions and is imported in all the programs implicitly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What r packages and why ? how to execute a program in a package ?&lt;br /&gt;&lt;/strong&gt;Package is a set of classes, which can be accessed by themselves and cannot be accessed outside the package. and can be defined as package &lt;pkg&gt;.&lt;br /&gt;Package name and the directory name must be the same.&lt;br /&gt;And the execution of programs in package is done by : java mypack.account&lt;br /&gt;where mypack is directory name and account is program name.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What does a java source file can contain ? &lt;/strong&gt;&lt;br /&gt;specifying package name.&lt;br /&gt;importing more than one package&lt;br /&gt;specifying classes and there methods&lt;br /&gt;………………&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why interface and what extends what ?&lt;br /&gt;&lt;/strong&gt;Interface is similar to abstract classes. this define only method declarations and definitions are specified in the classes which implements these interfaces.&lt;br /&gt;and “ one interface multiple methods “ signifies the polymorphism concept.&lt;br /&gt;Here an interface can extend another interface.&lt;br /&gt;and a class implements more than one interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How Exception handling is done in Java ? &lt;/strong&gt;&lt;br /&gt;Is managed via 5 keywords :&lt;br /&gt;try : statements that you want to monitor the exceptions contain in try block.&lt;br /&gt;catch : the exception thrown by try is catched by this.&lt;br /&gt;throw : to manually throw exception we go for this.&lt;br /&gt;throws : Exception that is thrown out of a method must be specified by throws after the method declaration.&lt;br /&gt;finally : this block is executed whether or not an exception is thrown. and also it is executed just before the method returns. and this is optional block.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What r checked and unchecked Exceptions ?&lt;br /&gt;&lt;/strong&gt;* Unchecked Exceptions are those which r not included in throws list and are derived from RuntimeException which are automatically available and are in java.lang.&lt;br /&gt;* Checked Exceptions are those which cannot handle by itself.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Thread and multithread ? How is thread created ? &lt;/strong&gt;&lt;br /&gt;Thread is a small unit of dispatchable code. ie., a single program can perform more than one task simultaneously. This is a light weight process and is of low cost.&lt;br /&gt;MultiThreading writes more efficient programs and make maximum use of CPU ie., it minimizes its idle time.&lt;br /&gt;A Thread is created in two ways :&lt;br /&gt;1) By implementing the runnable interface.&lt;br /&gt;2) By extending the Thread class itself.&lt;br /&gt;First way is used to update only run() method. ie we can use only run() method in this class.&lt;br /&gt;Second way is used to define several methods overridden by derived class.&lt;br /&gt;Generally we override only run() method so we go for runnable interface.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the various states and methods of thread ?&lt;br /&gt;&lt;/strong&gt;States : Running, Ready to run, Suspended, Resumed, blocked and terminated.&lt;br /&gt;Methods : getName, getPriority, isAlive, join, run, sleep, start.&lt;br /&gt;Thread priorities are MIN_PRIORITY, MAX_PRIORITY, NORM_PRIORITY.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is interprocess synchronization ?&lt;/strong&gt; ( also called Monitor, Semaphore )&lt;br /&gt;Consider a small box namely MONITOR that can hold only one thread. Once a thread enters a monitor, all other threads must wait until that thread exits the monitor.&lt;br /&gt;In this way, a monitor can be used to protect a shared asset from being manipulated by more than one thread at a time.&lt;br /&gt;Once a thread is inside a synchronized method, no other thread can call any other synchronized method on the same object.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Stream ?&lt;/strong&gt;&lt;br /&gt;It is an Abstraction that either produces or consumes information.&lt;br /&gt;Two types : Byte Stream and Character Stream.&lt;br /&gt;Print Writer is to Print output in Real World Programs.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How to enter data in java ?&lt;br /&gt;&lt;/strong&gt;First specify :&lt;br /&gt;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;then say br.read(), and this is put in do while loop to receive as many as we require.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Define Inline Functions ?&lt;br /&gt;&lt;/strong&gt;In ordinary functions, during the program execution, at any function call the controller jumps to the function definition, performs operation and returns the value, then comes back to the program.&lt;br /&gt;whereas in Inline functions the controller copies the complete function definition into the program and performs operations.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are the four components in URL ?&lt;br /&gt;&lt;/strong&gt;http:// www. yahoo .com : 8080 / index.html&lt;br /&gt;http: --- &gt; is protocol&lt;br /&gt;www. yahoo .com ---à is IP address&lt;br /&gt;8080 --à port number and is a pointer to memory location.&lt;br /&gt;index.html --à file path to be loaded&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a StringTokenizer ?&lt;br /&gt;&lt;/strong&gt;String Tokenizer provide parsing process in which it identifies the delimiters provided by the user , by default delimiters are spaces, tab, newline etc. and separates them from the tokens. Tokens are those which are separated by delimiters.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are macros and Inline functions ? Which is best and Difference ?&lt;/strong&gt;&lt;br /&gt;Inline functions do Parameter passing, where as Macros do Text Substitution.&lt;br /&gt;Its better to go for Inline functions than macros, else you may get different results.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How to Declare a pointer to function ?&lt;/strong&gt;&lt;br /&gt;int func_name(float) //ordinary declaration of function.&lt;br /&gt;int (*func_name_ptr)(float) // Declaration of pointer.&lt;br /&gt;Assigning the Address can be done as :&lt;br /&gt;func_name_ptr = func_name. // Return type and Signatures must be Same.&lt;br /&gt;Invoking a function pointer : int x = (*func_name_ptr)(values as specified);&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a file ? What is a Directory ?&lt;/strong&gt;&lt;br /&gt;File : Describes the properties of file, like permissions, time, date, directory path, and to navigate subdirectory hierarchies.&lt;br /&gt;Directory : Is a file that contains list of other files and directories .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is Serialization ?&lt;br /&gt;&lt;/strong&gt;The process of writing the state of an object to a byte stream. and can restore these objects by using deserialization.&lt;br /&gt;Is also need to implement RMI, which allows a java object of one machine to invoke java object of another machine.&lt;br /&gt;ie., the object is passed as an argument by serializing it and the receiving machine deserializes it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Interfaces include by java.lang ?&lt;/strong&gt;&lt;br /&gt;Java.lang is the package of all the classes.&lt;br /&gt;And is automatically imported into all Java programs.&lt;br /&gt;Intefaces : Cloneable, Comparable, Runnable.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is user defined exception?&lt;br /&gt;&lt;/strong&gt;To handle situations specific to our applications we go for User Defined Exceptions.&lt;br /&gt;and are defined by User using throw keyword.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between process and threads?&lt;br /&gt;&lt;/strong&gt;Process is a heavy weight task and is more cost.&lt;br /&gt;Thread is a light weight task which is of low cost.&lt;br /&gt;A Program can contain more than one thread.&lt;br /&gt;A program under execution is called as process.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is the difference between CGI and Servlet ?&lt;/strong&gt;&lt;br /&gt;CGI suffered serious performance problems. servlets performance is better.&lt;br /&gt;CGI create separate process to handle client request. and Servlets do not.&lt;br /&gt;CGI is platform dependent, whereas Servlet is platform-independent b’cauz written in java.&lt;br /&gt;Servlets can communicate with applets, databases and RMI mechanisms. &lt;/label&gt;&lt;/label&gt;&lt;br /&gt;&lt;label&gt;&lt;label&gt;&lt;br /&gt;&lt;strong&gt;What is update method called?&lt;br /&gt;&lt;/strong&gt;This method is called when your Applet has requested that a portion of its window to be redrawn. Default version of update() first fills an applet with the default background color and then calls paint(); This is a default method in the applet class to which we can extend it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are Vector, Hashtable, LinkedList and Enumeration?&lt;br /&gt;Vector&lt;/strong&gt; : The Vector class provides the capability to implement a growable array of objects. &lt;strong&gt;Hashtable&lt;/strong&gt; : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object's keys. Hash codes are integer values that identify objects.&lt;br /&gt;&lt;strong&gt;LinkedList&lt;/strong&gt;: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations.&lt;br /&gt;&lt;strong&gt;Enumeration&lt;/strong&gt;: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements( ) and nextElement( ). HasMoreElemnts( ) tests if this enumeration has more elements and nextElement method returns successive elements of the series.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What are statements in Java (JDBC) ?&lt;/strong&gt;&lt;br /&gt;Statement -- To be used createStatement() method for executing single SQL statement&lt;br /&gt;PreparedStatement -- To be used preparedStatement() method for executing same SQL statement over and over&lt;br /&gt;CallableStatement -- To be used prepareCall( ) method for multiple SQL statements over and over.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is a JAR file?&lt;/strong&gt;&lt;br /&gt;Jar file allows to efficiently deploying a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files.&lt;br /&gt;The package java.util.zip contains classes that read and write jar files.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is JNI?&lt;/strong&gt;&lt;br /&gt;java native interface : The machanism to integrate C code with a java program is called the Java Native Interface.&lt;br /&gt;&lt;br /&gt;What is the base class for all swing components?&lt;br /&gt;Jcomponent&lt;br /&gt;&lt;br /&gt;&lt;/label&gt;&lt;/label&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174827211062086979-7863222684238248219?l=javawebblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/7863222684238248219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=174827211062086979&amp;postID=7863222684238248219' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/7863222684238248219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/7863222684238248219'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/2007/08/java-faqs1.html' title='JAVA FAQS1'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174827211062086979.post-4820144622324290270</id><published>2007-08-06T11:25:00.000-07:00</published><updated>2007-08-06T11:27:06.770-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA FAQS'/><title type='text'>Quick Revision Tips</title><content type='html'>Quick Revision Tips&lt;br /&gt;1. An identifier in java must begin with a letter , a dollar sign($), or an underscore (-); subsequent characters may be letters, dollar signs, underscores, or digits. &lt;br /&gt;2. There are three top-level elements that may appear in a file. None of these elements is required. If they are present, then they must appear in the following order:&lt;br /&gt;-package declaration          &lt;br /&gt;-import statements         &lt;br /&gt;-class definitions  &lt;br /&gt;3. A java source file (.java file) can't have more than one public class , interface or combination of both.  &lt;br /&gt;4. "goto" is a keyword in Java. &lt;br /&gt;5. NULL is not a keyword, but null is a keyword in Java. &lt;br /&gt;6. A final class can't be subclassed. &lt;br /&gt;7. A final method can't be overridden but a non final method can be overridden to final method. &lt;br /&gt;8. Abstract classes can't be instantiated and should be subclassed. &lt;br /&gt;9. Primitive Wrapper classes are immutable. &lt;br /&gt;10. A static method can't refer to "this" or "super". &lt;br /&gt;11. A static method can't be overridden to non-static and vice versa. &lt;br /&gt;12. The variables in java can have the same name as method or class. &lt;br /&gt;13. All the static variables are initialized when the class is loaded. &lt;br /&gt;14. An interface can extend more than one interface, while a class can extend only one class. &lt;br /&gt;15. The variables in an interface are implicitly final and static. If the interface , itself, is declared as public the methods and variables are implicitly public. &lt;br /&gt;16. Variables cannot be synchronized. &lt;br /&gt;17. Instance variables of a class are automatically initialized, but local variables of a function need to be initialized explicitly. &lt;br /&gt;18. An abstract method cannot be static because the static methods can't be overridden. &lt;br /&gt;19. The lifecycle methods of an Applet are init(), start(), stop() and destroy().  &lt;br /&gt;20. The transient keyword is applicable to variables only.  &lt;br /&gt;21. The native keyword is applicable to methods only. &lt;br /&gt;22. The final keyword is applicable to methods , variables and classes. &lt;br /&gt;23. The abstract keyword is applicable to methods and classes. &lt;br /&gt;24. The static keyword is applicable to variables, methods or a block of code called static initializes. &lt;br /&gt;25. A native method can't be abstract but it can throw exception(s). &lt;br /&gt;26. A final class cannot have abstract methods. &lt;br /&gt;27. A class can't be both abstract and final. &lt;br /&gt;28. A transient variable may not be serialized. &lt;br /&gt;29. All methods of a final class are automatically final. &lt;br /&gt;30. While casting one class to another subclass to superclass is allowed without any type casting.&lt;br /&gt;e.g.. A extends B , B b = new A(); is valid but not the reverse. &lt;br /&gt;31. The String class in java is immutable. Once an instance is created, the string it contains cannot be changed.&lt;br /&gt;e.g. String s1 = new String("test"); s1.concat("test1"); Even after calling concat() method on s1, the value of s1 will remain to be "test". What actually happens is a new instance is created.&lt;br /&gt;But the StringBuffer class is mutable. &lt;br /&gt;32. The + and += operators are the only cases of operator overloading in java and is applicable to Strings. &lt;br /&gt;33. Bit-wise operators - &amp;, ^ and | operate on numeric and boolean operands. &lt;br /&gt;34. The short circuit logical operators &amp;&amp; and || provide logical AND and OR operations on boolean types and unlike &amp; and | , these are not applicable to integral types. The valuable additional feature provided by these operators is the right operand is not evaluated if the result of the operation can be determined after evaluating only the left operand. &lt;br /&gt;35. The difference between x = ++y; and x = y++;&lt;br /&gt;In the first case y will be incremented first and then assigned to x. In second case first y will be assigned to x then it will be incremented. &lt;br /&gt;36. Please make sure you know the difference between &lt;&lt; , &gt;&gt; and &gt;&gt;&gt;(unsigned rightshift) operators. &lt;br /&gt;37. The initialization values for different data types in java is as follows&lt;br /&gt;  byte = 0, int = 0, short = 0, char = '\u0000', long = 0L, float = 0.0f, double = 0.0d, boolean = false, &lt;br /&gt; object referenece (of any object) = null. &lt;br /&gt;38. Setting the object reference to null makes it a candidate for garbage collection. &lt;br /&gt;39. An overriding method may not throw a checked exception unless the overridden method also throws that exception or a superclass of that exception. &lt;br /&gt;40. Interface methods can't be native, static, synchronized, final, private, protected or abstract. &lt;br /&gt;41. Abstract classes can have constructors , and it can be called by super() when its subclassed. &lt;br /&gt;42. A final variable is a constant and a static variable is like a global variable. &lt;br /&gt;43. The String class is a final class, it can't be subclassed. &lt;br /&gt;44. The Math class has a private constructor, it can't be instantiated. &lt;br /&gt;45. The random() method of Math class in java returns a random number , a double , between 0.0 and 1.0. &lt;br /&gt;46. The java.lang.Throwable class has two subclasses : Exception and Error. &lt;br /&gt;47. An Error indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. &lt;br /&gt;48. The two kinds of exceptions in java are : Compile time (Checked ) and Run time (Unchecked) exceptions. All subclasses of Exception except the RunTimeException and its subclasses are checked exceptions.&lt;br /&gt;Examples of Checked exception : IOException, ClassNotFoundException. &lt;br /&gt;Examples of Runtime exception :ArrayIndexOutOfBoundsException,NullPointerException, ClassCastException, ArithmeticException, NumberFormatException. &lt;br /&gt;49. The unchecked exceptions do not have to be caught. &lt;br /&gt;50. A try block may not be followed by a catch but in that case, finally block must follow try. &lt;br /&gt;51. While using multiple catch blocks, the type of exception caught must progress from the most specific exception to catch to the superclass(es) of these exceptions. &lt;br /&gt;52. More than one exception can be listed in the throws clause of a method using commas. e.g. public void myMethod() throws IOException, ArithmeticException. &lt;br /&gt;53. On dividing an integer by 0 in java will throw ArithmeticException. &lt;br /&gt;54. The various methods of Java.lang.Object are&lt;br /&gt;clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString and wait.  &lt;br /&gt;55. The Java.lang.System is a final class and can't be subclassed. &lt;br /&gt;56. Garbage collection in java cannot be forced. The methods used to call garbage collection thread are System.gc() and Runtime.gc() &lt;br /&gt;57. To perform some task when an object is about to be garbage collected, you can override the finalize() method of the Object class. The JVM only invokes finalize() method once per object. The signature of finalize() method of Object class is : protected void finalize() throws Throwable. &lt;br /&gt;58. The parent classes of input and output streams : InputStream and OutputStream class are abstract classes. &lt;br /&gt;59. File class can't be used to create a new file. For that any other output stream class such as FileOutputStream or filter streams like PrintWriter should be used. Please note that java will create a file only when the file is not available. &lt;br /&gt;60. For the RandomAccessFile constructor, the mode argument must either be equal to "r" or "rw". &lt;br /&gt;61. In java, console input is accomplished by reading from System.in . &lt;br /&gt;62. System.in is an object of type InputStream; System.out and System.err are objects of type PrintStream. &lt;br /&gt;63. Both FileInputStream and FileOutputStream classes throws FileNotFoundException. In earlier versions of java, FileOutputStream() threw an IOException when an output could not be created. &lt;br /&gt;64. System.in is an object of type InputStream; System.out and System.err are objects of type PrintStream. &lt;br /&gt;65. A method can't be overridden to be more private. e.g.. a public method can only be overridden to be public. &lt;br /&gt;66. Both primitives and object references can be cast. &lt;br /&gt;67. If inner class is declared in a method then it can access only final variables of the particular method but can access all variables of the enclosing class. &lt;br /&gt;68. To refer to a field or method in the outer class instance from within the inner class, use Outer.this.fieldname . &lt;br /&gt;69. Inner classes may not declare static initializers or static members unless they are compile time constants i.e. static final var = value; &lt;br /&gt;70. A nested class cannot have the same name as any of its enclosing classes. &lt;br /&gt;71. Inner class may be private, protected, final, abstract or static. &lt;br /&gt;72. An example of creation of instance of an inner class from some other class:&lt;br /&gt;class Outer&lt;br /&gt;{&lt;br /&gt;    public class Inner{}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Another&lt;br /&gt;{&lt;br /&gt;    public void amethod()&lt;br /&gt;    {&lt;br /&gt;        Outer.Inner i = new Outer().new Inner();&lt;br /&gt;    }&lt;br /&gt;} &lt;br /&gt;73. Classes defined in methods can be anonymous, in which case they must be instantiated at the same point they are defined. These classes can't have explicit constructor and may implement interface or extend other classes. &lt;br /&gt;74. The Thread class resides in java.lang package and need not be imported. &lt;br /&gt;75. The sleep and yield methods of Thread class are static methods. &lt;br /&gt;76. The range of Thread priority in java is 1-10. The minimum priority is 1 and the maximum is 10. The default priority of any thread in java is 5. &lt;br /&gt;77. There are two ways to provide the behavior of a thread in java: extending the Thread class or implementing the Runnable interface. &lt;br /&gt;78. The only method of Runnable interface is "public void run();". &lt;br /&gt;79. New thread take on the priority of the thread that spawned it. &lt;br /&gt;80. Using the synchronized keyword in the method declaration, requires a thread obtain the lock for this object before it can execute the method. &lt;br /&gt;81. A synchronized method can be overridden to be not synchronized and vice versa. &lt;br /&gt;82. In java terminology, a monitor is any object that has some synchronized code. &lt;br /&gt;83. Both wait() and notify() methods must be called in synchronized code. &lt;br /&gt;84. The notify() mthod moves one thread, that is waiting on this object's monitor, into the Ready state. This could be any of the waiting threads. &lt;br /&gt;85. The notifyAll() method moves all threads, waiting on this object's monitor into the Ready state. &lt;br /&gt;86. Every object has a lock and at any moment that lock is controlled by, at most, one single thread. &lt;br /&gt;87. There are two ways to mark code as synchronized:&lt;br /&gt;a.) Synchronize an entire method by putting the synchronized modifier in the method's declaration.&lt;br /&gt;b.) Synchronize a subset of a method by surrounding the desired lines of code with curly brackets ({}). &lt;br /&gt;88. The argument to switch can be either byte, short , char or int. &lt;br /&gt;89. The expression for an if and while statement in java must be a boolean. &lt;br /&gt;90. Breaking to a label (using break &lt;labelname&gt;;) means that the loop at the label will be terminated and any outer loop will keep iterating. While a continue to a label (using continue &lt;lablename&gt;;) continues execution with the next iteration of the labeled loop. &lt;br /&gt;91. A static method can only call static variables or other static methods, without using the instance of the class. e.g. main() method can't directly access any non static method or variable, but using the instance of the class it can. &lt;br /&gt;92. instanceof is a java keyword not instanceOf. &lt;br /&gt;93. The if() statement in java takes only boolean as an argument. Please note that if (a=true){}, provided a is of type boolean is a valid statement and the code inside the if block will be executed.  &lt;br /&gt;94. The (-0.0 == 0.0) will return true, while (5.0==-5.0) will return false. &lt;br /&gt;95. An abstract class may not have even a single abstract method but if a class has an abstract method it has to be declared as abstract. &lt;br /&gt;96. Collection is an Interface where as Collections is a helper class. &lt;br /&gt;97. The default Layout Manager for Panel and Applet is Flow. For Frame and Window its BorderLayout. &lt;br /&gt;98. The FlowLayout always honors the a component's preferred size. &lt;br /&gt;99. BorderLayout honors the preferred width of components on the East and West, while the preferred height is honored for the components in the North and South. &lt;br /&gt;100. The java.awt.event package provides seven adapter classes, one for each listener interface. All these adapter classes have do-nothing methods (empty bodies) , implementing listener interface. &lt;br /&gt;101. A componenet subclass may handle its own events by calling enableEvents(), passing in an even mask. &lt;br /&gt;102. The Listener interfaces inherit directly from java.util.EventListener interface. &lt;br /&gt;103. A Container in java is a Component (Container extends Component) that can contain other components.  &lt;br /&gt;104. Graphics class is abstract, hence cannot be instantiated. &lt;br /&gt;105. The repaint() method invokes a component's update() method() which in turn invokes paint() method. &lt;br /&gt;106. The Applet class extends Panel, Frame class extends Window. &lt;br /&gt;107. A String in java is initialized to null, not empty string and an empty string is not same as a null string. &lt;br /&gt;108. The statement float f = 5.0; will give compilation error as default type for floating values is double and double can't be directly assigned to float without casting. &lt;br /&gt;109. The equals() method in String class compares the values of two Strings while == compares the memory address of the objects being compared.&lt;br /&gt;e.g. String s = new String("test"); String s1 = new String("test");&lt;br /&gt;s.equals(s1) will return true while s==s1 will return false. &lt;br /&gt;110. The valueOf() method converts data from its internal format into a human-readable form. It is a static method that is overloaded within String class for all of Java's built-in types, so that each type can be converted properly into a string. &lt;br /&gt;111. The main difference between Vector and ArrayList is that Vector is synchronized while the ArrayList is not. &lt;br /&gt;112. A Set is a collection, which cannot contain any duplicate elements and has no explicit order to its elements. &lt;br /&gt;113. A List is a collection, which can contain duplicate elements, and the elements are ordered. &lt;br /&gt;114. A Map does not implement the Collection interface. &lt;br /&gt;115. The following definition of main method is valid : static public void main(String[] args). &lt;br /&gt;116. The main() method can be declared final.  &lt;br /&gt;117. The example of array declaration along with initialization - int k[] = new int[]{1,2,3,4,9}; &lt;br /&gt;118. The size of an array is given by arrayname.length. &lt;br /&gt;119. The local variables (variables declared inside method) are not initialized by default. But the array elements are always initialized wherever they are defined be it class level or method level. &lt;br /&gt;120. In an array , the first element is at index 0 and the last at length-1. Please note that length is a special array variable and not a method. &lt;br /&gt;121. The octal number in java is preceded by 0 while the hexadecimal by 0x (x may be in small case or upper case)&lt;br /&gt;e.g.&lt;br /&gt;octal :022&lt;br /&gt;hexadecimal :0x12 &lt;br /&gt;122. A constructor cannot be native, abstract, static, synchronized or final. &lt;br /&gt;123. Constructors are not inherited so not possible to override them. &lt;br /&gt;124. A constructor body can include a return statement providing no value is returned . &lt;br /&gt;125. A constructor never return a value. If you specify a return value, the JVM (java virtual machine) will interpret it as a method. &lt;br /&gt;126. A call to this() or super() in a constructor must be placed at the first line. &lt;br /&gt;127. If a class contains no constructor declarations, then a default constructor that takes no arguments is supplied. This default constructor invokes the no-argument constructor of the super class  via super() call (if there is any super class). &lt;br /&gt;128. Be careful for static and abstract key word in the program. &lt;br /&gt;129. Also be careful for private keyword in front of a class. &lt;br /&gt;130. The UTF characters in java are as big as they need to be while Unicode characters are all 16 bits.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174827211062086979-4820144622324290270?l=javawebblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/4820144622324290270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=174827211062086979&amp;postID=4820144622324290270' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/4820144622324290270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/4820144622324290270'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/2007/08/quick-revision-tips.html' title='Quick Revision Tips'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174827211062086979.post-7269483560365104382</id><published>2007-06-29T07:11:00.001-07:00</published><updated>2007-08-22T11:28:53.322-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA FAQS'/><title type='text'>Hibernate</title><content type='html'>&lt;strong&gt;What is Hibernate?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;• Hibernate is an object-relational mapping tool (ORM) that allows for persisting Java objects in a relational database&lt;br /&gt;• Driven by XML configuration files to configure data connectivity and map classes to database tables&lt;br /&gt;• Not a Java/SQL code generation tool&lt;br /&gt;• Developer writes code to call API&lt;br /&gt;• API executes necessary SQL at runtime&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why Use Hibernate?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;• Eliminate need for repetitive SQL&lt;br /&gt;• Work with classes and objects instead of queries and result sets&lt;br /&gt;• More OO, less procedural&lt;br /&gt;• Mapping approach can resist changes in object/data model more easily&lt;br /&gt;• Strong support for caching&lt;br /&gt;• Handles all create-read-update-delete (CRUD) operations using simple API; no SQL&lt;br /&gt;• Generates DDL scripts to create DB schema (tables, constraints, sequences)&lt;br /&gt;• Flexibility to hand-tune SQL and call stored procedures to optimize performance&lt;br /&gt;• Supports over 20 RDBMS; change the database by tweaking configuration files&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Plain Old Java Object (POJO)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Default constructor&lt;br /&gt;• Identifier property&lt;br /&gt;• Get/set pairs&lt;br /&gt;• Collection&lt;br /&gt;&lt;br /&gt;property is an interface type&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Session session = sessionFactory.openSession();&lt;br /&gt;Transaction tx = session.beginTransaction();&lt;br /&gt;AuctionItem item = new AuctionItem();&lt;br /&gt;item.setDescription(”Batman Begins”);&lt;br /&gt;item.setType(”DVD”);&lt;br /&gt;session.save(item);&lt;br /&gt;tx.commit();&lt;br /&gt;session.close();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Updating Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Session session = sessionFactory.openSession();&lt;br /&gt;Transaction tx = session.beginTransaction();&lt;br /&gt;AuctionItem item =(AuctionItem) session.get(ActionItem.class, itemId);&lt;br /&gt;item.setDescription(newDescription);&lt;br /&gt;tx.commit();&lt;br /&gt;session.close();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Deleting Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Session session = sessionFactory.openSession();&lt;br /&gt;Transaction tx = session.beginTransaction();&lt;br /&gt;AuctionItem item =(AuctionItem) session.get(ActionItem.class, itemId);&lt;br /&gt;session.delete(item);&lt;br /&gt;tx.commit();&lt;br /&gt;session.close();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Selecting Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;• Hibernate Query Language (HQL), similar to SQL&lt;br /&gt;&lt;br /&gt;Session session = sessionFactory.openSession();&lt;br /&gt;Transaction tx = session.beginTransaction();&lt;br /&gt;&lt;br /&gt;List allAuctions = session.createQuery(”select item from AuctionItem item&lt;br /&gt;join item.bids bid where item.description like ‘Batman%’&lt;br /&gt;and bid.amount &lt; 15 “).list();&lt;br /&gt;&lt;br /&gt;tx.commit();&lt;br /&gt;session.close();&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Key Hibernate Classes&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;• &lt;b&gt;Configuration –&lt;/b&gt; uses mapping and database connection metadata to create SessionFactory&lt;br /&gt;&lt;br /&gt;• &lt;b&gt;SessionFactory –&lt;/b&gt;thread-safe cache of compiled mappings for database; created&lt;br /&gt;&lt;br /&gt;once at application startup (expensive)&lt;br /&gt;&lt;br /&gt;•–&lt;b&gt; Session –&lt;/b&gt; represents a “conversation” between application and database; holds 1st&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;level cache of objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;• Transaction – an atomic unit of work SessionFactory&lt;br /&gt;&lt;br /&gt;• Once the Configuration is prepared, obtaining the SessionFactory is&lt;br /&gt;&lt;br /&gt;easy:&lt;br /&gt;&lt;br /&gt;Configuration cfg = new Configuration();&lt;br /&gt;&lt;br /&gt;// … do some configuration …&lt;br /&gt;&lt;br /&gt;cfg.configure();&lt;br /&gt;&lt;br /&gt;SessionFactory sf = cfg.buildSessionFactory();&lt;br /&gt;Hibernate Querying Options&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;• HQL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;– Syntax similar to SQL&lt;br /&gt;– Unlike SQL, HQL is still database-agnostic&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;• Criteria&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;– Java-based API for building queries&lt;br /&gt;– Good for queries that are built up using lots of conditional logic; avoids messy string manipulation&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;• SQL / PLSQL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;– Often needed to optimize for performance or&lt;br /&gt;leverage vendor-specific features&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174827211062086979-7269483560365104382?l=javawebblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/7269483560365104382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=174827211062086979&amp;postID=7269483560365104382' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/7269483560365104382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/7269483560365104382'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/2007/06/hibernate.html' title='Hibernate'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174827211062086979.post-1762635611905447207</id><published>2007-06-22T12:06:00.000-07:00</published><updated>2007-08-06T11:21:38.058-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA FAQS'/><title type='text'>Syntax Code</title><content type='html'>&lt;strong&gt;Connecting to a Database&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example uses the JDBC-ODBC bridge to connect to a database called ''mydatabase''. &lt;br /&gt;try {&lt;br /&gt;  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;    &lt;br /&gt;  String url = "jdbc:odbc:mydatabase";&lt;br /&gt;  Connection con = DriverManager.getConnection(&lt;br /&gt;    url, "login", "password");&lt;br /&gt;} catch (ClassNotFoundException e) {&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating a Table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example creates a table called ''mytable'' with three columns: COL_A which holds strings, COL_B which holds integers, and COL_C which holds floating point numbers. &lt;br /&gt;try {&lt;br /&gt;  Statement stmt = con.createStatement();&lt;br /&gt;    &lt;br /&gt;  stmt.executeUpdate("CREATE TABLE mytable (&lt;br /&gt;    COL_A VARCHAR(100), COL_B INTEGER, COL_C FLOAT)");&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Entering a New Row into a Table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example enters a row containing a string, an integer, and a floating point number into the table called ''mytable''. &lt;br /&gt;try {&lt;br /&gt;  Statement stmt = connection.createStatement();&lt;br /&gt;  stmt.executeUpdate("INSERT INTO mytable &lt;br /&gt;    VALUES ('Patrick Chan', 123, 1.23)");&lt;br /&gt;  connection.close();&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Getting All Rows from a Table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example retrieves all the rows from a table called ''mytable''. A row in ''mytable'' consists of a string, integer, and floating point number. &lt;br /&gt;try {&lt;br /&gt;  Statement stmt = connection.createStatement();&lt;br /&gt;    &lt;br /&gt;  // Get data using colunm names.&lt;br /&gt;  ResultSet rs = stmt.executeQuery(&lt;br /&gt;    "SELECT * FROM mytable");&lt;br /&gt;  while (rs.next()) {&lt;br /&gt;    String s = rs.getString("COL_A");&lt;br /&gt;    int i = rs.getInt("COL_B");&lt;br /&gt;    float f = rs.getFloat("COL_C");&lt;br /&gt;    process(s, i, f);&lt;br /&gt;  }&lt;br /&gt;    &lt;br /&gt;  // Get data using colunm numbers.&lt;br /&gt;  rs = stmt.executeQuery(&lt;br /&gt;    "SELECT * FROM mytable");&lt;br /&gt;  while (rs.next()) {&lt;br /&gt;    String s = rs.getString(1);&lt;br /&gt;    int i = rs.getInt(2);&lt;br /&gt;    float f = rs.getFloat(3);&lt;br /&gt;    process(s, i, f);&lt;br /&gt;  }&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Getting Particular Rows from a Table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example retrieves all rows from a table called ''mytable'' whose column COL_A equals ``Patrick Chan''. A row in ''mytable'' consists of a string, integer, and floating point number. &lt;br /&gt;try {&lt;br /&gt;  Statement stmt = connection.createStatement();&lt;br /&gt;  ResultSet rs = stmt.executeQuery(&lt;br /&gt;    "SELECT * FROM mytable WHERE COL_A = 'Patrick Chan'");&lt;br /&gt;  rs.next();&lt;br /&gt;  String s = rs.getString("COL_A");&lt;br /&gt;  int i = rs.getInt("COL_B");&lt;br /&gt;  float f = rs.getFloat("COL_C");&lt;br /&gt;  process(s, i, f);&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Updating a Row of Data in a Table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example updates a row in a table called ``mytable''. In particular, for all rows whose column COL_B equals 123, column COL_A is set to ''John Doe''. &lt;br /&gt;try {&lt;br /&gt;  Statement stmt = connection.createStatement();&lt;br /&gt;  int numUpdated = stmt.executeUpdate(&lt;br /&gt;    "UPDATE mytable SET COL_A = 'John Doe' &lt;br /&gt;    WHERE COL_B = 123");&lt;br /&gt;  connection.close();&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using a Prepared Statement&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A prepared statement should be used in cases where a particular SQL statement is used frequently. The prepared statement is more expensive to set up but executes faster than a statement. This example demonstrates a prepared statement for getting all rows from a table called ''mytable'' whose column COL_A equals ''Patrick Chan''. This example also demonstrates a prepared statement for updating data in the table. In particular, for all rows whose column COL_B equals 123, column COL_A is set to ''John Doe''. &lt;br /&gt;try {&lt;br /&gt;  // Retrieving rows from the database.&lt;br /&gt;  PreparedStatement stmt = connection.prepareStatement(&lt;br /&gt;    "SELECT * FROM mytable WHERE COL_A = ?");&lt;br /&gt;  int colunm = 1;&lt;br /&gt;  stmt.setString(colunm, "Patrick Chan");&lt;br /&gt;  ResultSet rs = stmt.executeQuery();&lt;br /&gt;    &lt;br /&gt;  // Updating the database.&lt;br /&gt;  stmt = connection.prepareStatement(&lt;br /&gt;    "UPDATE mytable SET COL_A = ? WHERE COL_B = ?");&lt;br /&gt;  colunm = 1;&lt;br /&gt;  stmt.setString(colunm, "John Doe");&lt;br /&gt;  colunm = 2;&lt;br /&gt;  stmt.setInt(colunm, 123);&lt;br /&gt;  int numUpdated = stmt.executeUpdate();&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan.&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Handling Events with an Anonymous Class&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If an event handler is specific to a component (that is, not shared by other components), there is no need to declare a class to handle the event. The event handler can be implemented using an anonymous inner class. This example demonstrates an anonymous inner class to handle key events for a component. &lt;br /&gt; &lt;br /&gt;component.addKeyListener(new KeyAdapter() {&lt;br /&gt;  public void keyPressed(KeyEvent evt) {&lt;br /&gt;  }&lt;br /&gt;});&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Handling Action Events&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Action events are fired by subclasses of AbstractButton and includes buttons, checkboxes, and menus. &lt;br /&gt; &lt;br /&gt;AbstractButton button = new JButton(quot;OK");&lt;br /&gt;button.addActionListener(new MyActionListener());&lt;br /&gt;    &lt;br /&gt;public class MyActionListener &lt;br /&gt;  implements ActionListener {&lt;br /&gt;    public void actionPerformed(ActionEvent evt) {&lt;br /&gt;      // Determine which abstract &lt;br /&gt;      // button fired the event.&lt;br /&gt;      AbstractButton button = &lt;br /&gt;        (AbstractButton)evt.getSource();&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Handling Key Presses&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You can get the key that was pressed either as a key character (which is a Unicode character) or as a key code (a special value representing a particular key on the keyboard). &lt;br /&gt; &lt;br /&gt;component.addKeyListener(new MyKeyListener());&lt;br /&gt;    &lt;br /&gt;public class MyKeyListener extends KeyAdapter {&lt;br /&gt;  public void keyPressed(KeyEvent evt) {&lt;br /&gt;    // Check for key characters.&lt;br /&gt;    if (evt.getKeyChar() == 'a') {&lt;br /&gt;      process(evt.getKeyChar());&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    // Check for key codes.&lt;br /&gt;    if (evt.getKeyCode() == KeyEvent.VK_HOME) {&lt;br /&gt;      process(evt.getKeyCode());&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Handling Mouse Clicks&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;component.addMouseListener(&lt;br /&gt;  new MyMouseListener());&lt;br /&gt;    &lt;br /&gt;public class MyMouseListener &lt;br /&gt;  extends MouseAdapter {&lt;br /&gt;    public void mouseClicked(MouseEvent evt) {&lt;br /&gt;      if ((evt.getModifiers() &amp; &lt;br /&gt;        InputEvent.BUTTON1_MASK) != 0) {&lt;br /&gt;          processLeft(evt.getPoint());&lt;br /&gt;      }&lt;br /&gt;      if ((evt.getModifiers() &amp; &lt;br /&gt;        InputEvent.BUTTON2_MASK) != 0) {&lt;br /&gt;          processMiddle(evt.getPoint());&lt;br /&gt;      }&lt;br /&gt;      if ((evt.getModifiers() &amp; &lt;br /&gt;        InputEvent.BUTTON3_MASK) != 0) {&lt;br /&gt;          processRight(evt.getPoint());&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Handling Mouse Motion&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;component.addMouseMotionListener(&lt;br /&gt;  new MyMouseMotionListener());&lt;br /&gt;    &lt;br /&gt;    public class MyMouseMotionListener &lt;br /&gt;      extends MouseMotionAdapter {&lt;br /&gt;        public void mouseMoved(MouseEvent evt) {&lt;br /&gt;          // Process current position of cursor &lt;br /&gt;          // while all mouse buttons are up.&lt;br /&gt;          process(evt.getPoint());&lt;br /&gt;        }&lt;br /&gt;        public void mouseDragged(MouseEvent evt) {&lt;br /&gt;           // Process current position of cursor &lt;br /&gt;           // while mouse button is pressed.&lt;br /&gt;           process(evt.getPoint());&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Detecting Double and Triple Clicks&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;component.addMouseListener(&lt;br /&gt;  new MyMouseListener());&lt;br /&gt;    &lt;br /&gt;public class MyMouseListener extends MouseAdapter {&lt;br /&gt;  public void mouseClicked(MouseEvent evt) {&lt;br /&gt;    if (evt.getClickCount() == 3) {&lt;br /&gt;      // triple-click&lt;br /&gt;    } else if (evt.getClickCount() == 2) {&lt;br /&gt;      // double-click&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Handling Focus Changes&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;component.addFocusListener(&lt;br /&gt;  new MyFocusListener());&lt;br /&gt;    &lt;br /&gt;public class MyFocusListener &lt;br /&gt;  extends FocusAdapter {&lt;br /&gt;    public void focusGained(FocusEvent evt) {&lt;br /&gt;       // The component gained the focus.&lt;br /&gt;    }&lt;br /&gt;    public void focusLost(FocusEvent evt) {&lt;br /&gt;       // The component lost the focus.&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;Files, Streams, I/O (java.io)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Constructing a Path&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;On Windows, this example creates the path \blash a\blash b. On Unix, the path would be /a/b. &lt;br /&gt; &lt;br /&gt;String path = File.separator + &lt;br /&gt;  "a" + File.separator + "b";&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reading Text from Standard Input&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  BufferedReader in = new BufferedReader(&lt;br /&gt;    new InputStreamReader(System.in));&lt;br /&gt;  String str = "";&lt;br /&gt;  while (str != null) {&lt;br /&gt;    System.out.print("&gt; prompt ");&lt;br /&gt;    str = in.readLine();&lt;br /&gt;    process(str);&lt;br /&gt;  }&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reading Text from a File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  BufferedReader in = new BufferedReader(&lt;br /&gt;    new FileReader("infilename"));&lt;br /&gt;  String str;&lt;br /&gt;  while ((str = in.readLine()) != null) {&lt;br /&gt;    process(str);&lt;br /&gt;  }&lt;br /&gt;  in.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Writing to a File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If the file does not already exist, it is automatically created. &lt;br /&gt;try {&lt;br /&gt;  BufferedWriter out = new BufferedWriter(&lt;br /&gt;    new FileWriter("outfilename"));&lt;br /&gt;  out.write("aString");&lt;br /&gt;  out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Creating a Directory&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;(new File("directoryName")).mkdir();&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Appending to a File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  BufferedWriter out = new BufferedWriter(&lt;br /&gt;    new FileWriter("filename", true)); &lt;br /&gt;  out.write("aString");&lt;br /&gt;  out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Deleting a File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;(new File("filename")).delete();&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Deleting a Directory&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;(new File("directoryName")).delete();&lt;br /&gt; &lt;strong&gt;&lt;br /&gt;Creating a Temporary File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  // Create temp file.&lt;br /&gt;  File temp = File.createTempFile(&lt;br /&gt;    "pattern", ".suffix");&lt;br /&gt;    &lt;br /&gt;  // Delete temp file when program exits.&lt;br /&gt;  temp.deleteOnExit();&lt;br /&gt;    &lt;br /&gt;  // Write to temp file&lt;br /&gt;  BufferedWriter out = new BufferedWriter(&lt;br /&gt;    new FileWriter(temp));&lt;br /&gt;  out.write("aString");&lt;br /&gt;  out.close();&lt;br /&gt;  } catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Using a Random Access File&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  File f = new File("filename");&lt;br /&gt;  RandomAccessFile raf = &lt;br /&gt;    new RandomAccessFile(f, "rw");&lt;br /&gt;    &lt;br /&gt;  // Read a character.&lt;br /&gt;  char ch = raf.readChar();&lt;br /&gt;    &lt;br /&gt;  // Seek to end of file.&lt;br /&gt;  raf.seek(f.length());&lt;br /&gt;    &lt;br /&gt;  // Append to the end.&lt;br /&gt;  raf.writeChars("aString");&lt;br /&gt;  raf.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Serializing an Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The object to be serialized must implement java.io.Serializable. &lt;br /&gt;try {&lt;br /&gt;  ObjectOutput out = new ObjectOutputStream(&lt;br /&gt;    new FileOutputStream("filename.ser"));&lt;br /&gt;  out.writeObject(object);&lt;br /&gt;  out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Deserializing an Object&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This example deserializes a java.awt.Button object. &lt;br /&gt;try {&lt;br /&gt;  ObjectInputStream in = new ObjectInputStream(&lt;br /&gt;    new FileInputStream("filename.ser"));&lt;br /&gt;  AnObject object = (AnObject) in.readObject();&lt;br /&gt;  in.close();&lt;br /&gt;} catch (ClassNotFoundException e) {&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Traversing a Directory&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;public static void traverse(File f) {&lt;br /&gt;  process(f);&lt;br /&gt;    &lt;br /&gt;  if (f.isDirectory()) {&lt;br /&gt;    String[] children = f.list();&lt;br /&gt;    for (int i=0; i &lt; children.length; i++) {&lt;br /&gt;      traverse(new File(f, children[i]));&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Reading UTF-8 Encoded Data&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  BufferedReader in = new BufferedReader(&lt;br /&gt;    new InputStreamReader(new FileInputStream(&lt;br /&gt;    "infilename"), "UTF8"));&lt;br /&gt;  String str = in.readLine();&lt;br /&gt;} catch (UnsupportedEncodingException e) {&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Writing UTF-8 Encoded Data&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  Writer out = new BufferedWriter(&lt;br /&gt;    new OutputStreamWriter(new FileOutputStream(&lt;br /&gt;    "outfilename"), "UTF8"));&lt;br /&gt;  out.write(aString);&lt;br /&gt;  out.close();&lt;br /&gt;} catch (UnsupportedEncodingException e) {&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Reading ISO Latin-1 Encoded Data&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  BufferedReader in = new BufferedReader(&lt;br /&gt;    new InputStreamReader(new FileInputStream(&lt;br /&gt;    "infilename"), "8859_1"));&lt;br /&gt;  String str = in.readLine();&lt;br /&gt;} catch (UnsupportedEncodingException e) {&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Writing ISO Latin-1 Encoded Data&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  Writer out = new BufferedWriter(&lt;br /&gt;    new OutputStreamWriter(new FileOutputStream(&lt;br /&gt;    "outfilename"), "8859_1"));&lt;br /&gt;  out.write(aString);&lt;br /&gt;  out.close();&lt;br /&gt;} catch (UnsupportedEncodingException e) {&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Networking (java.net)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Creating a URL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt; // With components.&lt;br /&gt;    URL url = new URL("http","hostname", 80, "index.html");&lt;br /&gt;    &lt;br /&gt;// With a single string.&lt;br /&gt;   url = new URL(&lt;br /&gt;   "http://hostname:80/index.html");&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Parsing a URL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  URL url = new URL("http://hostname:80/index.html#_top_");&lt;br /&gt;  String protocol = url.getProtocol();    // http&lt;br /&gt;  String host = url.getHost();  // hostname&lt;br /&gt;   int port = url.getPort();    // 80&lt;br /&gt;   String file = url.getFile(); // index.html&lt;br /&gt;   String ref = url.getRef();    // _top_&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Reading Text from a URL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;  URL url = new URL("http://hostname:80/index.html");&lt;br /&gt;  BufferedReader in = new BufferedReader(&lt;br /&gt;        new InputStreamReader(url.openStream()));&lt;br /&gt;    &lt;br /&gt;  String str;&lt;br /&gt;   while ((str = in.readLine()) != null) {&lt;br /&gt;  process(str);&lt;br /&gt;     }&lt;br /&gt;    in.close();&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    } catch (IOException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Resolving a Hostname&lt;/strong&gt;&lt;br /&gt; &lt;br /&gt;Creating a Client Socket&lt;br /&gt;try {&lt;br /&gt;  InetAddress addr = InetAddress.getByName("java.sun.com");&lt;br /&gt;  int port = 80;&lt;br /&gt;  Socket sock = new Socket(addr, port);&lt;br /&gt;   } catch (IOException e) {&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;Creating a Server Socket&lt;br /&gt;try {&lt;br /&gt;  int port = 2000;&lt;br /&gt;   ServerSocket srv = new ServerSocket(port);&lt;br /&gt;  &lt;br /&gt;  // Wait for connection from client.&lt;br /&gt;   Socket socket = srv.accept();&lt;br /&gt;   } catch (IOException e) {&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;Reading Text from a Socket&lt;br /&gt; try {&lt;br /&gt;  BufferedReader rd = new BufferedReader(&lt;br /&gt;  new InputStreamReader(socket.getInputStream()));&lt;br /&gt;    &lt;br /&gt;  String str;&lt;br /&gt;  while ((str = rd.readLine()) != null) {&lt;br /&gt;  process(str);&lt;br /&gt;  &lt;br /&gt;   }&lt;br /&gt;        rd.close();&lt;br /&gt;    } catch (IOException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Writing Text to a Socket&lt;br /&gt;try {&lt;br /&gt; BufferedWriter wr = new BufferedWriter(&lt;br /&gt;   new OutputStreamWriter(socket.getOutputStream()));&lt;br /&gt;      wr.write("aString");&lt;br /&gt;        wr.flush();&lt;br /&gt;    } catch (IOException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Sending a Datagram&lt;br /&gt;public static void send(InetAddress dst, &lt;br /&gt;            int port, byte[] outbuf, int len) {&lt;br /&gt;try {&lt;br /&gt;  DatagramPacket request = new DatagramPacket(&lt;br /&gt;                      outbuf, len, dst, port);&lt;br /&gt;    DatagramSocket socket = new DatagramSocket();&lt;br /&gt;      socket.send(request);&lt;br /&gt;     } catch (SocketException e) {&lt;br /&gt;     } catch (IOException e) {&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;Receiving a Datagram&lt;br /&gt; try {&lt;br /&gt;  byte[] inbuf = new byte[256]; // default size&lt;br /&gt;  DatagramSocket socket = new DatagramSocket();&lt;br /&gt;   &lt;br /&gt;  // Wait for packet&lt;br /&gt;  DatagramPacket packet = new DatagramPacket(&lt;br /&gt;                          inbuf, inbuf.length);&lt;br /&gt;   socket.receive(packet);&lt;br /&gt;    &lt;br /&gt;  // Data is now in inbuf&lt;br /&gt;   int numBytesReceived = packet.getLength();&lt;br /&gt;   } catch (SocketException e) {&lt;br /&gt;   } catch (IOException e) {&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;Joining a Multicast Group&lt;br /&gt;public void join(String groupName, int port) {&lt;br /&gt; try {&lt;br /&gt;  MulticastSocket msocket = new MulticastSocket(port);&lt;br /&gt;  group = InetAddress.getByName(groupName);&lt;br /&gt;   msocket.joinGroup(group);&lt;br /&gt;   } catch (IOException e) {&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Receiving from a Multicast Group&lt;br /&gt;public void read(MulticastSocket msocket,&lt;br /&gt;                     byte[] inbuf) {&lt;br /&gt;try {&lt;br /&gt; DatagramPacket packet = new DatagramPacket(&lt;br /&gt;                      inbuf, inbuf.length);&lt;br /&gt;    &lt;br /&gt; // Wait for packet&lt;br /&gt; msocket.receive(packet);&lt;br /&gt; &lt;br /&gt;// Data is now in inbuf&lt;br /&gt;int numBytesReceived = packet.getLength();&lt;br /&gt;   } catch (IOException e) {&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Sending to a Multicast Group&lt;br /&gt; byte[] outbuf = new byte[1024];&lt;br /&gt; int port = 1234;&lt;br /&gt;  try {&lt;br /&gt;  DatagramSocket socket = new DatagramSocket();&lt;br /&gt;  InetAddress groupAddr = InetAddress.getByName(&lt;br /&gt;  "228.1.2.3");&lt;br /&gt;   DatagramPacket packet = new DatagramPacket(&lt;br /&gt;           outbuf, outbuf.length, groupAddr, port);&lt;br /&gt;   socket.send(packet);&lt;br /&gt;   } catch (SocketException e) {&lt;br /&gt;   } catch (IOException e) {&lt;br /&gt;   }&lt;br /&gt;Defining and Exporting a Remote Object&lt;br /&gt;1. Define the remote interface. &lt;br /&gt;    import java.rmi.*;&lt;br /&gt;    &lt;br /&gt; public interface RObject extends Remote {&lt;br /&gt;  void aMethod() throws RemoteException;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Looking Up a Remote Object and Invoking a Method&lt;br /&gt; try {&lt;br /&gt; // Look up remote object&lt;br /&gt; RObject robj = (RObject) Naming.lookup(&lt;br /&gt; "//localhost/RObjectServer");&lt;br /&gt;    &lt;br /&gt; // Invoke method on remote object&lt;br /&gt;  robj.aMethod();&lt;br /&gt; } catch (MalformedURLException e) {&lt;br /&gt; } catch (UnknownHostException e) {&lt;br /&gt; } catch (NotBoundException e) {&lt;br /&gt; } catch (RemoteException e) {&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;Passing Parameters to a Remote Method&lt;br /&gt;Arguments to remote methods must be primitive, serializable, or Remote. This example demonstrates the declaration and use of all three parameter types. &lt;br /&gt; &lt;br /&gt;1. Define the remote interface. &lt;br /&gt; import java.rmi.*;&lt;br /&gt;    &lt;br /&gt; public interface RObject extends Remote {&lt;br /&gt;  // This parameter is primitive.&lt;br /&gt;  void primitiveArg(int num) throws RemoteException;&lt;br /&gt;    &lt;br /&gt; // This parameter implements Serializable.&lt;br /&gt;    void byValueArg(Integer num) throws RemoteException;&lt;br /&gt;    &lt;br /&gt; // This parameter implements Remote.&lt;br /&gt;    void byRefArg(ArgObject arg) throws RemoteException;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public interface ArgObject extends Remote {&lt;br /&gt;        int aMethod() throws RemoteException;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;2. Define the remote object implementation. &lt;br /&gt; import java.rmi.*;&lt;br /&gt; import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;    &lt;br /&gt;  public class RObjectImpl extends UnicastRemoteObject implements RObject {&lt;br /&gt;   public RObjectImpl() throws RemoteException {&lt;br /&gt;         super();&lt;br /&gt;    }&lt;br /&gt;  public void primitiveArg(int num) throws RemoteException {&lt;br /&gt;    }&lt;br /&gt;  public void byValueArg(Integer num) throws RemoteException {&lt;br /&gt;    }&lt;br /&gt;   public void byRefArg(ArgObject arg) throws RemoteException {&lt;br /&gt;    }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;3. Compile the remote object implementation. &lt;br /&gt;    &gt; javac RObject.java RObjectImpl.java&lt;br /&gt; &lt;br /&gt;4. Generate the skeletons and stubs. &lt;br /&gt;    &gt; rmic RObjectImpl&lt;br /&gt; &lt;br /&gt;5. Create an instance of RObjectImpl and bind it to the RMI Registry. &lt;br /&gt;    try {&lt;br /&gt;        RObject robj = new RObjectImpl();&lt;br /&gt;        Naming.rebind("//localhost/RObjectServer", robj);&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    } catch (UnknownHostException e) {&lt;br /&gt;    } catch (RemoteException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;6. Look Up the Remote object and pass the parameters. &lt;br /&gt;    try {&lt;br /&gt;        // Look up the remote object&lt;br /&gt;        RObject robj = (RObject) Naming.lookup("//localhost/RObjectServer");&lt;br /&gt;    &lt;br /&gt;        // Pass a primitive value as argument&lt;br /&gt;        robj.primitiveArg(1998);&lt;br /&gt;    &lt;br /&gt;        // Pass a serializable object as argument&lt;br /&gt;        robj.byValueArg(new Integer(9));&lt;br /&gt;    &lt;br /&gt;        // Pass a Remote object as argument&lt;br /&gt;        robj.byRefArg(new ArgObjectImpl());&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    } catch (UnknownHostException e) {&lt;br /&gt;    } catch (NotBoundException e) {&lt;br /&gt;    } catch (RemoteException e) {&lt;br /&gt;    }&lt;br /&gt;Returning Values from a Remote Method&lt;br /&gt;Return values from remote methods must be primitive, serializable, or Remote. This example demonstrates the declaration and use of all three return types. 1. Define the remote interface. &lt;br /&gt; &lt;br /&gt;import java.rmi.*;&lt;br /&gt; public interface RObject extends Remote {&lt;br /&gt; // This return value is primitive.&lt;br /&gt;  int primitiveRet() throws RemoteException;&lt;br /&gt;  &lt;br /&gt; // This return value implements Serializable.&lt;br /&gt;   Integer byValueRet() throws RemoteException;&lt;br /&gt;    &lt;br /&gt; // This return value implements Remote.&lt;br /&gt;     ArgObject byRefRet() throws RemoteException;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public interface ArgObject extends Remote {&lt;br /&gt;        int aMethod() throws RemoteException;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;2. Define the remote object implementation. &lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;    &lt;br /&gt;public class RObjectImpl extends UnicastRemoteObject &lt;br /&gt;                              implements RObject {&lt;br /&gt;  public RObjectImpl() throws RemoteException {&lt;br /&gt;            super();&lt;br /&gt;     }&lt;br /&gt; public int primitiveRet() throws RemoteException {&lt;br /&gt;      return 3000;&lt;br /&gt;    }&lt;br /&gt;  public Integer byValueRet() throws RemoteException {&lt;br /&gt;   return new Integer(2000);&lt;br /&gt;   }&lt;br /&gt;   public ArgObject byRefRet() throws RemoteException {&lt;br /&gt;    return new ArgObjectImpl();&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;3. Compile the remote object implementation. &lt;br /&gt;    &gt; javac RObject.java RObjectImpl.java&lt;br /&gt;    &lt;br /&gt;4. Generate the skeletons and stubs. &lt;br /&gt;  &gt; rmic RObjectImpl&lt;br /&gt; &lt;br /&gt;5. Create an instance of RObjectImpl and bind it to the RMI Registry. &lt;br /&gt; try {&lt;br /&gt;RObject robj = new RObjectImpl();&lt;br /&gt;   Naming.rebind("//localhost/RObjectServer", robj);&lt;br /&gt;  } catch (MalformedURLException e) {&lt;br /&gt; } catch (UnknownHostException e) {&lt;br /&gt;  } catch (RemoteException e) {&lt;br /&gt; }&lt;br /&gt;6. Look Up the Remote object, invoke the methods, and receive the return values. &lt;br /&gt; try {&lt;br /&gt; // Look up the remote object&lt;br /&gt; RObject robj = (RObject) Naming.lookup(&lt;br /&gt;                         "//localhost/RObjectServer");&lt;br /&gt;    &lt;br /&gt; // Receive the primitive value as return value&lt;br /&gt; int r1 = robj.primitiveRet();&lt;br /&gt;    &lt;br /&gt; // Receive the serializable object as return value&lt;br /&gt; Integer r2 = robj.byValueRet();&lt;br /&gt;    &lt;br /&gt;  // Receive the Remote Object as return value&lt;br /&gt;   ArgObject aobj =  robj.byRefRet();&lt;br /&gt;  } catch (MalformedURLException e) {&lt;br /&gt;  } catch (UnknownHostException e) {&lt;br /&gt;    } catch (NotBoundException e) {&lt;br /&gt;   } catch (RemoteException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Throwing an Exception from a Remote Method&lt;br /&gt; &lt;br /&gt;1. Define the remote interface.&lt;br /&gt; import java.rmi.*;&lt;br /&gt;    &lt;br /&gt; public interface RObject extends Remote {&lt;br /&gt;   void aMethod() throws RemoteException;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;2. Define the remote object implementation. &lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;    &lt;br /&gt;public class RObjectImpl extends&lt;br /&gt; UnicastRemoteObject implements RObject {&lt;br /&gt; public RObjectImpl() throws RemoteException {&lt;br /&gt;    super();&lt;br /&gt; }&lt;br /&gt;public void aMethod() throws RemoteException {&lt;br /&gt;// The actual exception must be wrapped in&lt;br /&gt;// a RemoteException&lt;br /&gt;   throw new RemoteException(&lt;br /&gt; "message", new FileNotFoundException("message"));&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;3. Compile the remote object implementation. &lt;br /&gt;&gt; javac RObject.java RObjectImpl.java&lt;br /&gt; &lt;br /&gt;4. Generate the skeletons and stubs. &lt;br /&gt;&gt; rmic RObjectImpl&lt;br /&gt;5. Create an instance of RObjectImpl and bind it to the RMI Registry. &lt;br /&gt; try {&lt;br /&gt; RObject robj = new RObjectImpl();&lt;br /&gt;  Naming.rebind("//localhost/RObjectServer", robj);&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    } catch (UnknownHostException e) {&lt;br /&gt;    } catch (RemoteException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;6. Look up the Remote object, invoke the method, and catch the exception. &lt;br /&gt; try {&lt;br /&gt; // Look up the remote object.&lt;br /&gt; RObject robj = (RObject) Naming.lookup(&lt;br /&gt; "//localhost/RObjectServer");&lt;br /&gt;    &lt;br /&gt; // Invoke the method.&lt;br /&gt;  robj.aMethod();&lt;br /&gt;    } catch (MalformedURLException e) {&lt;br /&gt;    } catch (UnknownHostException e) {&lt;br /&gt;    } catch (NotBoundException e) {&lt;br /&gt;    } catch (RemoteException e) {&lt;br /&gt; // Get the actual exception that was thrown.&lt;br /&gt;    Throwable realException = e.detail;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Strings (java.lang)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Constructing a String&lt;br /&gt;If you are constructing a string with several appends, it may be more efficient to construct it using a StringBuffer and then convert it to an immutable String object. &lt;br /&gt;StringBuffer buf = new StringBuffer("Initial Text");&lt;br /&gt;    &lt;br /&gt;// Modify&lt;br /&gt;int index = 1;&lt;br /&gt;buf.insert(index, "abc");&lt;br /&gt;buf.append("def");&lt;br /&gt;           &lt;br /&gt; // Convert to string&lt;br /&gt; String s = buf.toString();&lt;br /&gt;Getting a Substring from a String&lt;br /&gt;int start = 1;&lt;br /&gt;int end = 4;&lt;br /&gt; String substr = "aString".substring(start, end);   // Str&lt;br /&gt; &lt;br /&gt;Searching a String&lt;br /&gt; String string = "aString";&lt;br /&gt;    &lt;br /&gt; // First occurrence.&lt;br /&gt; int index = string.indexOf('S');  // 1&lt;br /&gt; &lt;br /&gt; // Last occurrence.&lt;br /&gt; index = string.lastIndexOf('i');  // 4&lt;br /&gt;    &lt;br /&gt; // Not found.&lt;br /&gt; index = string.lastIndexOf('z');  // -1&lt;br /&gt; &lt;br /&gt;Replacing Characters in a String&lt;br /&gt;// Replace all occurrences of 'a' with 'o'&lt;br /&gt;String newString = string.replace('a', 'o');&lt;br /&gt; &lt;br /&gt;Replacing Substrings in a String&lt;br /&gt; static String replace(String str, &lt;br /&gt;         String pattern, String replace) {&lt;br /&gt;   int s = 0;&lt;br /&gt;   int e = 0;&lt;br /&gt; StringBuffer result = new StringBuffer();&lt;br /&gt;    &lt;br /&gt;  while ((e = str.indexOf(pattern, s)) &gt;= 0) {&lt;br /&gt;    result.append(str.substring(s, e));&lt;br /&gt;    result.append(replace);&lt;br /&gt;    s = e+pattern.length();&lt;br /&gt;      }&lt;br /&gt;    result.append(str.substring(s));&lt;br /&gt;    return result.toString();&lt;br /&gt;    }&lt;br /&gt;Converting a String to Upper or Lower Case&lt;br /&gt; &lt;br /&gt; // Convert to upper case&lt;br /&gt; String upper = string.toUpperCase();  &lt;br /&gt;    &lt;br /&gt; // Convert to lower case&lt;br /&gt; String lower = string.toLowerCase();  &lt;br /&gt; &lt;br /&gt;Converting a String to a Number&lt;br /&gt;int i = Integer.parseInt("123");&lt;br /&gt;long l = Long.parseLong("123");&lt;br /&gt;float f = Float.parseFloat("123.4");&lt;br /&gt;double d = Double.parseDouble("123.4e10");&lt;br /&gt; &lt;br /&gt;Converting Unicode to UTF-8&lt;br /&gt;try {&lt;br /&gt; String string = "\u5639\u563b";&lt;br /&gt; byte[] utf8 = string.getBytes("UTF8");&lt;br /&gt; } catch (UnsupportedEncodingException e) {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;Converting UTF-8 to Unicode&lt;br /&gt; public static String toUnicode(byte[] utf8buf) {&lt;br /&gt;  try {&lt;br /&gt;    return new String(utf8buf, "UTF8");&lt;br /&gt;    } catch (UnsupportedEncodingException e) {&lt;br /&gt;    }&lt;br /&gt;    return null;&lt;br /&gt;    }        &lt;br /&gt; &lt;br /&gt;Determining a Character's Unicode Block&lt;br /&gt;char ch = '\u5639';&lt;br /&gt;Character.UnicodeBlock block = &lt;br /&gt;            Character.UnicodeBlock.of(ch);&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;Breaking a String into Words&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;String aString = "word1 word2 word3";&lt;br /&gt;StringTokenizer parser = &lt;br /&gt;          new StringTokenizer(aString);&lt;br /&gt;while (parser.hasMoreTokens()) {&lt;br /&gt;        processWord(parser.nextToken());&lt;br /&gt;    }&lt;br /&gt;  &lt;br /&gt;Some More Syntax is  to Added&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174827211062086979-1762635611905447207?l=javawebblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/1762635611905447207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=174827211062086979&amp;postID=1762635611905447207' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/1762635611905447207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/1762635611905447207'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/2007/06/syntax-code.html' title='Syntax Code'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-174827211062086979.post-8386845831934257567</id><published>2007-06-18T11:02:00.000-07:00</published><updated>2007-06-29T07:16:31.426-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA FAQS'/><title type='text'>paper 1</title><content type='html'>INTERVIEW QUESTIONS&lt;br /&gt;What is the diffrence between an Abstract class and Interface ?&lt;br /&gt;What is user defined exception ?&lt;br /&gt;What do you know about the garbate collector ?&lt;br /&gt;What is the difference between C++ &amp; Java ?&lt;br /&gt;Explain RMI Architecture?&lt;br /&gt;How do you communicate in between Applets &amp;amp; Servlets ?&lt;br /&gt;What is the use of Servlets ?&lt;br /&gt;What is JDBC? How do you connect to the Database ?&lt;br /&gt;In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?&lt;br /&gt;What is the difference between Process and Threads ?&lt;br /&gt;What is the difference between RMI &amp; Corba ?&lt;br /&gt;What are the services in RMI ?&lt;br /&gt;How will you initialize an Applet ?&lt;br /&gt;What is the order of method invocation in an Applet ?&lt;br /&gt;When is update method called ?&lt;br /&gt;How will you pass values from HTML page to the Servlet ?&lt;br /&gt;Have you ever used HashTable and Dictionary ?&lt;br /&gt;How will you communicate between two Applets ?&lt;br /&gt;What are statements in JAVA ?&lt;br /&gt;What is JAR file ?&lt;br /&gt;What is JNI ?&lt;br /&gt;What is the base class for all swing components ?&lt;br /&gt;What is JFC ?&lt;br /&gt;What is Difference between AWT and Swing ?&lt;br /&gt;Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?&lt;br /&gt;How does thread synchronization occurs inside a monitor ?&lt;br /&gt;How will you call an Applet using a Java Script function ?&lt;br /&gt;Is there any tag in HTML to upload and download files ?&lt;br /&gt;Why do you Canvas ?&lt;br /&gt;How can you push data from an Applet to Servlet ?&lt;br /&gt;What are 4 drivers available in JDBC ?&lt;br /&gt;How you can know about drivers and database information ?&lt;br /&gt;If you are truncated using JDBC, How can you know ..that how much data is truncated ?&lt;br /&gt;And What situation , each of the 4 drivers used ?&lt;br /&gt;How will you perform transaction using JDBC ?&lt;br /&gt;In RMI, server object first loaded into the memory and then the stub reference is sent to the client ? or whether a stub reference is directly sent to the client ?&lt;br /&gt;Suppose server object is not loaded into the memory, and the client request for it , what will happen?&lt;br /&gt;What is serialization ?&lt;br /&gt;Can you load the server object dynamically? If so, what are the major 3 steps involved in it ?&lt;br /&gt;What is difference RMI registry and OSAgent ?&lt;br /&gt;To a server method, the client wants to send a value 20, with this value exceeds to 20,. a message should be sent to the client ? What will you do for achieving for this ?&lt;br /&gt;What are the benefits of Swing over AWT ?&lt;br /&gt;Where the CardLayout is used ?&lt;br /&gt;What is the Layout for ToolBar ?&lt;br /&gt;What is the difference between Grid and GridbagLayout ?&lt;br /&gt;How will you add panel to a Frame ?&lt;br /&gt;What is the corresponding Layout for Card in Swing ?&lt;br /&gt;What is light weight component ?&lt;br /&gt;Can you run the product development on all operating systems ?&lt;br /&gt;What is the webserver used for running the Servlets ?&lt;br /&gt;What is Servlet API used for conneting database ?&lt;br /&gt;What is bean ? Where it can be used ?&lt;br /&gt;What is difference in between Java Class and Bean ?&lt;br /&gt;Can we send object using Sockets ?&lt;br /&gt;What is the RMI and Socket ?&lt;br /&gt;How to communicate 2 threads each other ?&lt;br /&gt;What are the files generated after using IDL to Java Compilet ?&lt;br /&gt;What is the protocol used by server and client ?&lt;br /&gt;Can I modify an object in CORBA ?&lt;br /&gt;What is the functionality stubs and skeletons ?&lt;br /&gt;What is the mapping mechanism used by Java to identify IDL language ?&lt;br /&gt;Diff between Application and Applet ?&lt;br /&gt;What is serializable Interface ?&lt;br /&gt;What is the difference between CGI and Servlet ?&lt;br /&gt;What is the use of Interface ?&lt;br /&gt;Why Java is not fully objective oriented ?&lt;br /&gt;Why does not support multiple Inheritance ?&lt;br /&gt;What it the root class for all Java classes ?&lt;br /&gt;What is polymorphism ?&lt;br /&gt;Suppose If we have variable ' I ' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ?&lt;br /&gt;In servlets, we are having a web page that is invoking servlets username and password ? which is cheks in the database ? Suppose the second page also If we want to verify the same information whethe it will connect to the database or it will be used previous information?&lt;br /&gt;What are virtual functions ?&lt;br /&gt;Write down how will you create a binary Tree ?&lt;br /&gt;What are the traverses in Binary Tree ?&lt;br /&gt;Write a program for recursive Traverse ?&lt;br /&gt;What are session variable in Servlets ?&lt;br /&gt;What is client server computing ?&lt;br /&gt;What is Constructor and Virtual function? Can we call Virtual funciton in a constructor ?&lt;br /&gt;Why we use OOPS concepts? What is its advantage ?&lt;br /&gt;What is the middleware ? What is the functionality of Webserver ?&lt;br /&gt;Why Java is not 100 % pure OOPS ? ( EcomServer )&lt;br /&gt;When we will use an Interface and Abstract class ?&lt;br /&gt;What is an RMI?&lt;br /&gt;How will you pass parameters in RMI ? Why u serialize?&lt;br /&gt;What is the exact difference in between Unicast and Multicast object ? Where we will use ?&lt;br /&gt;What is the main functionality of the Remote Reference Layer ?&lt;br /&gt;How do you download stubs from a Remote place ?&lt;br /&gt;What is the difference in between C++ and Java ? can u explain in detail ?&lt;br /&gt;I want to store more than 10 objects in a remote server ? Which methodology will follow ?&lt;br /&gt;What is the main functionality of the Prepared Statement ?&lt;br /&gt;What is meant by static query and dynamic query ?&lt;br /&gt;What are the Normalization Rules ? Define the Normalization ?&lt;br /&gt;What is meant by Servelet? What are the parameters of the service method ?&lt;br /&gt;What is meant by Session ? Tell me something about HTTPSession Class ?&lt;br /&gt;How do you invoke a Servelt? What is the difference in between doPost and doGet methods ?&lt;br /&gt;What is the difference in between the HTTPServlet and Generic Servlet ? Expalin their methods ? Tell me their parameter names also ?&lt;br /&gt;Have you used threads in Servelet ?&lt;br /&gt;Write a program on RMI and JDBC using StoredProcedure ?&lt;br /&gt;How do you sing an Applet ?&lt;br /&gt;In a Container there are 5 components. I want to display the all the components names, how will you do that one ?&lt;br /&gt;Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ?&lt;br /&gt;Tell me the latest versions in JAVA related areas ?&lt;br /&gt;What is meant by class loader ? How many types are there? When will we use them ?&lt;br /&gt;How do you load an Image in a Servlet ?&lt;br /&gt;What is meant by flickering ?&lt;br /&gt;What is meant by distributed Application ? Why we are using that in our applications ?&lt;br /&gt;What is the functionality of the stub ?&lt;br /&gt;Have you used any version control ?&lt;br /&gt;What is the latest version of JDBC ? What are the new features are added in that ?&lt;br /&gt;Explain 2 tier and 3 -tier Architecture ?&lt;br /&gt;What is the role of the webserver ?&lt;br /&gt;How have you done validation of the fileds in your project ?&lt;br /&gt;What is the main difficulties that you are faced in your project ?&lt;br /&gt;What is meant by cookies ? Explain ?&lt;br /&gt;Problem faced in your earlier project&lt;br /&gt;How OOPS concept is achieved in Java&lt;br /&gt;Features for using Java&lt;br /&gt;How does Java 2.0 differ from Java 1.0&lt;br /&gt;Public static void main – Explain&lt;br /&gt;What are command line arguments&lt;br /&gt;Explain about the three-tier model&lt;br /&gt;Difference between String &amp;amp; StringBuffer&lt;br /&gt;Wrapper class. Is String a Wrapper Class&lt;br /&gt;What are the restriction for static method&lt;br /&gt;Purpose of the file class&lt;br /&gt;Default modifier in Interface&lt;br /&gt;Difference between Interface &amp; Abstract class&lt;br /&gt;Can abstract be declared as Final&lt;br /&gt;Can we declare variables inside a method as Final Variables&lt;br /&gt;What is the package concept and use of package&lt;br /&gt;How can a dead thread be started&lt;br /&gt;Difference between Applet &amp;amp; Application&lt;br /&gt;Life cycle of the Applet&lt;br /&gt;Can Applet have constructors&lt;br /&gt;Differeence between canvas class &amp; graphics class&lt;br /&gt;Explain about Superclass &amp;amp; subclass&lt;br /&gt;Difference between TCP &amp; UDP&lt;br /&gt;What is AppletStub&lt;br /&gt;Explain Stream Tokenizer&lt;br /&gt;What is the difference between two types of threads&lt;br /&gt;Checked &amp;amp; Unchecked exception&lt;br /&gt;Use of throws exception&lt;br /&gt;What is finally in exception handling&lt;br /&gt;Vector class&lt;br /&gt;What will happen to the Exception object after exception handling&lt;br /&gt;Two types of multi-tasking&lt;br /&gt;Two ways to create the thread&lt;br /&gt;Synchronization&lt;br /&gt;I/O Filter&lt;br /&gt;How can you retrieve warnings in JDBC&lt;br /&gt;Can applet in different page communicate with each other&lt;br /&gt;Four driver Manager&lt;br /&gt;Features of JDBC 20&lt;br /&gt;Explain about stored procedures&lt;br /&gt;Servlet Life cycle&lt;br /&gt;Why do you go for servlet rather than CGI&lt;br /&gt;How to generate skeleton &amp; Stub classes&lt;br /&gt;Explain lazy activation&lt;br /&gt;Firewalls in RMI&lt;br /&gt;&lt;br /&gt;What is meant by Java ?&lt;br /&gt;What is meant by a class ?&lt;br /&gt;What is meant by a method ?&lt;br /&gt;What are the OOPS concepts in Java ?&lt;br /&gt;What is meant by encapsulation ? Explain with an example&lt;br /&gt;What is meant by inheritance ? Explain with an example&lt;br /&gt;What is meant by polymorphism ? Explain with an example&lt;br /&gt;Is multiple inheritance allowed in Java ? Why ?&lt;br /&gt;What is meant by Java interpreter ?&lt;br /&gt;What is meant by JVM ?&lt;br /&gt;What is a compilation unit ?&lt;br /&gt;What is meant by identifiers ?&lt;br /&gt;What are the different types of modifiers ?&lt;br /&gt;What are the access modifiers in Java ?&lt;br /&gt;What are the primitive data types in Java ?&lt;br /&gt;What is meant by a wrapper class ?&lt;br /&gt;What is meant by static variable and static method ?&lt;br /&gt;What is meant by Garbage collection ?&lt;br /&gt;What is meant by abstract class&lt;br /&gt;What is meant by final class, methods and variables ?&lt;br /&gt;What is meant by interface ?&lt;br /&gt;What is meant by a resource leak ?&lt;br /&gt;What is the difference between interface and abstract class ?&lt;br /&gt;What is the difference between public private, protected and static&lt;br /&gt;What is meant by method overloading ?&lt;br /&gt;What is meant by method overriding ?&lt;br /&gt;What is singleton class ?&lt;br /&gt;What is the difference between an array and a vector ?&lt;br /&gt;What is meant by constructor ?&lt;br /&gt;What is meant by casting ?&lt;br /&gt;What is the difference between final, finally and finalize ?&lt;br /&gt;What is meant by packages ?&lt;br /&gt;What are all the packages ?&lt;br /&gt;Name 2 calsses you have used ?&lt;br /&gt;Name 2 classes that can store arbitrary number of objects ?&lt;br /&gt;What is the difference between java.applet.* and java.applet.Applet ?&lt;br /&gt;What is a default package ?&lt;br /&gt;What is meant by a super class and how can you call a super class ?&lt;br /&gt;What is anonymous class ?&lt;br /&gt;Name interfaces without a method ?&lt;br /&gt;What is the use of an interface ?&lt;br /&gt;What is a serializable interface ?&lt;br /&gt;How to prevent field from serialization ?&lt;br /&gt;What is meant by exception ?&lt;br /&gt;How can you avoid the runtime exception ?&lt;br /&gt;What is the difference between throw and throws ?&lt;br /&gt;What is the use of finally ?&lt;br /&gt;Can multiple catch statements be used in exceptions ?&lt;br /&gt;Is it possible to write a try within a try statement ?&lt;br /&gt;What is the method to find if the object exited or not ?&lt;br /&gt;What is meant by a Thread ?&lt;br /&gt;What is meant by multi-threading ?&lt;br /&gt;What is the 2 way of creating a thread ? Which is the best way and why ?&lt;br /&gt;What is the method to find if a thread is active or not ?&lt;br /&gt;What are the thread-to-thread communcation ?&lt;br /&gt;What is the difference between sleep and suspend ?&lt;br /&gt;Can thread become a member of another thread ?&lt;br /&gt;What is meant by deadlock ?&lt;br /&gt;How can you avoid a deadlock ?&lt;br /&gt;What are the three typs of priority ?&lt;br /&gt;What is the use of synchronizations ?&lt;br /&gt;Garbage collector thread belongs to which priority ?&lt;br /&gt;What is meant by time-slicing ?&lt;br /&gt;What is the use of ‘this’ ?&lt;br /&gt;How can you find the length and capacity of a string buffer ?&lt;br /&gt;How to compare two strings ?&lt;br /&gt;What are the interfaces defined by Java.lang ?&lt;br /&gt;What is the purpose of run-time class and system class&lt;br /&gt;What is meant by Stream and Types ?&lt;br /&gt;What is the method used to clear the buffer ?&lt;br /&gt;What is meant by Stream Tokenizer ?&lt;br /&gt;What is serialization and de-serialisation ?&lt;br /&gt;What is meant by Applet ?&lt;br /&gt;How to find the host from which the Applet has originated ?&lt;br /&gt;What is the life cycle of an Applet ?&lt;br /&gt;How do you load an HTML page from an Applet ?&lt;br /&gt;What is meant by Applet Stub Interface ?&lt;br /&gt;What is meant by getCodeBase and getDocumentBase method ?&lt;br /&gt;How can you call an applet from a HTML file&lt;br /&gt;What is meant by Applet Flickering ?&lt;br /&gt;What is the use of parameter tag ?&lt;br /&gt;What is audio clip Interface and what are all the methods in it ?&lt;br /&gt;What is the difference between getAppletInfo and getParameterInfo ?&lt;br /&gt;How to communicate between applet and an applet ?&lt;br /&gt;What is meant by event handling ?&lt;br /&gt;What are all the listeners in java and explain ?&lt;br /&gt;What is meant by an adapter class ?&lt;br /&gt;What are the types of mouse event listeners ?&lt;br /&gt;What are the types of methods in mouse listeners ?&lt;br /&gt;What is the difference between panel and frame ?&lt;br /&gt;What is the default layout of the panel and frame ?&lt;br /&gt;What is meant by controls and types ?&lt;br /&gt;What is the difference between a scroll bar and a scroll panel.&lt;br /&gt;What is the difference between list and choice ?&lt;br /&gt;How to place a component on Windows ?&lt;br /&gt;What are the different types of Layouts ?&lt;br /&gt;What is meant by CardLayout ?&lt;br /&gt;What is the difference between GridLayout and GridBagLayout&lt;br /&gt;What is the difference between menuitem and checkboxmenu item.&lt;br /&gt;What is meant by vector class, dictionary class , hash table class,and property class ?&lt;br /&gt;Which class has no duplicate elements ?&lt;br /&gt;What is resource bundle ?&lt;br /&gt;What is an enumeration class ?&lt;br /&gt;What is meant by Swing ?&lt;br /&gt;What is the difference between AWT and Swing ?&lt;br /&gt;What is the difference between an applet and a Japplet&lt;br /&gt;What are all the components used in Swing ?&lt;br /&gt;What is meant by tab pans ?&lt;br /&gt;What is the use of JTree ?&lt;br /&gt;How can you add and remove nodes in Jtree.&lt;br /&gt;What is the method to expand and collapse nodes in a Jtree ?&lt;br /&gt;What is the use of JTable ?&lt;br /&gt;What is meant by JFC ?&lt;br /&gt;What is the class in Swing to change the appearance of the Frame in Runtime.&lt;br /&gt;How to reduce flicking in animation ?&lt;br /&gt;What is JDBC ?&lt;br /&gt;How do you connect to the database ? What are the steps ?&lt;br /&gt;What are the drivers available in JDBC ? Explain&lt;br /&gt;How can you load the driver ?&lt;br /&gt;What are the different types of statement s ?&lt;br /&gt;How can you created JDBC statements ?&lt;br /&gt;How will you perform transactions using JDBC ?&lt;br /&gt;What are the two drivers for web apllication?&lt;br /&gt;What are the different types of 2 tier and 3 tier architecture ?&lt;br /&gt;How can you retrieve warning in JDBC ?&lt;br /&gt;What is the exception thrown by JDBC ?&lt;br /&gt;What is meants by PreparedStatement ?&lt;br /&gt;What is difference between PreparedStatement and Statement ?&lt;br /&gt;How can you call the stored procedures ?&lt;br /&gt;What is meant by a ResultSet ?&lt;br /&gt;What is the difference between ExecuteUpdate and ExecuteQuery ?&lt;br /&gt;How do you know which driver is connected to a database ?&lt;br /&gt;What is DSN and System DSN and differentiate these two ?&lt;br /&gt;What is meant by TCP, IP, UDP ?&lt;br /&gt;What is the difference between TCP and UDP ?&lt;br /&gt;What is a proxy server ?&lt;br /&gt;What is meant by URL&lt;br /&gt;What is a socket and server sockets ?&lt;br /&gt;When MalformedURLException and UnknownHost Exception throws ?&lt;br /&gt;What is InetAddress ?&lt;br /&gt;What is datagram and datagram packets and datagram sockets ?&lt;br /&gt;Write the range of multicast socket IP address ?&lt;br /&gt;What is meant by a servlet ?&lt;br /&gt;What are the types of servlets ? Explain&lt;br /&gt;What is the different between a Servlet and a CGI.&lt;br /&gt;What is the difference between 2 types of Servlets ?&lt;br /&gt;What is the type of method for sending request from HTTP server ?&lt;br /&gt;What are the exceptions thrown by Servlets ? Why ?&lt;br /&gt;What is the life cycle of a servlet ?&lt;br /&gt;What is meant by cookies ?&lt;br /&gt;What is HTTP Session ?&lt;br /&gt;What is the difference between GET and POST methods ?&lt;br /&gt;How can you run a Servlet Program ?&lt;br /&gt;How to commuincate between an applet and a servlet ?&lt;br /&gt;What is a Servlet-to-Servlet communcation ?&lt;br /&gt;What is Session Tracking ?&lt;br /&gt;What are the security issues in Servlets ?&lt;br /&gt;What is HTTP Tunneling&lt;br /&gt;How do you load an image in a Servlet ?&lt;br /&gt;What is Servlet Chaining ?&lt;br /&gt;What is URL Rewriting ?&lt;br /&gt;What is context switching ?&lt;br /&gt;What is meant by RMI ?&lt;br /&gt;Explain RMI Architecture ?&lt;br /&gt;What is meant by a stub ?&lt;br /&gt;What is meant by a skelotn ?&lt;br /&gt;What is meant by serialisation and deserialisation ?&lt;br /&gt;What is meant by RRL ?&lt;br /&gt;What is the use of TL ?&lt;br /&gt;What is RMI Registry ?&lt;br /&gt;What is rmic ?&lt;br /&gt;How will you pass parameter in RMI ?&lt;br /&gt;What exceptions are thrown by RMI ?&lt;br /&gt;What are the steps involved in RMI ?&lt;br /&gt;What is meant by bind(), rebind(), unbind() and lookup() methods&lt;br /&gt;What are the advanatages of RMI ?&lt;br /&gt;What is JNI ?&lt;br /&gt;What is Remote Interface ?&lt;br /&gt;What class is used to create Server side object ?&lt;br /&gt;What class is used to bind the server object with RMI Registry ?&lt;br /&gt;What is the use of getWriter method ?&lt;br /&gt;What is meant by Javabeans ?&lt;br /&gt;What is JAR file ?&lt;br /&gt;What is meant by manifest files ?&lt;br /&gt;What is Introspection ?&lt;br /&gt;What are the steps involved to create a bean ?&lt;br /&gt;Say any two properties in Beans ?&lt;br /&gt;What is persistence ?&lt;br /&gt;What is the use of beaninfo ?&lt;br /&gt;What are the interfaces you used in Beans ?&lt;br /&gt;What are the classes you used in Beans ?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;JAVA and EJB - INTERVIEW QUESTIONS&lt;br /&gt;What is Entity Bean and Session Bean ?&lt;br /&gt;What are the methods of Entity Bean?&lt;br /&gt;How does Stateful Session bean store its state ?&lt;br /&gt;Why does Stateless Session bean not store its state even though it has ejbActivate and ejbPassivate ?&lt;br /&gt;What are the services provided by the container ?&lt;br /&gt;Types of transaction ?&lt;br /&gt;What is bean managed transaction ?&lt;br /&gt;Why does EJB needs two interface( Home and Remote Interface) ?&lt;br /&gt;What are transaction attributes ?&lt;br /&gt;What is the difference between Container managed persistent bean and Bean managed persistent entity bean ?&lt;br /&gt;What is J2EE ?&lt;br /&gt;What is JTS ?&lt;br /&gt;How many entity beans used and how many tables can u use in EJB project ?&lt;br /&gt;What is scalable,portability in J2EE?&lt;br /&gt;What is Connection pooling?Is it advantageous?&lt;br /&gt;Method and class used for Connection pooling ?&lt;br /&gt;How to deploy in J2EE(i.e Jar,War file) ?&lt;br /&gt;How is entity bean created using Container managed entity bean ?&lt;br /&gt;Sotware architechture of EJB ?&lt;br /&gt;In Entity bean will the create method in EJB home and ejbCreate in Entity bean have the same parameters ?&lt;br /&gt;What methods do u use in Servlet – Applet communication ?&lt;br /&gt;What are the types of Servlet ?&lt;br /&gt;Difference between HttpServlet and Generic Servlets ?&lt;br /&gt;Difference between doGet and doPost ?&lt;br /&gt;What are the methods in HttpServlet?&lt;br /&gt;What are the types of SessionTracking?&lt;br /&gt;What is Cookie ? Why is Cookie used ?&lt;br /&gt;If my browser does not support Cookie,and my server sends a cookie instance What will happen ?&lt;br /&gt;Why do u use Session Tracking in HttpServlet ?&lt;br /&gt;Can u use javaScript in Servlets ?&lt;br /&gt;What is the capacity the doGet can send to the server ?&lt;br /&gt;What are the type of protocols used in HttpServlet ?&lt;br /&gt;Difference between TCP/IP and IP protocol ?&lt;br /&gt;Why do you use UniCastRemoteObject in RMI ?&lt;br /&gt;How many interfaces are used in RMI?&lt;br /&gt;Can Rmi registry be written in the code, without having to write it in the command prompt and if yes where?&lt;br /&gt;Why is Socket used ?&lt;br /&gt;What are the types of JDBC drivers ?&lt;br /&gt;Explain the third driver(Native protocol driver) ?&lt;br /&gt;Which among the four driver is pure Java driver ?&lt;br /&gt;What are the Isolation level in JDBC transaction ?&lt;br /&gt;How do you connect with the database ?&lt;br /&gt;How do you connect without the Class.forName (" ") ?&lt;br /&gt;What does Class.forName return ?&lt;br /&gt;What are the types of statement ?&lt;br /&gt;Why is preparedStatement,CallableStatement used for?&lt;br /&gt;In real time project which driver did u use ?&lt;br /&gt;Difference between AWT and Swing compenents ?&lt;br /&gt;Is there any heavy weight component in Swings ?&lt;br /&gt;Can the Swing application if you upload in net, be compatible with your browser?&lt;br /&gt;What should you do get your browser compatible with swing components?&lt;br /&gt;What are the methods in Applet ?&lt;br /&gt;When is init(),start() called ?&lt;br /&gt;When you navigate from one applet to another what are the methods called ?&lt;br /&gt;What is the difference between Trusted and Untrusted Applet ?&lt;br /&gt;What is Exception ?&lt;br /&gt;What are the ways you can handle exception ?&lt;br /&gt;When is try,catch block used ?&lt;br /&gt;What is finally method in Exceptions ?&lt;br /&gt;What are the types of access modifiers ?&lt;br /&gt;What is protected and friendly ?&lt;br /&gt;What are the other modifiers ?&lt;br /&gt;Is synchronised modifier ?&lt;br /&gt;What is meant by polymorphism ?&lt;br /&gt;What is inheritance ?&lt;br /&gt;What is method Overloading ? What is this in OOPS ?&lt;br /&gt;What is method Overriding ? What is it in OOPS ?&lt;br /&gt;Does java support multi dimensional arrays ?&lt;br /&gt;Is multiple inheritance used in Java ?&lt;br /&gt;How do you send a message to the browser in JavaScript ?&lt;br /&gt;Does javascript support multidimensional arrays ?&lt;br /&gt;Why is XML used mainly?&lt;br /&gt;Do use coding for database connectivity in XML?&lt;br /&gt;What is DTD ?&lt;br /&gt;Is there any tool in java that can create reports ?&lt;br /&gt;Interview Questions in Core Java&lt;br /&gt;&lt;br /&gt;1.what is a transient variable?&lt;br /&gt;A transient variable is a variable that may not be serialized.&lt;br /&gt;&lt;br /&gt;2.which containers use a border Layout as their default layout?&lt;br /&gt;The window, Frame and Dialog classes use a border layout as their default layout.&lt;br /&gt;&lt;br /&gt;3.Why do threads block on I/O?&lt;br /&gt;Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o&lt;br /&gt;Operation is performed.&lt;br /&gt;&lt;br /&gt;4. How are Observer and Observable used?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;5. What is synchronization and why is it important?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;6. Can a lock be acquired on a class?&lt;br /&gt;Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;7. What's new with the stop(), suspend() and resume() methods in JDK 1.2?&lt;br /&gt;The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.&lt;br /&gt;&lt;br /&gt;8. Is null a keyword?&lt;br /&gt;The null value is not a keyword.&lt;br /&gt;&lt;br /&gt;9. What is the preferred size of a component?&lt;br /&gt;The preferred size of a component is the minimum component size that will allow the component to display normally.&lt;br /&gt;&lt;br /&gt;10. What method is used to specify a container's layout?&lt;br /&gt;The setLayout() method is used to specify a container's layout.&lt;br /&gt;&lt;br /&gt;11. Which containers use a FlowLayout as their default layout?&lt;br /&gt;The Panel and Applet classes use the FlowLayout as their default layout.&lt;br /&gt;&lt;br /&gt;12. What state does a thread enter when it terminates its processing?&lt;br /&gt;When a thread terminates its processing, it enters the dead state.&lt;br /&gt;&lt;br /&gt;13. What is the Collections API?&lt;br /&gt;The Collections API is a set of classes and interfaces that support operations on collections of objects.&lt;br /&gt;&lt;br /&gt;14. Which characters may be used as the second character of an identifier,&lt;br /&gt;but not as the first character of an identifier?&lt;br /&gt;The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.&lt;br /&gt;&lt;br /&gt;15. What is the List interface?&lt;br /&gt;The List interface provides support for ordered collections of objects.&lt;br /&gt;&lt;br /&gt;16. How does Java handle integer overflows and underflows?&lt;br /&gt;It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;17. What is the Vector class?&lt;br /&gt;The Vector class provides the capability to implement a growable array of objects&lt;br /&gt;&lt;br /&gt;18. What modifiers may be used with an inner class that is a member of an outer class?&lt;br /&gt;A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.&lt;br /&gt;&lt;br /&gt;19. What is an Iterator interface?&lt;br /&gt;The Iterator interface is used to step through the elements of a Collection.&lt;br /&gt;&lt;br /&gt;20. What is the difference between the &gt;&gt; and &gt;&gt;&gt; operators?&lt;br /&gt;The &gt;&gt; operator carries the sign bit when shifting right. The &gt;&gt;&gt; zero-fills bits that have been shifted out.&lt;br /&gt;&lt;br /&gt;21. Which method of the Component class is used to set the position and&lt;br /&gt;size of a component?&lt;br /&gt;setBounds()&lt;br /&gt;&lt;br /&gt;22. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?&lt;br /&gt;Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.&lt;br /&gt;&lt;br /&gt;23What is the difference between yielding and sleeping?&lt;br /&gt;When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.&lt;br /&gt;&lt;br /&gt;24. Which java.util classes and interfaces support event handling?&lt;br /&gt;The EventObject class and the EventListener interface support event processing.&lt;br /&gt;&lt;br /&gt;25. Is sizeof a keyword?&lt;br /&gt;The sizeof operator is not a keyword.&lt;br /&gt;&lt;br /&gt;26. What are wrapped classes?&lt;br /&gt;Wrapped classes are classes that allow primitive types to be accessed as objects.&lt;br /&gt;&lt;br /&gt;27. Does garbage collection guarantee that a program will not run out of memory?&lt;br /&gt;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&lt;br /&gt;&lt;br /&gt;28. What restrictions are placed on the location of a package statement&lt;br /&gt;within a source code file?&lt;br /&gt;A package statement must appear as the first line in a source code file (excluding blank lines and comments).&lt;br /&gt;&lt;br /&gt;29. Can an object's finalize() method be invoked while it is reachable?&lt;br /&gt;An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.&lt;br /&gt;&lt;br /&gt;30. What is the immediate superclass of the Applet class?&lt;br /&gt;Panel&lt;br /&gt;&lt;br /&gt;31. What is the difference between preemptive scheduling and time slicing?&lt;br /&gt;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&lt;br /&gt;other factors.&lt;br /&gt;&lt;br /&gt;32. Name three Component subclasses that support painting.&lt;br /&gt;The Canvas, Frame, Panel, and Applet classes support painting.&lt;br /&gt;&lt;br /&gt;33. What value does readLine() return when it has reached the end of a file?&lt;br /&gt;The readLine() method returns null when it has reached the end of a file.&lt;br /&gt;&lt;br /&gt;34. What is the immediate superclass of the Dialog class?&lt;br /&gt;Window&lt;br /&gt;&lt;br /&gt;35. What is clipping?&lt;br /&gt;Clipping is the process of confining paint operations to a limited area or shape.&lt;br /&gt;&lt;br /&gt;36. What is a native method?&lt;br /&gt;A native method is a method that is implemented in a language other than Java.&lt;br /&gt;&lt;br /&gt;37. Can a for statement loop indefinitely?&lt;br /&gt;Yes, a for statement can loop indefinitely. For example, consider the following:&lt;br /&gt;for(;;) ;&lt;br /&gt;&lt;br /&gt;38. What are order of precedence and associativity, and how are they used?&lt;br /&gt;Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left&lt;br /&gt;&lt;br /&gt;39. When a thread blocks on I/O, what state does it enter?&lt;br /&gt;A thread enters the waiting state when it blocks on I/O.&lt;br /&gt;&lt;br /&gt;40. To what value is a variable of the String type automatically initialized?&lt;br /&gt;The default value of an String type is null.&lt;br /&gt;&lt;br /&gt;41. What is the catch or declare rule for method declarations?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;42. What is the difference between a MenuItem and a CheckboxMenuItem?&lt;br /&gt;The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.&lt;br /&gt;&lt;br /&gt;43. What is a task's priority and how is it used in scheduling?&lt;br /&gt;A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.&lt;br /&gt;&lt;br /&gt;44. What class is the top of the AWT event hierarchy?&lt;br /&gt;The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.&lt;br /&gt;&lt;br /&gt;45. When a thread is created and started, what is its initial state?&lt;br /&gt;A thread is in the ready state after it has been created and started.&lt;br /&gt;&lt;br /&gt;46. Can an anonymous class be declared as implementing an interface and extending a class?&lt;br /&gt;An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.&lt;br /&gt;&lt;br /&gt;47. What is the range of the short type?&lt;br /&gt;The range of the short type is -(2^15) to 2^15 - 1.&lt;br /&gt;&lt;br /&gt;48. What is the range of the char type?&lt;br /&gt;The range of the char type is 0 to 2^16 - 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;49. In which package are most of the AWT events that support the event-delegation&lt;br /&gt;model defined?&lt;br /&gt;Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.&lt;br /&gt;&lt;br /&gt;50. What is the immediate superclass of Menu?&lt;br /&gt;MenuItem&lt;br /&gt;&lt;br /&gt;51. What is the purpose of finalization?&lt;br /&gt;The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.&lt;br /&gt;&lt;br /&gt;52. Which class is the immediate superclass of the MenuComponent class.&lt;br /&gt;Object&lt;br /&gt;&lt;br /&gt;53. What invokes a thread's run() method?&lt;br /&gt;After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.&lt;br /&gt;&lt;br /&gt;54. What is the difference between the Boolean &amp; operator and the &amp;amp;&amp; operator?&lt;br /&gt;If an expression involving the Boolean &amp;amp; operator is evaluated, both operands are evaluated. Then the &amp; operator is applied to the operand. When an expression involving the &amp;amp;&amp; operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The &amp;amp;&amp; operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.&lt;br /&gt;&lt;br /&gt;55. Name three subclasses of the Component class.&lt;br /&gt;Box.Filler, Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, or TextComponent&lt;br /&gt;&lt;br /&gt;56. What is the GregorianCalendar class?&lt;br /&gt;The GregorianCalendar provides support for traditional Western calendars.&lt;br /&gt;&lt;br /&gt;57. Which Container method is used to cause a container to be laid out and redisplayed?&lt;br /&gt;validate()&lt;br /&gt;&lt;br /&gt;58. What is the purpose of the Runtime class?&lt;br /&gt;The purpose of the Runtime class is to provide access to the Java runtime system.&lt;br /&gt;&lt;br /&gt;59. How many times may an object's finalize() method be invoked by the&lt;br /&gt;garbage collector?&lt;br /&gt;An object's finalize() method may only be invoked once by the garbage collector.&lt;br /&gt;&lt;br /&gt;60. What is the purpose of the finally clause of a try-catch-finally statement?&lt;br /&gt;The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.&lt;br /&gt;&lt;br /&gt;61. What is the argument type of a program's main() method?&lt;br /&gt;A program's main() method takes an argument of the String[] type.&lt;br /&gt;&lt;br /&gt;62. Which Java operator is right associative?&lt;br /&gt;The = operator is right associative.&lt;br /&gt;&lt;br /&gt;63. What is the Locale class?&lt;br /&gt;The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;64. Can a double value be cast to a byte?&lt;br /&gt;Yes, a double value can be cast to a byte.&lt;br /&gt;&lt;br /&gt;65. What is the difference between a break statement and a continue statement?&lt;br /&gt;A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.&lt;br /&gt;&lt;br /&gt;66. What must a class do to implement an interface?&lt;br /&gt;It must provide all of the methods in the interface and identify the interface in its implements clause.&lt;br /&gt;&lt;br /&gt;67. What method is invoked to cause an object to begin executing as a separate thread?&lt;br /&gt;The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.&lt;br /&gt;&lt;br /&gt;68. Name two subclasses of the TextComponent class.&lt;br /&gt;TextField and TextArea&lt;br /&gt;&lt;br /&gt;69. What is the advantage of the event-delegation model over the earlier event-inheritance model?&lt;br /&gt;The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation&lt;br /&gt;between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance&lt;br /&gt;model.&lt;br /&gt;&lt;br /&gt;70. Which containers may have a MenuBar?&lt;br /&gt;Frame&lt;br /&gt;&lt;br /&gt;71. How are commas used in the intialization and iteration parts of a for statement?&lt;br /&gt;Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;72. What is the purpose of the wait(), notify(), and notifyAll() methods?&lt;br /&gt;The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.&lt;br /&gt;&lt;br /&gt;73. What is an abstract method?&lt;br /&gt;An abstract method is a method whose implementation is deferred to a subclass.&lt;br /&gt;&lt;br /&gt;74. How are Java source code files named?&lt;br /&gt;A Java source code file takes the name of a public class or interface that is defined within the file. A source code file may contain at most one public class or interface. If a public class or interface is defined within a source code file, then the source code file must take the name of the public class or interface. If no public class or interface is defined&lt;br /&gt;within a source code file, then the file must take on a name that is different than its classes and interfaces. Source code files use the .java extension.&lt;br /&gt;&lt;br /&gt;75. What is the relationship between the Canvas class and the Graphics class?&lt;br /&gt;A Canvas object provides access to a Graphics object via its paint() method.&lt;br /&gt;&lt;br /&gt;76. What are the high-level thread states?&lt;br /&gt;The high-level thread states are ready, running, waiting, and dead.&lt;br /&gt;&lt;br /&gt;77. What value does read() return when it has reached the end of a file?&lt;br /&gt;The read() method returns -1 when it has reached the end of a file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;78. Can a Byte object be cast to a double value?&lt;br /&gt;No, an object cannot be cast to a primitive value.&lt;br /&gt;&lt;br /&gt;79. What is the difference between a static and a non-static inner class?&lt;br /&gt;A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.&lt;br /&gt;&lt;br /&gt;80. What is the difference between the String and StringBuffer classes?&lt;br /&gt;String objects are constants. StringBuffer objects are not.&lt;br /&gt;&lt;br /&gt;81. If a variable is declared as private, where may the variable be accessed?&lt;br /&gt;A private variable may only be accessed within the class in which it is declared.&lt;br /&gt;&lt;br /&gt;82. What is an object's lock and which object's have locks?&lt;br /&gt;An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;83. What is the Dictionary class?&lt;br /&gt;The Dictionary class provides the capability to store key-value pairs.&lt;br /&gt;&lt;br /&gt;84. How are the elements of a BorderLayout organized?&lt;br /&gt;The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container.&lt;br /&gt;&lt;br /&gt;85. What is the % operator?&lt;br /&gt;It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.&lt;br /&gt;&lt;br /&gt;86. When can an object reference be cast to an interface reference?&lt;br /&gt;An object reference be cast to an interface reference when the object implements the referenced interface.&lt;br /&gt;&lt;br /&gt;87. What is the difference between a Window and a Frame?&lt;br /&gt;The Frame class extends Window to define a main application window that can have a menu bar.&lt;br /&gt;&lt;br /&gt;88. Which class is extended by all other classes?&lt;br /&gt;The Object class is extended by all other classes.&lt;br /&gt;&lt;br /&gt;89. Can an object be garbage collected while it is still reachable?&lt;br /&gt;A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected..&lt;br /&gt;&lt;br /&gt;90. Is the ternary operator written x : y ? z or x ? y : z ?&lt;br /&gt;It is written x ? y : z.&lt;br /&gt;&lt;br /&gt;91. What is the difference between the Font and FontMetrics classes?&lt;br /&gt;The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.&lt;br /&gt;&lt;br /&gt;92. How is rounding performed under integer division?&lt;br /&gt;The fractional part of the result is truncated. This is known as rounding toward zero.&lt;br /&gt;&lt;br /&gt;93. What happens when a thread cannot acquire a lock on an object?&lt;br /&gt;If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;94. What is the difference between the Reader/Writer class hierarchy and the&lt;br /&gt;InputStream/OutputStream class hierarchy?&lt;br /&gt;The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.&lt;br /&gt;&lt;br /&gt;95. What classes of exceptions may be caught by a catch clause?&lt;br /&gt;A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.&lt;br /&gt;&lt;br /&gt;96. If a class is declared without any access modifiers, where may the class be accessed?&lt;br /&gt;A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.&lt;br /&gt;&lt;br /&gt;97. What is the SimpleTimeZone class?&lt;br /&gt;The SimpleTimeZone class provides support for a Gregorian calendar.&lt;br /&gt;&lt;br /&gt;98. What is the Map interface?&lt;br /&gt;The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;99. Does a class inherit the constructors of its superclass?&lt;br /&gt;A class does not inherit constructors from any of its superclasses.&lt;br /&gt;&lt;br /&gt;100. For which statements does it make sense to use a label?&lt;br /&gt;The only statements for which it makes sense to use a label are those statements that can enclose a break or continue statement.&lt;br /&gt;&lt;br /&gt;101. What is the purpose of the System class?&lt;br /&gt;The purpose of the System class is to provide access to system resources.&lt;br /&gt;&lt;br /&gt;102. Which TextComponent method is used to set a TextComponent to the read-only state?&lt;br /&gt;setEditable()&lt;br /&gt;&lt;br /&gt;103. How are the elements of a CardLayout organized?&lt;br /&gt;The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.&lt;br /&gt;&lt;br /&gt;104. Is &amp;amp;&amp;= a valid Java operator?&lt;br /&gt;No, it is not.&lt;br /&gt;&lt;br /&gt;105. Name the eight primitive Java types.&lt;br /&gt;The eight primitive types are byte, char, short, int, long, float, double, and boolean.&lt;br /&gt;&lt;br /&gt;106. Which class should you use to obtain design information about an object?&lt;br /&gt;The Class class is used to obtain information about an object's design.&lt;br /&gt;&lt;br /&gt;107. What is the relationship between clipping and repainting?&lt;br /&gt;When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.&lt;br /&gt;&lt;br /&gt;108. Is "abc" a primitive value?&lt;br /&gt;The String literal "abc" is not a primitive value. It is a String object.&lt;br /&gt;&lt;br /&gt;109. What is the relationship between an event-listener interface and an&lt;br /&gt;event-adapter class?&lt;br /&gt;An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.&lt;br /&gt;&lt;br /&gt;110. What restrictions are placed on the values of each case of a switch statement?&lt;br /&gt;During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.&lt;br /&gt;&lt;br /&gt;111. What modifiers may be used with an interface declaration?&lt;br /&gt;An interface may be declared as public or abstract.&lt;br /&gt;&lt;br /&gt;112. Is a class a subclass of itself?&lt;br /&gt;A class is a subclass of itself.&lt;br /&gt;&lt;br /&gt;113. What is the highest-level event class of the event-delegation model?&lt;br /&gt;The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.&lt;br /&gt;&lt;br /&gt;114. What event results from the clicking of a button?&lt;br /&gt;The ActionEvent event is generated as the result of the clicking of a button.&lt;br /&gt;&lt;br /&gt;115. How can a GUI component handle its own events?&lt;br /&gt;A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.&lt;br /&gt;&lt;br /&gt;116. What is the difference between a while statement and a do statement?&lt;br /&gt;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&lt;br /&gt;always execute the body of a loop at least once.&lt;br /&gt;&lt;br /&gt;117. How are the elements of a GridBagLayout organized?&lt;br /&gt;The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.&lt;br /&gt;&lt;br /&gt;118. What advantage do Java's layout managers provide over traditional windowing systems?&lt;br /&gt;Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.&lt;br /&gt;&lt;br /&gt;119. What is the Collection interface?&lt;br /&gt;The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.&lt;br /&gt;&lt;br /&gt;120. What modifiers can be used with a local inner class?&lt;br /&gt;A local inner class may be final or abstract.&lt;br /&gt;&lt;br /&gt;121. What is the difference between static and non-static variables?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;122. What is the difference between the paint() and repaint() methods?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;123. What is the purpose of the File class?&lt;br /&gt;The File class is used to create objects that provide access to the files and directories of a local file system.&lt;br /&gt;&lt;br /&gt;124. Can an exception be rethrown?&lt;br /&gt;Yes, an exception can be rethrown.&lt;br /&gt;&lt;br /&gt;125. Which Math method is used to calculate the absolute value of a number?&lt;br /&gt;The abs() method is used to calculate absolute values.&lt;br /&gt;&lt;br /&gt;126. How does multithreading take place on a computer with a single CPU?&lt;br /&gt;The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.&lt;br /&gt;&lt;br /&gt;127. When does the compiler supply a default constructor for a class?&lt;br /&gt;The compiler supplies a default constructor for a class if no other constructors are provided.&lt;br /&gt;&lt;br /&gt;128. When is the finally clause of a try-catch-finally statement executed?&lt;br /&gt;The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.&lt;br /&gt;&lt;br /&gt;129. Which class is the immediate superclass of the Container class?&lt;br /&gt;Component&lt;br /&gt;&lt;br /&gt;130. If a method is declared as protected, where may the method be accessed?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;131. How can the Checkbox class be used to create a radio button?&lt;br /&gt;By associating Checkbox objects with a CheckboxGroup.&lt;br /&gt;&lt;br /&gt;132. Which non-Unicode letter characters may be used as the first character&lt;br /&gt;of an identifier?&lt;br /&gt;The non-Unicode letter characters $ and _ may appear as the first character of an identifier&lt;br /&gt;&lt;br /&gt;133. What restrictions are placed on method overloading?&lt;br /&gt;Two methods may not have the same name and argument list but different return types.&lt;br /&gt;&lt;br /&gt;134. What happens when you invoke a thread's interrupt method while it is&lt;br /&gt;sleeping or waiting?&lt;br /&gt;When a task's interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.&lt;br /&gt;&lt;br /&gt;135. What is casting?&lt;br /&gt;There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte&lt;br /&gt;values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.&lt;br /&gt;&lt;br /&gt;136. What is the return type of a program's main() method?&lt;br /&gt;A program's main() method has a void return type.&lt;br /&gt;&lt;br /&gt;137. Name four Container classes.&lt;br /&gt;Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane&lt;br /&gt;&lt;br /&gt;138. What is the difference between a Choice and a List?&lt;br /&gt;A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.&lt;br /&gt;&lt;br /&gt;139. What class of exceptions are generated by the Java run-time system?&lt;br /&gt;The Java runtime system generates RuntimeException and Error exceptions.&lt;br /&gt;&lt;br /&gt;140. What class allows you to read objects directly from a stream?&lt;br /&gt;The ObjectInputStream class supports the reading of objects from input streams.&lt;br /&gt;&lt;br /&gt;141. What is the difference between a field variable and a local variable?&lt;br /&gt;A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.&lt;br /&gt;&lt;br /&gt;142. Under what conditions is an object's finalize() method invoked by the garbage collector?&lt;br /&gt;The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.&lt;br /&gt;&lt;br /&gt;143. How are this() and super() used with constructors?&lt;br /&gt;this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.&lt;br /&gt;&lt;br /&gt;144. What is the relationship between a method's throws clause and the exceptions&lt;br /&gt;that can be thrown during the method's execution?&lt;br /&gt;A method's throws clause must declare any checked exceptions that are not caught within the body of the method.&lt;br /&gt;&lt;br /&gt;145. What is the difference between the JDK 1.02 event model and the event-delegation&lt;br /&gt;model introduced with JDK 1.1?&lt;br /&gt;The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model, components are required to handle their own events. If they do not handle a particular event, the event is inherited by (or bubbled up to) the component's container. The container then either handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried.&lt;br /&gt;&lt;br /&gt;In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhandled events.&lt;br /&gt;&lt;br /&gt;146. How is it possible for two String objects with identical values not to be equal&lt;br /&gt;under the == operator?&lt;br /&gt;The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.&lt;br /&gt;&lt;br /&gt;147. Why are the methods of the Math class static?&lt;br /&gt;So they can be invoked as if they are a mathematical code library.&lt;br /&gt;&lt;br /&gt;148. What Checkbox method allows you to tell if a Checkbox is checked?&lt;br /&gt;getState()&lt;br /&gt;&lt;br /&gt;149. What state is a thread in when it is executing?&lt;br /&gt;An executing thread is in the running state.&lt;br /&gt;&lt;br /&gt;150. What are the legal operands of the instanceof operator?&lt;br /&gt;The left operand is an object reference or null value and the right operand is a class, interface, or array type.&lt;br /&gt;&lt;br /&gt;151. How are the elements of a GridLayout organized?&lt;br /&gt;The elements of a GridBad layout are of equal size and are laid out using the squares of a grid.&lt;br /&gt;&lt;br /&gt;152. What an I/O filter?&lt;br /&gt;An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.&lt;br /&gt;&lt;br /&gt;153. If an object is garbage collected, can it become reachable again?&lt;br /&gt;Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;154. What is the Set interface?&lt;br /&gt;The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.&lt;br /&gt;&lt;br /&gt;155. What classes of exceptions may be thrown by a throw statement?&lt;br /&gt;A throw statement may throw any expression that may be assigned to the Throwable type.&lt;br /&gt;&lt;br /&gt;156. What are E and PI?&lt;br /&gt;E is the base of the natural logarithm and PI is mathematical value pi.&lt;br /&gt;&lt;br /&gt;157. Are true and false keywords?&lt;br /&gt;The values true and false are not keywords.&lt;br /&gt;&lt;br /&gt;158. What is a void return type?&lt;br /&gt;A void return type indicates that a method does not return a value.&lt;br /&gt;&lt;br /&gt;159. What is the purpose of the enableEvents() method?&lt;br /&gt;The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.&lt;br /&gt;&lt;br /&gt;160. What is the difference between the File and RandomAccessFile classes?&lt;br /&gt;The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.&lt;br /&gt;&lt;br /&gt;161. What happens when you add a double value to a String?&lt;br /&gt;The result is a String object.&lt;br /&gt;&lt;br /&gt;162. What is your platform's default character encoding?&lt;br /&gt;If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1..&lt;br /&gt;&lt;br /&gt;163. Which package is always imported by default?&lt;br /&gt;The java.lang package is always imported by default.&lt;br /&gt;&lt;br /&gt;164. What interface must an object implement before it can be written to a&lt;br /&gt;stream as an object?&lt;br /&gt;An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.&lt;br /&gt;&lt;br /&gt;165. How are this and super used?&lt;br /&gt;this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.&lt;br /&gt;&lt;br /&gt;166. What is the purpose of garbage collection?&lt;br /&gt;The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and&lt;br /&gt;reused.&lt;br /&gt;&lt;br /&gt;167. What is a compilation unit?&lt;br /&gt;A compilation unit is a Java source code file.&lt;br /&gt;&lt;br /&gt;168. What interface is extended by AWT event listeners?&lt;br /&gt;All AWT event listeners extend the java.util.EventListener interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;169. What restrictions are placed on method overriding?&lt;br /&gt;Overridden methods must have the same name, argument list, and return type.&lt;br /&gt;The overriding method may not limit the access of the method it overrides.&lt;br /&gt;The overriding method may not throw any exceptions that may not be thrown&lt;br /&gt;by the overridden method.&lt;br /&gt;&lt;br /&gt;170. How can a dead thread be restarted?&lt;br /&gt;A dead thread cannot be restarted.&lt;br /&gt;&lt;br /&gt;171. What happens if an exception is not caught?&lt;br /&gt;An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.&lt;br /&gt;&lt;br /&gt;172. What is a layout manager?&lt;br /&gt;A layout manager is an object that is used to organize components in a container.&lt;br /&gt;&lt;br /&gt;173. Which arithmetic operations can result in the throwing of an ArithmeticException?&lt;br /&gt;Integer / and % can result in the throwing of an ArithmeticException.&lt;br /&gt;&lt;br /&gt;174. What are three ways in which a thread can enter the waiting state?&lt;br /&gt;A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its&lt;br /&gt;(deprecated) suspend() method.&lt;br /&gt;&lt;br /&gt;175. Can an abstract class be final?&lt;br /&gt;An abstract class may not be declared as final.&lt;br /&gt;&lt;br /&gt;176. What is the ResourceBundle class?&lt;br /&gt;The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.&lt;br /&gt;&lt;br /&gt;177. What happens if a try-catch-finally statement does not have a catch clause&lt;br /&gt;to handle an exception that is thrown within the body of the try statement?&lt;br /&gt;The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination.&lt;br /&gt;&lt;br /&gt;178. What is numeric promotion?&lt;br /&gt;Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int&lt;br /&gt;values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.&lt;br /&gt;&lt;br /&gt;179. What is the difference between a Scrollbar and a ScrollPane?&lt;br /&gt;A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.&lt;br /&gt;&lt;br /&gt;180. What is the difference between a public and a non-public class?&lt;br /&gt;A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.&lt;br /&gt;&lt;br /&gt;181. To what value is a variable of the boolean type automatically initialized?&lt;br /&gt;The default value of the boolean type is false.&lt;br /&gt;&lt;br /&gt;182. Can try statements be nested?&lt;br /&gt;Try statements may be tested.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;183. What is the difference between the prefix and postfix forms of the ++ operator?&lt;br /&gt;The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.&lt;br /&gt;&lt;br /&gt;184. What is the purpose of a statement block?&lt;br /&gt;A statement block is used to organize a sequence of statements as a single statement group.&lt;br /&gt;&lt;br /&gt;185. What is a Java package and how is it used?&lt;br /&gt;A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.&lt;br /&gt;&lt;br /&gt;186. What modifiers may be used with a top-level class?&lt;br /&gt;A top-level class may be public, abstract, or final.&lt;br /&gt;&lt;br /&gt;187. What are the Object and Class classes used for?&lt;br /&gt;The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.&lt;br /&gt;&lt;br /&gt;188. How does a try statement determine which catch clause should be used&lt;br /&gt;to handle an exception?&lt;br /&gt;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 exception is executed.&lt;br /&gt;The remaining catch clauses are ignored.&lt;br /&gt;&lt;br /&gt;189. Can an unreachable object become reachable again?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;190. When is an object subject to garbage collection?&lt;br /&gt;An object is subject to garbage collection when it becomes unreachable to the program in which it is used.&lt;br /&gt;&lt;br /&gt;191. What method must be implemented by all threads?&lt;br /&gt;All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface.&lt;br /&gt;&lt;br /&gt;192. What methods are used to get and set the text label displayed by a Button object?&lt;br /&gt;getLabel() and setLabel()&lt;br /&gt;&lt;br /&gt;193. Which Component subclass is used for drawing and painting?&lt;br /&gt;Canvas&lt;br /&gt;&lt;br /&gt;194. What are synchronized methods and synchronized statements?&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;195. What are the two basic ways in which classes that can be run as threads&lt;br /&gt;may be defined?&lt;br /&gt;A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.&lt;br /&gt;&lt;br /&gt;196. What are the problems faced by Java programmers who don't use layout managers?&lt;br /&gt;Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.&lt;br /&gt;&lt;br /&gt;197. What is the difference between an if statement and a switch statement?&lt;br /&gt;The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.&lt;br /&gt;&lt;br /&gt;198. What happens when you add a double value to a String?&lt;br /&gt;The result is a String object.&lt;br /&gt;&lt;br /&gt;199. What is the List interface?&lt;br /&gt;The List interface provides support for ordered collections of objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Database - JDBC (java.sql)&lt;br /&gt;Connecting to a Database&lt;br /&gt;This example uses the JDBC-ODBC bridge to connect to a database called ''mydatabase''.&lt;br /&gt;try {&lt;br /&gt;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");&lt;br /&gt;String url = "jdbc:odbc:mydatabase";&lt;br /&gt;Connection con = DriverManager.getConnection(&lt;br /&gt;url, "login", "password");&lt;br /&gt;} catch (ClassNotFoundException e) {&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;Creating a Table&lt;br /&gt;This example creates a table called ''mytable'' with three columns: COL_A which holds strings, COL_B which holds integers, and COL_C which holds floating point numbers.&lt;br /&gt;try {&lt;br /&gt;Statement stmt = con.createStatement();&lt;br /&gt;stmt.executeUpdate("CREATE TABLE mytable (&lt;br /&gt;COL_A VARCHAR(100), COL_B INTEGER, COL_C FLOAT)");&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;Entering a New Row into a Table&lt;br /&gt;This example enters a row containing a string, an integer, and a floating point number into the table called ''mytable''.&lt;br /&gt;try {&lt;br /&gt;Statement stmt = connection.createStatement();&lt;br /&gt;stmt.executeUpdate("INSERT INTO mytable&lt;br /&gt;VALUES ('Patrick Chan', 123, 1.23)");&lt;br /&gt;connection.close();&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;Getting All Rows from a Table&lt;br /&gt;This example retrieves all the rows from a table called ''mytable''. A row in ''mytable'' consists of a string, integer, and floating point number.&lt;br /&gt;try {&lt;br /&gt;Statement stmt = connection.createStatement();&lt;br /&gt;// Get data using colunm names.&lt;br /&gt;ResultSet rs = stmt.executeQuery(&lt;br /&gt;"SELECT * FROM mytable");&lt;br /&gt;while (rs.next()) {&lt;br /&gt;String s = rs.getString("COL_A");&lt;br /&gt;int i = rs.getInt("COL_B");&lt;br /&gt;float f = rs.getFloat("COL_C");&lt;br /&gt;process(s, i, f);&lt;br /&gt;}&lt;br /&gt;// Get data using colunm numbers.&lt;br /&gt;rs = stmt.executeQuery(&lt;br /&gt;"SELECT * FROM mytable");&lt;br /&gt;while (rs.next()) {&lt;br /&gt;String s = rs.getString(1);&lt;br /&gt;int i = rs.getInt(2);&lt;br /&gt;float f = rs.getFloat(3);&lt;br /&gt;process(s, i, f);&lt;br /&gt;}&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;Getting Particular Rows from a Table&lt;br /&gt;This example retrieves all rows from a table called ''mytable'' whose column COL_A equals ``Patrick Chan''. A row in ''mytable'' consists of a string, integer, and floating point number.&lt;br /&gt;try {&lt;br /&gt;Statement stmt = connection.createStatement();&lt;br /&gt;ResultSet rs = stmt.executeQuery(&lt;br /&gt;"SELECT * FROM mytable WHERE COL_A = 'Patrick Chan'");&lt;br /&gt;rs.next();&lt;br /&gt;String s = rs.getString("COL_A");&lt;br /&gt;int i = rs.getInt("COL_B");&lt;br /&gt;float f = rs.getFloat("COL_C");&lt;br /&gt;process(s, i, f);&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;Updating a Row of Data in a Table&lt;br /&gt;This example updates a row in a table called ``mytable''. In particular, for all rows whose column COL_B equals 123, column COL_A is set to ''John Doe''.&lt;br /&gt;try {&lt;br /&gt;Statement stmt = connection.createStatement();&lt;br /&gt;int numUpdated = stmt.executeUpdate(&lt;br /&gt;"UPDATE mytable SET COL_A = 'John Doe'&lt;br /&gt;WHERE COL_B = 123");&lt;br /&gt;connection.close();&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;Using a Prepared Statement&lt;br /&gt;A prepared statement should be used in cases where a particular SQL statement is used frequently. The prepared statement is more expensive to set up but executes faster than a statement. This example demonstrates a prepared statement for getting all rows from a table called ''mytable'' whose column COL_A equals ''Patrick Chan''. This example also demonstrates a prepared statement for updating data in the table. In particular, for all rows whose column COL_B equals 123, column COL_A is set to ''John Doe''.&lt;br /&gt;try {&lt;br /&gt;// Retrieving rows from the database.&lt;br /&gt;PreparedStatement stmt = connection.prepareStatement(&lt;br /&gt;"SELECT * FROM mytable WHERE COL_A = ?");&lt;br /&gt;int colunm = 1;&lt;br /&gt;stmt.setString(colunm, "Patrick Chan");&lt;br /&gt;ResultSet rs = stmt.executeQuery();&lt;br /&gt;// Updating the database.&lt;br /&gt;stmt = connection.prepareStatement(&lt;br /&gt;"UPDATE mytable SET COL_A = ? WHERE COL_B = ?");&lt;br /&gt;colunm = 1;&lt;br /&gt;stmt.setString(colunm, "John Doe");&lt;br /&gt;colunm = 2;&lt;br /&gt;stmt.setInt(colunm, 123);&lt;br /&gt;int numUpdated = stmt.executeUpdate();&lt;br /&gt;} catch (SQLException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan.&lt;br /&gt;&lt;br /&gt;Handling Events with an Anonymous Class&lt;br /&gt;If an event handler is specific to a component (that is, not shared by other components), there is no need to declare a class to handle the event. The event handler can be implemented using an anonymous inner class. This example demonstrates an anonymous inner class to handle key events for a component.&lt;br /&gt;&lt;br /&gt;component.addKeyListener(new KeyAdapter() {&lt;br /&gt;public void keyPressed(KeyEvent evt) {&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;Handling Action Events&lt;br /&gt;Action events are fired by subclasses of AbstractButton and includes buttons, checkboxes, and menus.&lt;br /&gt;&lt;br /&gt;AbstractButton button = new JButton(quot;OK");&lt;br /&gt;button.addActionListener(new MyActionListener());&lt;br /&gt;public class MyActionListener&lt;br /&gt;implements ActionListener {&lt;br /&gt;public void actionPerformed(ActionEvent evt) {&lt;br /&gt;// Determine which abstract&lt;br /&gt;// button fired the event.&lt;br /&gt;AbstractButton button =&lt;br /&gt;(AbstractButton)evt.getSource();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Handling Key Presses&lt;br /&gt;You can get the key that was pressed either as a key character (which is a Unicode character) or as a key code (a special value representing a particular key on the keyboard).&lt;br /&gt;&lt;br /&gt;component.addKeyListener(new MyKeyListener());&lt;br /&gt;public class MyKeyListener extends KeyAdapter {&lt;br /&gt;public void keyPressed(KeyEvent evt) {&lt;br /&gt;// Check for key characters.&lt;br /&gt;if (evt.getKeyChar() == 'a') {&lt;br /&gt;process(evt.getKeyChar());&lt;br /&gt;}&lt;br /&gt;// Check for key codes.&lt;br /&gt;if (evt.getKeyCode() == KeyEvent.VK_HOME) {&lt;br /&gt;process(evt.getKeyCode());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Handling Mouse Clicks&lt;br /&gt;component.addMouseListener(&lt;br /&gt;new MyMouseListener());&lt;br /&gt;public class MyMouseListener&lt;br /&gt;extends MouseAdapter {&lt;br /&gt;public void mouseClicked(MouseEvent evt) {&lt;br /&gt;if ((evt.getModifiers() &amp;&lt;br /&gt;InputEvent.BUTTON1_MASK) != 0) {&lt;br /&gt;processLeft(evt.getPoint());&lt;br /&gt;}&lt;br /&gt;if ((evt.getModifiers() &amp;&lt;br /&gt;InputEvent.BUTTON2_MASK) != 0) {&lt;br /&gt;processMiddle(evt.getPoint());&lt;br /&gt;}&lt;br /&gt;if ((evt.getModifiers() &amp;&lt;br /&gt;InputEvent.BUTTON3_MASK) != 0) {&lt;br /&gt;processRight(evt.getPoint());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Handling Mouse Motion&lt;br /&gt;component.addMouseMotionListener(&lt;br /&gt;new MyMouseMotionListener());&lt;br /&gt;public class MyMouseMotionListener&lt;br /&gt;extends MouseMotionAdapter {&lt;br /&gt;public void mouseMoved(MouseEvent evt) {&lt;br /&gt;// Process current position of cursor&lt;br /&gt;// while all mouse buttons are up.&lt;br /&gt;process(evt.getPoint());&lt;br /&gt;}&lt;br /&gt;public void mouseDragged(MouseEvent evt) {&lt;br /&gt;// Process current position of cursor&lt;br /&gt;// while mouse button is pressed.&lt;br /&gt;process(evt.getPoint());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Detecting Double and Triple Clicks&lt;br /&gt;component.addMouseListener(&lt;br /&gt;new MyMouseListener());&lt;br /&gt;public class MyMouseListener extends MouseAdapter {&lt;br /&gt;public void mouseClicked(MouseEvent evt) {&lt;br /&gt;if (evt.getClickCount() == 3) {&lt;br /&gt;// triple-click&lt;br /&gt;} else if (evt.getClickCount() == 2) {&lt;br /&gt;// double-click&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Handling Focus Changes&lt;br /&gt;component.addFocusListener(&lt;br /&gt;new MyFocusListener());&lt;br /&gt;public class MyFocusListener&lt;br /&gt;extends FocusAdapter {&lt;br /&gt;public void focusGained(FocusEvent evt) {&lt;br /&gt;// The component gained the focus.&lt;br /&gt;}&lt;br /&gt;public void focusLost(FocusEvent evt) {&lt;br /&gt;// The component lost the focus.&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Files, Streams, I/O (java.io)&lt;br /&gt;Constructing a Path&lt;br /&gt;On Windows, this example creates the path \blash a\blash b. On Unix, the path would be /a/b.&lt;br /&gt;&lt;br /&gt;String path = File.separator +&lt;br /&gt;"a" + File.separator + "b";&lt;br /&gt;&lt;br /&gt;Reading Text from Standard Input&lt;br /&gt;try {&lt;br /&gt;BufferedReader in = new BufferedReader(&lt;br /&gt;new InputStreamReader(System.in));&lt;br /&gt;String str = "";&lt;br /&gt;while (str != null) {&lt;br /&gt;System.out.print("&gt; prompt ");&lt;br /&gt;str = in.readLine();&lt;br /&gt;process(str);&lt;br /&gt;}&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Reading Text from a File&lt;br /&gt;try {&lt;br /&gt;BufferedReader in = new BufferedReader(&lt;br /&gt;new FileReader("infilename"));&lt;br /&gt;String str;&lt;br /&gt;while ((str = in.readLine()) != null) {&lt;br /&gt;process(str);&lt;br /&gt;}&lt;br /&gt;in.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Writing to a File&lt;br /&gt;If the file does not already exist, it is automatically created.&lt;br /&gt;try {&lt;br /&gt;BufferedWriter out = new BufferedWriter(&lt;br /&gt;new FileWriter("outfilename"));&lt;br /&gt;out.write("aString");&lt;br /&gt;out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Creating a Directory&lt;br /&gt;(new File("directoryName")).mkdir();&lt;br /&gt;&lt;br /&gt;Appending to a File&lt;br /&gt;try {&lt;br /&gt;BufferedWriter out = new BufferedWriter(&lt;br /&gt;new FileWriter("filename", true));&lt;br /&gt;out.write("aString");&lt;br /&gt;out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;Deleting a File&lt;br /&gt;(new File("filename")).delete();&lt;br /&gt;&lt;br /&gt;Deleting a Directory&lt;br /&gt;(new File("directoryName")).delete();&lt;br /&gt;&lt;br /&gt;Creating a Temporary File&lt;br /&gt;try {&lt;br /&gt;// Create temp file.&lt;br /&gt;File temp = File.createTempFile(&lt;br /&gt;"pattern", ".suffix");&lt;br /&gt;// Delete temp file when program exits.&lt;br /&gt;temp.deleteOnExit();&lt;br /&gt;// Write to temp file&lt;br /&gt;BufferedWriter out = new BufferedWriter(&lt;br /&gt;new FileWriter(temp));&lt;br /&gt;out.write("aString");&lt;br /&gt;out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Using a Random Access File&lt;br /&gt;try {&lt;br /&gt;File f = new File("filename");&lt;br /&gt;RandomAccessFile raf =&lt;br /&gt;new RandomAccessFile(f, "rw");&lt;br /&gt;// Read a character.&lt;br /&gt;char ch = raf.readChar();&lt;br /&gt;// Seek to end of file.&lt;br /&gt;raf.seek(f.length());&lt;br /&gt;// Append to the end.&lt;br /&gt;raf.writeChars("aString");&lt;br /&gt;raf.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;Serializing an Object&lt;br /&gt;The object to be serialized must implement java.io.Serializable.&lt;br /&gt;try {&lt;br /&gt;ObjectOutput out = new ObjectOutputStream(&lt;br /&gt;new FileOutputStream("filename.ser"));&lt;br /&gt;out.writeObject(object);&lt;br /&gt;out.close();&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Deserializing an Object&lt;br /&gt;This example deserializes a java.awt.Button object.&lt;br /&gt;try {&lt;br /&gt;ObjectInputStream in = new ObjectInputStream(&lt;br /&gt;new FileInputStream("filename.ser"));&lt;br /&gt;AnObject object = (AnObject) in.readObject();&lt;br /&gt;in.close();&lt;br /&gt;} catch (ClassNotFoundException e) {&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Traversing a Directory&lt;br /&gt;public static void traverse(File f) {&lt;br /&gt;process(f);&lt;br /&gt;if (f.isDirectory()) {&lt;br /&gt;String[] children = f.list();&lt;br /&gt;for (int i=0; i&lt;children.length; class="" robj="(RObject)" socket="srv.accept();" port="url.getPort();" outbuf="new" inbuf="new" in="new" group="InetAddress.getByName(groupName);" msocket="new" request="new" wr="new" rd="new" srv="new" sock="new" addr="'InetAddress.getByName(" url="new" ref="url.getRef();" file="url.getFile();" host="url.getHost();" protocol="url.getProtocol();" out="new" str="in.readLine())" numbytesreceived="packet.getLength();" groupaddr="InetAddress.getByName("&gt; javac RObject.java RObjectImpl.java&lt;br /&gt;&lt;br /&gt;4. Generate the skeletons and stubs.&lt;br /&gt;&gt; rmic RObjectImpl&lt;br /&gt;&lt;br /&gt;5. Create an instance of RObjectImpl and bind it to the RMI Registry.&lt;br /&gt;try {&lt;br /&gt;RObject robj = new RObjectImpl();&lt;br /&gt;Naming.rebind("//localhost/RObjectServer", robj);&lt;br /&gt;} catch (MalformedURLException e) {&lt;br /&gt;} catch (UnknownHostException e) {&lt;br /&gt;} catch (RemoteException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;6. Look Up the Remote object and pass the parameters.&lt;br /&gt;try {&lt;br /&gt;// Look up the remote object&lt;br /&gt;RObject robj = (RObject) Naming.lookup("//localhost/RObjectServer");&lt;br /&gt;// Pass a primitive value as argument&lt;br /&gt;robj.primitiveArg(1998);&lt;br /&gt;// Pass a serializable object as argument&lt;br /&gt;robj.byValueArg(new Integer(9));&lt;br /&gt;// Pass a Remote object as argument&lt;br /&gt;robj.byRefArg(new ArgObjectImpl());&lt;br /&gt;} catch (MalformedURLException e) {&lt;br /&gt;} catch (UnknownHostException e) {&lt;br /&gt;} catch (NotBoundException e) {&lt;br /&gt;} catch (RemoteException e) {&lt;br /&gt;}&lt;br /&gt;Returning Values from a Remote Method&lt;br /&gt;Return values from remote methods must be primitive, serializable, or Remote. This example demonstrates the declaration and use of all three return types. 1. Define the remote interface.&lt;br /&gt;&lt;br /&gt;import java.rmi.*;&lt;br /&gt;public interface RObject extends Remote {&lt;br /&gt;// This return value is primitive.&lt;br /&gt;int primitiveRet() throws RemoteException;&lt;br /&gt;// This return value implements Serializable.&lt;br /&gt;Integer byValueRet() throws RemoteException;&lt;br /&gt;// This return value implements Remote.&lt;br /&gt;ArgObject byRefRet() throws RemoteException;&lt;br /&gt;}&lt;br /&gt;public interface ArgObject extends Remote {&lt;br /&gt;int aMethod() throws RemoteException;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;2. Define the remote object implementation.&lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;public class RObjectImpl extends UnicastRemoteObject&lt;br /&gt;implements RObject {&lt;br /&gt;public RObjectImpl() throws RemoteException {&lt;br /&gt;super();&lt;br /&gt;}&lt;br /&gt;public int primitiveRet() throws RemoteException {&lt;br /&gt;return 3000;&lt;br /&gt;}&lt;br /&gt;public Integer byValueRet() throws RemoteException {&lt;br /&gt;return new Integer(2000);&lt;br /&gt;}&lt;br /&gt;public ArgObject byRefRet() throws RemoteException {&lt;br /&gt;return new ArgObjectImpl();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;3. Compile the remote object implementation.&lt;br /&gt;&gt; javac RObject.java RObjectImpl.java&lt;br /&gt;4. Generate the skeletons and stubs.&lt;br /&gt;&gt; rmic RObjectImpl&lt;br /&gt;&lt;br /&gt;5. Create an instance of RObjectImpl and bind it to the RMI Registry.&lt;br /&gt;try {&lt;br /&gt;RObject robj = new RObjectImpl();&lt;br /&gt;Naming.rebind("//localhost/RObjectServer", robj);&lt;br /&gt;} catch (MalformedURLException e) {&lt;br /&gt;} catch (UnknownHostException e) {&lt;br /&gt;} catch (RemoteException e) {&lt;br /&gt;}&lt;br /&gt;6. Look Up the Remote object, invoke the methods, and receive the return values.&lt;br /&gt;try {&lt;br /&gt;// Look up the remote object&lt;br /&gt;RObject robj = (RObject) Naming.lookup(&lt;br /&gt;"//localhost/RObjectServer");&lt;br /&gt;// Receive the primitive value as return value&lt;br /&gt;int r1 = robj.primitiveRet();&lt;br /&gt;// Receive the serializable object as return value&lt;br /&gt;Integer r2 = robj.byValueRet();&lt;br /&gt;// Receive the Remote Object as return value&lt;br /&gt;ArgObject aobj = robj.byRefRet();&lt;br /&gt;} catch (MalformedURLException e) {&lt;br /&gt;} catch (UnknownHostException e) {&lt;br /&gt;} catch (NotBoundException e) {&lt;br /&gt;} catch (RemoteException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Throwing an Exception from a Remote Method&lt;br /&gt;&lt;br /&gt;1. Define the remote interface.&lt;br /&gt;import java.rmi.*;&lt;br /&gt;public interface RObject extends Remote {&lt;br /&gt;void aMethod() throws RemoteException;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;2. Define the remote object implementation.&lt;br /&gt;import java.rmi.*;&lt;br /&gt;import java.rmi.server.UnicastRemoteObject;&lt;br /&gt;public class RObjectImpl extends&lt;br /&gt;UnicastRemoteObject implements RObject {&lt;br /&gt;public RObjectImpl() throws RemoteException {&lt;br /&gt;super();&lt;br /&gt;}&lt;br /&gt;public void aMethod() throws RemoteException {&lt;br /&gt;// The actual exception must be wrapped in&lt;br /&gt;// a RemoteException&lt;br /&gt;throw new RemoteException(&lt;br /&gt;"message", new FileNotFoundException("message"));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;3. Compile the remote object implementation.&lt;br /&gt;&gt; javac RObject.java RObjectImpl.java&lt;br /&gt;&lt;br /&gt;4. Generate the skeletons and stubs.&lt;br /&gt;&gt; rmic RObjectImpl&lt;br /&gt;5. Create an instance of RObjectImpl and bind it to the RMI Registry.&lt;br /&gt;try {&lt;br /&gt;RObject robj = new RObjectImpl();&lt;br /&gt;Naming.rebind("//localhost/RObjectServer", robj);&lt;br /&gt;} catch (MalformedURLException e) {&lt;br /&gt;} catch (UnknownHostException e) {&lt;br /&gt;} catch (RemoteException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;6. Look up the Remote object, invoke the method, and catch the exception.&lt;br /&gt;try {&lt;br /&gt;// Look up the remote object.&lt;br /&gt;RObject robj = (RObject) Naming.lookup(&lt;br /&gt;"//localhost/RObjectServer");&lt;br /&gt;// Invoke the method.&lt;br /&gt;robj.aMethod();&lt;br /&gt;} catch (MalformedURLException e) {&lt;br /&gt;} catch (UnknownHostException e) {&lt;br /&gt;} catch (NotBoundException e) {&lt;br /&gt;} catch (RemoteException e) {&lt;br /&gt;// Get the actual exception that was thrown.&lt;br /&gt;Throwable realException = e.detail;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Strings (java.lang)&lt;br /&gt;Constructing a String&lt;br /&gt;If you are constructing a string with several appends, it may be more efficient to construct it using a StringBuffer and then convert it to an immutable String object.&lt;br /&gt;StringBuffer buf = new StringBuffer("Initial Text");&lt;br /&gt;// Modify&lt;br /&gt;int index = 1;&lt;br /&gt;buf.insert(index, "abc");&lt;br /&gt;buf.append("def");&lt;br /&gt;// Convert to string&lt;br /&gt;String s = buf.toString();&lt;br /&gt;Getting a Substring from a String&lt;br /&gt;int start = 1;&lt;br /&gt;int end = 4;&lt;br /&gt;String substr = "aString".substring(start, end); // Str&lt;br /&gt;&lt;br /&gt;Searching a String&lt;br /&gt;String string = "aString";&lt;br /&gt;// First occurrence.&lt;br /&gt;int index = string.indexOf('S'); // 1&lt;br /&gt;&lt;br /&gt;// Last occurrence.&lt;br /&gt;index = string.lastIndexOf('i'); // 4&lt;br /&gt;// Not found.&lt;br /&gt;index = string.lastIndexOf('z'); // -1&lt;br /&gt;&lt;br /&gt;Replacing Characters in a String&lt;br /&gt;// Replace all occurrences of 'a' with 'o'&lt;br /&gt;String newString = string.replace('a', 'o');&lt;br /&gt;&lt;br /&gt;Replacing Substrings in a String&lt;br /&gt;static String replace(String str,&lt;br /&gt;String pattern, String replace) {&lt;br /&gt;int s = 0;&lt;br /&gt;int e = 0;&lt;br /&gt;StringBuffer result = new StringBuffer();&lt;br /&gt;while ((e = str.indexOf(pattern, s)) &gt;= 0) {&lt;br /&gt;result.append(str.substring(s, e));&lt;br /&gt;result.append(replace);&lt;br /&gt;s = e+pattern.length();&lt;br /&gt;}&lt;br /&gt;result.append(str.substring(s));&lt;br /&gt;return result.toString();&lt;br /&gt;}&lt;br /&gt;Converting a String to Upper or Lower Case&lt;br /&gt;&lt;br /&gt;// Convert to upper case&lt;br /&gt;String upper = string.toUpperCase();&lt;br /&gt;// Convert to lower case&lt;br /&gt;String lower = string.toLowerCase();&lt;br /&gt;&lt;br /&gt;Converting a String to a Number&lt;br /&gt;int i = Integer.parseInt("123");&lt;br /&gt;long l = Long.parseLong("123");&lt;br /&gt;float f = Float.parseFloat("123.4");&lt;br /&gt;double d = Double.parseDouble("123.4e10");&lt;br /&gt;&lt;br /&gt;Converting Unicode to UTF-8&lt;br /&gt;try {&lt;br /&gt;String string = "\u5639\u563b";&lt;br /&gt;byte[] utf8 = string.getBytes("UTF8");&lt;br /&gt;} catch (UnsupportedEncodingException e) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Converting UTF-8 to Unicode&lt;br /&gt;public static String toUnicode(byte[] utf8buf) {&lt;br /&gt;try {&lt;br /&gt;return new String(utf8buf, "UTF8");&lt;br /&gt;} catch (UnsupportedEncodingException e) {&lt;br /&gt;}&lt;br /&gt;return null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Determining a Character's Unicode Block&lt;br /&gt;char ch = '\u5639';&lt;br /&gt;Character.UnicodeBlock block =&lt;br /&gt;Character.UnicodeBlock.of(ch);&lt;br /&gt;&lt;br /&gt;Breaking a String into Words&lt;br /&gt;String aString = "word1 word2 word3";&lt;br /&gt;StringTokenizer parser =&lt;br /&gt;new StringTokenizer(aString);&lt;br /&gt;while (parser.hasMoreTokens()) {&lt;br /&gt;processWord(parser.nextToken());&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/174827211062086979-8386845831934257567?l=javawebblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javawebblog.blogspot.com/feeds/8386845831934257567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=174827211062086979&amp;postID=8386845831934257567' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/8386845831934257567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/174827211062086979/posts/default/8386845831934257567'/><link rel='alternate' type='text/html' href='http://javawebblog.blogspot.com/2007/06/paper-1.html' title='paper 1'/><author><name>gouse</name><uri>http://www.blogger.com/profile/13059729325413820275</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
