Showing posts with label JAVA. Show all posts

Most Useful Eclipse shortcuts

10:18 PM
This blog is about useful Eclipse shortcuts ,this list is by no means complete and I will suggest you guys to share eclipse shortcuts listed other than here to make this more useful.Knowing Eclipse shortcuts not only improve your productivity but also makes your more efficient, you will have more time for things you like to do.I was big fan of Netbeans IDE before coming across Eclipse because I was from J2ME background and Netbeans provide sofisticated IDE environment to enable you to build, debug and run your application in various emulator including some advanced processing options e.g. PreProcessing , setting up Exception breakpoint etc.
But when I join a big bank I came acorss Eclipse IDE , since everybody in my team is using and etbeans IDE was not available in company ( don't know why that was not allowed netbeans even though it was free) I have decided to go Eclipse way , later I found that Eclipse was most suited for those application give some of cool feature of eclipse e.g. Remote Debugging, Conditionnal Breakpoint , Exception breakpoint and Ctrl+T and Ctrl+R kind of shortcuts.
Here I am sharing list of Eclipse shortcut which I found most useful and using in my day to day life while writing code, reading code or debugging .
Eclipse Shortcut
1) Ctrl + T for finding class even from jar
2) Ctrl + R for finding any resource (file) including config xml files
3) Ctrl + 1 for quick fix
4) Ctrl + Shift + o for organize imports
5) Ctrl + / for commenting , uncommenting lines and blocks
6) Ctrl + Shift + / for commenting ,uncommenting lines with block comment
7) Ctrl + o for quick outline going quickly to method
8) Selecting class and pressing F4 to see its Type hierarchy
9) Alt + right and Alt + left for going back and forth while editing.
10) Ctrl + F4 or Ctrl + w for closing current file
11) Ctrl+Shirt+W for closing all files.
12) Alt + Shift + W for show in package explorer
13) Ctrl + Shift + Up and down for navigating from member to member (variables and methods) 14) Ctrl + l go to line
15) Ctrl + k and Ctrl + Shift +K for find next/previous
16) select text and press Ctrl + Shift + F for formatting.
17) Ctrl + F for find , find/replace
18) Ctrl + D to delete a line
19) Ctrl + Q for going to last edited place
20) Ctrl + T for toggling between super type and subtype
21) Go to other open editors: Ctrl + E.
22) Move to one problem (i.e.: error, warning) to the next (or previous) in a file: Ctrl + . for next, and Ctrl + , for previous problem
23) Hop back and forth through the files you have visited: Alt + ← and Alt + →, respectively.
24) Go to a type declaration: F3
25) CTRL+Shift+G, which searches the workspace for references to the selected method or variable
26) Ctrl+Shift+L to view listing
27) Alt + Shift + j to add javadoc at any place in java source file.
28) CTRL+SHIFT+P to find closing brace. place the cursor at opening brace and use this.
29) Alt+Shift+X, Q to run Ant build file using keyboard shortcuts.
30) Ctrl + Shift +F for Autoformating.
Please post if you guys have some more useful Eclipse shortcuts as comments , I will include them in this list.
Read On 1 comments

10 Tricky Java Interview Questions

6:26 AM
Here are some Java interview questions which are un-common

1) What is the performance effect of a large number of import statements which are not used?
Ans: They are ignored if the corresponding class is not used.


2) Give a scenario where hotspot will optimize your code?
Ans: If we have defined a variable as static and then initialized this variable in a static block then the Hotspot will merge the variable and the initialization in a single statement and hence reduce the code.

3) What will happen if an exception is thrown from the finally block?
Ans: The program will exit if the exception is not catched in the finally block.


4) How does decorator design pattern works in I/O classes?
Ans: The various classes like BufferedReader , BufferedWriter workk on the underlying stream classes. Thus Buffered* class will provide a Buffer for Reader/Writer classes.


5) If I give you an assignment to design Shopping cart web application, how will you define the architecture of this application. You are free to choose any framework, tool or server?
Ans: Usually I will choose a MVC framework which will make me use other design patterns like Front Controller, Business Delegate, Service Locater, DAO, DTO, Loose Coupling etc. Struts 2 is very easy to configure and comes with other plugins like Tiles, Velocity and Validator etc. The architecture of Struts becomes the architecture of my application with various actions and corresponding JSP pages in place.

6) What is a deadlock in Java? How will you detect and get rid of deadlocks?
Ans: Deadlock exists when two threads try to get hold of a object which is already held by another object.


7) Why is it better to use hibernate than JDBC for database interaction in various Java applications?
Ans: Hibernate provides an OO view of the database by mapping the various classes to the database tables. This helps in thinking in terms of the OO language then in RDBMS terms and hence increases productivity.

8) How can one call one constructor from another constructor in a class?
Ans: Use the this() method to refer to constructors.

9) What is the purpose of intern() method in the String class?
Ans: It helps in moving the normal string objects to move to the String literal pool


10) How will you make your web application to use the https protocol?
Ans: This has more to do with the particular server being used than the application itself. Here is how it can be done on tomcat:
Read On 0 comments

JSP Comment vs HTML Comment - what's the difference?

7:46 AM
JSP Comment

<%-- comment text --%> - this is the format of the JSP comments specified in the JSP Specifications. A JSP Comment is removed by the JSP Engine at the translation time itself and the compilation unit doesn't contain them. The comment processing in JSP is very similar to what we have in any other language. Comments don't need to ne compiled as we all know that they are not executed and they simply serve the purpose of making the source code more readable, and maintainable.

HTML Comment

- this is the syntax of an HTML comment as specified by the HTML Specifications. A JSP page considers this as a normal HTML tag and hence it doesn't remove them. All HTML comments are maintained in the response and one can easily see them jusy by viewing the page source of the rendered HTML page in the browser.

Difference between JSP Comment & HTML Comment

JSP Comments are removed by the JSP Engine during the translation phase (JSP Comments are not even part of the compilation unit) whereas the HTML Comments are treated like any other HTML tage and hence they are maintained throughout. This is reason why we can easily see the HTML comments in the browse by viewing the source of the page.

What about // or /*...*/? Are they JSP Comments?

No... they are only Java comments. Since, we are allowed to embed Java code into a JSP page, hence we can have them in a valid JSP page. These comments are treated the same way they are treated in a normal Java program. They all are removed before compilation and like JSP Comments they are also not part of the compilation unit.
Read On 1 comments

Followers