Java's Chronicle

Tuesday, December 2, 2014

While
developing web applications, we frequently change JSP contents, but in order to
reflect those changes we often copy the file into .WAR folder deployed on the
server. Though it is small steps as we are used to, but how good it will be if
we have changes reflecting automatically….doesn’t it sounds pretty cool???

3. In Project Explorer, right click the project which has the JSP files and
choose Properties.

4. In the Properties window, select "File synchronization"
on the left.

5. Select the checkbox "[] Enable FileSync builder for project".

6. Click on "Add Folder" button and select the folder which is
the root folder of all JSP files (for eg, you may select
Project/j2ee-apps/XXX/Module.war folder).

7. Click on "Browse..." button against "Default target
folder" and choose the WAR folder inside your deployed EAR folder in the
app server (for eg, in Jboss, it would be
C:\jboss-eap-5.1\jboss-as\server\{server-configuration}\deploy\{Project}.ear\{module}.war).

8. Click OK.

9.FileSync plugin does an initial synchronization. Test it by making small
changes to JSP , and see the changes reflected.

Here
i am trying to sort some group of stirng objects using Arrays.sort() method and
collections.sort() method respectively it sorted and gave me the proper output
....but when i tried to sort group of employee objects i got the exception as :Exception in thread "main" java.lang.ClassCastException: Employee cannot be cast to java.lang.Comparable

Tuesday, June 22, 2010

Ctrl+space. Autocomplete.
This will recommend a list of classes they will fit what you have typed so far. If there is only one match, it will just print it out for you. After it does print it out for you, it will include the import for you. If something is ever missing the import at the top, I will just go to the Class declaration and just hit Ctrl+space.

Ctrl+Shift+O : Import packages:
This is very much required when we have to import packages for classes. (Organizing)

Ctrl+Shift+R. Open resource.
I cannot live without this shortcut. It is such a time saver. Whenever you are trying to find a specific class, just start typing it and it will populate which classes match that criteria. Once you found it, select it and there you go! It also works great if you are new to a framework and need to find certain classes or if you partly recall the class name but not 100% sure.

Ctrl+O. Show inherited members.
This is another one that works great when you are working with classes with a massive lump of methods attached to it. You COULD do this within the Package Explorer, but no one likes touching that mouse! You can even type to filter down your methods. If you have methods with the same name and just different parameters, this also works great. Just type in part of the method name and get a few overview and access to each of the methods.

Ctrl+H. Loads search box.
I cant tell you how often this saves me. This isnt just a ‘find’ box, this does a ‘find in files’ within the File Search tab. Within here, you can specify what you are looking for in the files, what you file types you want to search in, etc. There are other types of search you can use, but I have not run into a case where I need them. Have you?

Ctrl+Shift+C. Comments a block of code.
This is perfect for debugging. It is strange because really when you think about it, you are only talking about having something put a /* at the begging of what you selected and a */ at the end of what you selected. However, I use this a lot more often than you would expect.

Ctrl+D. Delete a line.
Self explanatory. Extremely useful. If I didn’t have that, I’d have to waste time with Shift+End, Delete!.

Ctrl+E. Menu for opened files.
This will bring up a list of opened files that you have. Not only that, it will also allow you to type in your class names to narrow down your choices.

Ctrl+Shift+E : Window for Opened files:
This key is used to view all the files opened in the editor , where it will be easy to identify & open the files .

Ctrl+1:
Is used for renaming variables at a time through out the file. Will be useful when we want to rename the variable name where the variable being used at many places.

F4. Shows class hierarchy.
This is extremely useful when you are new to a with a massive framework and you really want to get a sense of how things are all connect, who extends what, etc.

F3 and Ctrl+Left Mouse Click. Shows declaration.
I enjoy using this when I am working with larger files or anything with long methods (which always irks me). It can get extremely annoying to see where some variables are declared. All you have to do is high light the variable then hit F3. Sometimes I will hold control and hover over variable names if I am having a problem.

F5, F6, F7, F8. In debug mode.
There three shortcuts are probably used more than anything. I wanted to group them all into one section.

F5 – Step Into. When you are debugging an application and you come across a function call, F5 will step into that function and proceed from there.

F6 – Step. This allow you to debug line by line. However, this will not step into any functions.

