Friday, June 30, 2006
Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
| Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first. |
Wednesday, June 28, 2006
Can we use the constructor, instead of init(), to initialize servlet?
| Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext. |
Tuesday, June 27, 2006
EJB Interview Questions Part-1
| What is the need of Remote and Home interface. Why cant it be in one? The main reason is because there is a clear division of roles and responsabilities between the two interfaces. The home interface is your way to communicate with the container, that is who is responsable of creating, locating even removing one or more beans. The remote interface is your link to the bean, that will allow you to remotely access to all its methods and members. As you can see there are two distinct elements (the container and the beans) and you need two different interfaces for accessing to both of them. Can I develop an Entity Bean without implementing the create() method in the home interface? As per the specifications, there can be 'ZERO' or 'MORE' create() methods defined in an Entity Bean. In cases where create() method is not provided, the only way to access the bean is by knowing its primary key, and by acquiring a handle to it by using its corresponding finder method. In those cases, you can create an instance of a bean based on the data present in the table. All one needs to know is the primary key of that table. i.e. a set a columns that uniquely identify a single row in that table. Once this is known, one can use the 'getPrimaryKey()' to get a remote reference to that bean, which can further be used to invoke business methods. What is the difference between Context, InitialContext and Session Context? How they are used? javax.naming.Context is an interface that provides methods for binding a name to an object. It's much like the RMI Naming.bind() method. javax.naming.InitialContext is a Context and provides implementation for methods available in the Context interface. Where as SessionContext is an EJBContext object that is provided by the EJB container to a SessionBean in order for the SessionBean to access the information and/or services or the container. There is EntityContext too which is also and EJBContext object that'll be provided to an EntityBean for the purpose of the EntityBean accessing the container details. In general, the EJBContext (SessionContext and EntityContext), AppletContext and ServletContext help the corresponding Java objects in knowing about its 'context' [environment in which they run], and to access particular information and/or service. Whereas, the javax.naming.Context is for the purpose of 'NAMING' [by the way of referring to] an object. |
Friday, June 23, 2006
java e-Books
How many Design Patterns are there in Java ?
| In j2ee they have 15 Design Pattern: Presentation Tier: 1.Intercepting Filter 2. Front Controller 3. View Helper 4. Composite View 5. Service to Worker 6. Dispatcher View Business Tier: 7. Business Delegate 8. Transfer Object 9. Session Facade 10. Service Locator 11. Transfer Object 12. Value List Handler 13. Composite Entity Integration Tier: 14.Service Activator 15 Data Access Object |
Wednesday, June 21, 2006
Things That Java Does Not Have (Help)
Hi Friends, The inventors of Java were C/C++ programmers, and they made conscious decisions to leave out most of the C/C++ features that get programmers into trouble. In one way you can say these are drowback of java :)
|
Tuesday, June 20, 2006
What is the difference between the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1?
| 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. 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. http://master-in-java.blogspot.com/ |
Monday, June 19, 2006
How can you minimize the need of garbage collection and make the memory use more effective?
| Ans:Use object pooling and weak object references. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList? Ans: ArrayList |
What is callBack method?
| A callback method is a method intended to be passed as a parameter. The callee can then call the passed method asynchronously and with whatever parameters it deems appropriate. Callbacks are often used in event handling code. |
Friday, June 16, 2006
why Java classes direct program messages to the system console, but error messages to the file??
| Hi Friends, Today as usual I came to office and started my work. As I am in development have to write a code and then run it on the server.But today when I started my server I started Wondering why Java classes direct program messages to the system console, but error messages to the file (log files)? I tried finding out solution for the same and after struggle of an hour I found the solution for the same. So I thought I will share this with you all and If I am wrong please Correct me . Here is the Solution: The class System has a variable out that represents the standard output, and the variable err that represent the standard error device. By default, they both point at the system console. This is how the standard output could be re-directed: Stream st = new Stream (new FileOutputStream("output.txt")); System.setOut(st); And error redirect to the file. System.setErr(st); |
Java Programmer
| Java Programmer - (www.shopping.com) - Shop for Java Programmer on shopping.com. Java Programmer - (www.bizdir.org) - Search the Open Directory for Java Programmer Java Programmer - (forum.java.sun.com) - Java Forums - Developer Forums Java Programmer - (www.danchisholm.net) - Java Programmer Certification Mock Exams Java Programmer - (www.jchq.net) - Java Programmer Certification, SCJP FAQ, Tutorial, Mock Exam, Demo ... |
Thursday, June 15, 2006
Basic Interview Questions On Java
| Java technical interview guide I have written part two with some possible answers. Also, renamed the post. I did a technical evaluation for a candidate my employer was looking at awhile ago, so I had an opportunity to try and figure out a good set of technical questions for a prospective intermediate level Java web developer. I’ll just present a whole bunch of questions I came up with - no answers though. I might start up an answers post at a later date, but I don’t want to make this too easy for those trying to fool interviewers. =) Obviously, if you ask every question I have listed here your interview could take hours, so pick and choose what you like. I’d be interested in feedback for ideas on important topics I’ve overlooked or questions that are unfair or unnecessary. I’ve tried to avoid things that can be easily answered with a quick google search, such as basic syntax and API method questions. General Intro Questions Just laying the ground work to help lead the way for areas to focus on… • Give me a high level description of your experience with the Java platform. What APIs do you have experience with? Servlets? J2EE? Swing? • What development methodologies have you used? Which one have you liked the most? The least? • What open source frameworks do you have experience with? • What other languages have you used? Object Oriented Principles • Define object oriented programming (quite a loaded question…). What are the key OO principles? • Describe polymorphism. • Describe inheritance (”is-a”) and composition (”has-a”). Can you give an example of a use case for each? • What is coupling? Why do we want loose coupling in our systems? Java Basics Some very fundamental questions I think any “non-beginner” level dev should know. If there are a lot of problems with these it may not be worth continuing. • What is the difference between abstract classes and interfaces? • Explain the access modifiers in Java. • Talk about method overriding and method overloading and their differences. • Why does Java have exceptions? What is the difference between checked and unchecked exceptions? • What are constructors? Are they inherited? • What is the static modifier used for in regards to classes and methods? • What are the equals() and hashcode() ? Describe their contracts. • When do you use String and when do you use StringBuffer/StringBuilder Java Intermediate/Advanced • Explain the following statement: Java is always pass-by-value. • How do you create an immutable type? What are the advantages of immutability? • What is a static inner class? Can you provide an example from the Java API? • What are the implications of implementing serializable in an object? • Why would you declare a private constructor? • When do you want to use unchecked exceptions and when do you want to use checked? • Can you explain how Strings are “interned” in Java? • What are enumerated types? Why would you use them? Java Collections • What are the core interfaces of the Collection framework? • How do Vector and HashTable relate to Collections? • Desribe typical use cases or examples of common uses for Map, Set, and Lists. • What method(s) should override for objects you plan to add to sets or maps? • How do you get an immutable collection? Threading If a developer works only in the heavily abstracted world of Spring/Hibernate/whatever, they may not have had to touch an actual Runnable since college. Still, its good to know about threading at least on a basic level. • What does the synchronized key word do? Where is it valid to use it (ie inside a method call, static block, etc)? • Explain the two ways to instantiate threads in Java. • What is “double-checked locking“? What design pattern is it typically associated with? What is wrong with it? • What is a daemon thread? How do you create one? • What method do you use to start a thread? Servlets and JSPs • What are the steps to create a basic servlet? • Describe the lifecycle of a basic servlet - for instance, when are they created? What method is called from a typical HTTP request? What about requests and threads? • What does it mean to say that HTTP is stateless? How do servlets provide a possible solution to maintain state for web applications? • Are JSP’s thread safe? • What are Listeners? What is a typical use for a StartupListener? • What are filters and why would you use them? • Describe the four different scopes available with servlets? Design Patterns • What are the three types of design patterns? • Can you talk about the history of design patterns? • Why use design patterns? • What is the role of composition (aggregation) in design patterns? • What design patterns do you use often and have the most experience with? Can you talk about a typical use case? • Can you provide a description of any of the following patterns? Strategy, State, or Template method? • What is Model View Controller, and why would you want to use it? What are some of the disadvantages of it? • What is inversion of control, and what does it give you? Open Ended Questions These questions are more to just stir discussion and debate and to get a feel for the candidate, rather then to get the “right” answer. • How would you build a software version of Monopoly? • Can you compare (insert dynamic language of choice here - Ruby/Python/Lisp/etc) to Java? When would you prefer one over the other? • What do you think is the most common cause of project failure in the software development business? • What do you think of the rise of open source over the last ten years? Where do you see open source in the future? • What does agile development mean to you? • What is your ideal development environment like? Both in terms of hardware and software, and location and surroundings? • What was the last technical book you read? Give me the Cliff Notes version of it. • What are some of your favorite resources beyond Google? This could include websites, magazines, technical authors, experts, favorite blogs, etc. • Do you have experience with Test Driven Development? If so, what do you think of it? • What will be the next language or development topic you want to learn about? |
What is the purpose all xml files in struts?
| 1. tiles-def.xml tiles-def.xml is used as a configuration file for an appliction during tiles developmentYou can define the layout / header / footer / body content for your View. 2. validation.xml The validation.xml file is used to declare sets of validations that should be applied to Form Beans.Each Form Bean you want to validate has its own definition in this fileInside that definition, you specify the validations you want to apply to the Form Bean's fields. 3.In struts-config.xml we define Date Sources / Form Beans / Global Exceptions / Global Forwards / Action Mappings / Message Resources / Plug-ins 4. Resourcebundle.properties Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails. 5.ApplicationResources.properties errors.registrationForm.name={0} Is an invalid name.In the registrationForm.jsp |
Wednesday, June 14, 2006
One of the strong Frame-work on which I ever Work..
| Hi Friends, It’s been a Year I am working on health care project, we have our own framework which is very strong. the technologies which are getting used for this frame work are very good. So I thought I will share this with u all. The technologies which we are using are : • JSF • Hibernate • Oracle • Canoo- as testing tool Frame -work follows MVC Pattern. We are using JSF as view. And Hibernate supports to fetch the Queries from DB.While working on this project I found JSF is very good technology which can be use as view instated of using simple Jsps.Jsf provides good set of components which we can use to develop our application. But with this I also found that the IDs which we are using for naming the component are very much important otherwise the JSF page won't come. In one way u can say that IDs are very much important in the JSF.In next post I will tell u something about hibernate. |
Monday, June 12, 2006
100 keyboard shortcuts
| CTRL+C (Copy) CTRL+X (Cut) CTRL+V (Paste) CTRL+Z (Undo) DELETE (Delete) SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin) CTRL while dragging an item (Copy the selected item) CTRL+SHIFT while dragging an item (Create a shortcut to the selected item) F2 key (Rename the selected item) CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word) CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word) CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph) CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph) CTRL+SHIFT with any of the arrow keys (Highlight a block of text) SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document) CTRL+A (Select all) F3 key (Search for a file or a folder) ALT+ENTER (View the properties for the selected item) ALT+F4 (Close the active item, or quit the active program) ALT+ENTER (Display the properties of the selected object) ALT+SPACEBAR (Open the shortcut menu for the active window) CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously) ALT+TAB (Switch between the open items) ALT+ESC (Cycle through items in the order that they had been opened) F6 key (Cycle through the screen elements in a window or on the desktop) F4 key (Display the Address bar list in My Computer or Windows Explorer) SHIFT+F10 (Display the shortcut menu for the selected item) ALT+SPACEBAR (Display the System menu for the active window) CTRL+ESC (Display the Start menu) ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command) F10 key (Activate the menu bar in the active program) RIGHT ARROW (Open the next menu to the right, or open a submenu) LEFT ARROW (Open the next menu to the left, or close a submenu) F5 key (Update the active window) BACKSPACE (View the folder one level up in My Computer or Windows Explorer) ESC (Cancel the current task) SHIFT when you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing) Dialog Box Keyboard Shortcuts CTRL+TAB (Move forward through the tabs) CTRL+SHIFT+TAB (Move backward through the tabs) TAB (Move forward through the options) SHIFT+TAB (Move backward through the options) ALT+Underlined letter (Perform the corresponding command or select the corresponding option) ENTER (Perform the command for the active option or button) SPACEBAR (Select or clear the check box if the active option is a check box) Arrow keys (Select a button if the active option is a group of option buttons) F1 key (Display Help) F4 key (Display the items in the active list) BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box) m*cro$oft Natural Keyboard Shortcuts Windows Logo (Display or hide the Start menu) Windows Logo+BREAK (Display the System Properties dialog box) Windows Logo+D (Display the desktop) Windows Logo+M (Minimize all of the windows) Windows Logo+SHIFT+M (Restore the minimized windows) Windows Logo+E (Open My Computer) Windows Logo+F (Search for a file or a folder) CTRL+Windows Logo+F (Search for computers) Windows Logo+F1 (Display Windows Help) Windows Logo+ L (Lock the keyboard) Windows Logo+R (Open the Run dialog box) Windows Logo+U (Open Utility Manager) Accessibility Keyboard Shortcuts Right SHIFT for eight seconds (Switch FilterKeys either on or off) Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off) Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off) SHIFT five times (Switch the StickyKeys either on or off) NUM LOCK for five seconds (Switch the ToggleKeys either on or off) Windows Logo +U (Open Utility Manager) Windows Explorer Keyboard Shortcuts END (Display the bottom of the active window) HOME (Display the top of the active window) NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder) NUM LOCK+Plus sign (+) (Display the contents of the selected folder) NUM LOCK+Minus sign (-) (Collapse the selected folder) LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder) RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder) Shortcut Keys for Character Map After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts: RIGHT ARROW (Move to the right or to the beginning of the next line) LEFT ARROW (Move to the left or to the end of the previous line) UP ARROW (Move up one row) DOWN ARROW (Move down one row) PAGE UP (Move up one screen at a time) PAGE DOWN (Move down one screen at a time) HOME (Move to the beginning of the line) END (Move to the end of the line) CTRL+HOME (Move to the first character) CTRL+END (Move to the last character) SPACEBAR (Switch between Enlarged and Normal mode when a character is selected) m*cro$oft Management Console (MMC) Main Window Keyboard Shortcuts CTRL+O (Open a saved console) CTRL+N (Open a new console) CTRL+S (Save the open console) CTRL+M (Add or remove a console item) CTRL+W (Open a new window) F5 key (Update the content of all console windows) ALT+SPACEBAR (Display the MMC window menu) ALT+F4 (Close the console) ALT+A (Display the Action menu) ALT+V (Display the View menu) ALT+F (Display the File menu) ALT+O (Display the Favorites menu) MMC Console Window Keyboard Shortcuts CTRL+P (Print the current page or active pane) ALT+Minus sign (-) (Display the window menu for the active console window) SHIFT+F10 (Display the Action shortcut menu for the selected item) F1 key (Open the Help topic, if any, for the selected item) F5 key (Update the content of all console windows) CTRL+F10 (Maximize the active console window) CTRL+F5 (Restore the active console window) ALT+ENTER (Display the Properties dialog box, if any, for the selected item) F2 key (Rename the selected item) CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console) Remote Desktop Connection Navigation CTRL+ALT+END (Open the m*cro$oft Windows NT Security dialog box) ALT+PAGE UP (Switch between programs from left to right) ALT+PAGE DOWN (Switch between programs from right to left) ALT+INSERT (Cycle through the programs in most recently used order) ALT+HOME (Display the Start menu) CTRL+ALT+BREAK (Switch the client computer between a window and a full screen) ALT+DELETE (Display the Windows menu) CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.) CTRL+ALT+Plus sign (+) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.) m*cro$oft Internet Explorer Navigation CTRL+B (Open the Organize Favorites dialog box) CTRL+E (Open the Search bar) CTRL+F (Start the Find utility) CTRL+H (Open the History bar) CTRL+I (Open the Favorites bar) CTRL+L (Open the Open dialog box) CTRL+N (Start another instance of the browser with the same Web address) CTRL+O (Open the Open dialog box, the same as CTRL+L) CTRL+P (Open the Print dialog box) CTRL+R (Update the current Web page) CTRL+W (Close the current window) |
Friday, June 02, 2006
What makes a plugin secure?
| Here are some characteristics of a secure plugin: 1. It is digitally signed by the publisher by a third party issued certificate. This way the user at least knows where the plugin in coming from. 2. Inform the user of any actions which can lead to any changes in the system before hand and allow user to reject the proposed actions. 3. Give user the option to save current system settings such that the user can go back to it after the plugin has finished execution if the user so desires. Items 2 and 3 above are sometimes the responsiblity of the application installing and using the plugin and not the plugin itself. From the end user perspective they are the same. So the the word plugin here can mean either just the plugin or the plugin together with web application driving it. Both java applets and activex components are plugins. Both are written to the disk and saved for future use. ActiveX components can be used by applications other than the web browser while for most practical purposes, java applets can only be used from a web browser (there are stanalone java applet hosting programs out there but they are mostly used by developers and not by end users). The ActiveX component installation requires modification to system registery and hence the end user must have administrative privilege in order to install it while Java applets don't need any adminitrative privilege for installation. One can argue that this makes a signed Java Applet a bigger security threat than an ActiveX component since even a user with minimum previlege can download and run it without the knowledge of the system adminstrator. The only way to avoid this situation is to set the browser to not allow Java Applets all together. A conspiracy of the Microsoft haters? Lets face it whenever it comes to deploying any technology produced by Microsoft, there are always two camps: one which loves it for its simplicity and ease of use and the other which hates it just because it came from the "evil empire". The case of ActiveX vs. Java Applet is even more polarized since it also involves a technology produced by Sun Microsystems, by far the most visible Microsoft adversary. I hope after reading this blog, you examine the security issues related to ActiveX and Java applets in a technology neutral manner as both can be written in a secure or malicious way. |