F7 – Step out. If you are debugging in a function and you want to step out of it to where the function was called, this is what is used.

F8 – Skip to next breakpoint. If there arent any other break points to high, you will be just running the application until your application hits another breakpoint, taking you back into debug mode.

Alt+leftarrow or Alt+rightarrow. Jump back to a line, Jump forward to a line.
According to eclipse, this is “Next word, Previous word’. I am not sure what that means. All I know if I am stepping into functions, debugging through multiple files and breakpoints, this is a life saver. It allows me to retrace my steps, step by step. If I go back with Alt+leftarrow, I can go right back to where I was with Alt+rightarray.

Ctrl+Shift+L. Displays all shortcuts.
Self explanitory. Dig in and find your favorite!This last one is not about using a shortcut. It is about what you have to do to turn it of.

Ctrl+W or Ctrl+F4: close the single file.
This is used to close the current file that is opened in the editor.

Ctrl+Shift+W or Ctrl+Shift+F4 : Close all the files:
When many files we have opened this is very much useful to close all the files opened in the editor in a single shot.

Alt + left key : Navigation
This is used to navigate from one page to another page in the left direction .

Alt+right key : the same as above for right navigation.

Ctrl+Shift+/ : comment
This is used to add the block level comment in a page.

===============================================================Question 3:What will happen when you compile and run the following code?public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } } a) Error Variable i may not have been initialized c) 1b) null d) 0

a) Error at compile time b) Error at Runtime c) prints Hello d) No Error and no output

===============================================================Question 5:Which of the following statements are true?a) A byte can represent between -128 to 127 b) A byte can represent between -256 to 256c) A byte can represent between -127 to 128 d) A char can represent between -2x2 pow 16 2 x2 pow 16 - 1

===============================================================Question 6:Which of the following statements are true?a) Constructors cannot have a visibility modifier b) Constructors can only have a primitive return typec) Constructors can be marked public and protected, but not private d) Constructors are not inherited

===============================================================Question 7:What will happen when you attempt to compile and run the following class? class Base{ Base(int i){ System.out.println("Base"); } } class Severn extends Base{ public static void main(String argv[]){ Severn s = new Severn(); } void Severn(){ System.out.println("Severn"); } } a) Compilation and output of the string "Severn" at runtime b) Compilation and no output at runtimec) Compile time errord) Compilation and output of the string "Base"

public static boolean place(boolean location){ if(location==true){ System.out.println("Borcetshire"); } System.out.println("Powick"); return true; } } What will happen when you attempt to compile and run it?a) Compile time error b) Output of Borcetshire and Powick followed by "Hello Crowle"c) Output of "Hello Crowle" d) No output===============================================================Question 11:What will happen when you attempt to compile and run the following code? public class Sandys{ private int court; public static void main(String argv[]){ Sandys s = new Sandys(99); System.out.println(s.court); } Sandys(int ballcount){ court=ballcount; } } a) Compile time error, the variable court is defined as privateb) Compile time error, s is not initialized when the System.out method is called c) Compilation and execution with no outputd) Compilation and run with an output of 99===============================================================Question 12:Given the following code class Base{ static int oak=99; } public class Doverdale extends Base{ public static void main(String argv[]){ Doverdale d = new Doverdale(); d.amethod(); } public void amethod(){ //Here } } Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak? a) super.oak=1; b) Base.oak=22;c) oak=33; d) oak=50.1;===============================================================Question 13:Which of the following statements are true?a) A method cannot be overloaded to be less public in a child classb) To be overridden a method only needs the same name and parameter typesc) To be overridden a method must have the same name, parameter and return typesd) An overridden method must have the same name, parameter names and parameter types===============================================================Question 14:You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?

a)myarray.length();b)myarray.length;c)myarray.sized)myarray.size();===============================================================Question 15:What will happen when you attempt to compile and run this programpublic class Outer{public String name = "Outer";public static void main(String argv[]){ Inner i = new Inner(); i.showName(); }//End of main private class Inner{ String name =new String("Inner"); void showName(){ System.out.println(name); } }//End of Inner class}a) Compile and run with output of "Outer"b) Compile and run with output of "Inner"c) Compile time error because Inner is declared as privated) Compile time error because of the line creating the instance of Inner===============================================================Question 16:Given the following class definition, which of the following methods could be legally placed after the comment //Here