Welcome to my blog, hope you enjoy reading
RSS

Thursday 20 December 2012

Does Java pass by value or pass by reference in java



Does Java is pass by value or pass by reference is one of the tricky Java question mostly asked on fresher level interviews. Before debating whether Java is pass by value or pass by reference lets first clear what is pass by value and what is pass by reference. This question has its origin on C and C++ where you can pass function parameter either value or memory address, where value is stored (pointer). As per Java specificationeverything in Java is pass by value whether its primitive value or objects and it does make sense because Java doesn't support pointers or pointer arithmetic, Similarly multiple inheritance and operator overloading is also not supported in Java. This question becomes confusing when interviewer ask about how object is passed in Java ? Answer to this question is simple whenever a method parameter expect object, reference of that object is passed. Many programmer confuses reference with pointers here which is not correct, reference is a kind of handle which is used to locate object or change object, but it doesn’t allows any pointer arithmetic i.e. you can not increase or decrease memory address and locate a different object using reference in Java.


Pass by Value and Pass by Reference Example in Java

Let’s see two example of calling method and passing parameter this will clear any doubt whether Java is pass by value or pass by reference. consider following example:


public class PassByValueExample {
 
    
public static void main(String args[]) {
       
int number = 3;
       printNext
(number);
       
System.out.println("number Inside main(): "+number);
    
}
 
    
public static void printNext(int number){
        number++
;
        
System.out.println("number Inside printNext(): "+number);
    
}
  
}
Output:
number Inside printNext
()4
number Inside main
()3


Above example clearly shows that primitives are passed as pass by value to method parameters, had Java pass by reference both main method and printNext() would have printed same value. Now look at another example of passing object as method parameter which will confuse you that Java is pass by reference, which Java is not.

public class PassByReferenceConfusion {
 
    
public static void main(String args[]) {
       Car car = 
new Car("BMW");
       
System.out.println("Brand of Car Inside main() before: "+ car.brand);
       printBrand
(car);
       
System.out.println("Brand of Car Inside main()after: "+ car.brand);
    
}
 
    
public static void printBrand(Car car){
        car.
brand = "Maruti";
        
System.out.println("Brand of Car Inside printBrand(): "+car.brand);
    
}
 
    
private static class Car{
        
private String brand;
     
        
public Car(String brand){
            
this.brand = brand;
        
}

    
}
}
Output:
Brand of Car Inside main
() before: BMW
Brand of Car Inside printBrand
(): Maruti
Brand of Car Inside main
()after: Maruti

If you see change made in method parameter is reflected globally i.e. brand of car is changed in all places it means one object is used in both method. Well in reality if you pass object as method parameter in Java  it passes "value of reference" or in simple term object reference or handle to Object in Java. Here reference term is entirely different than reference term used in C and C+ which directly points to memory address of variable and subject to pointer arithmetic. in Java object can only be accessed by its reference as you can not get memory address where object is stored or more precisely there is no method to get value of object by passing memory address.

To conclude everything in Java including primitive and objects are pass by value. In case of object value of reference is passed.


Share

Wednesday 19 December 2012

How to remove (delete) Eclipse workspaces


How to remove (delete) Eclipse workspaces.



Approch 1:
Its possible to remove the workspace in eclipse without much complications. The options are available under Preferences->General->Startup and Shutdown->Workspaces.

Share

Importing multiple projects into eclipse


Importing multiple projects into eclipse

If all of your old projects exist in a single directory or in a single parent directory, you can do File -> Import... -> Existing Projects into workspace. Choose a root directory that is a parent all of the projects you want to import. You will then be able to import all of the projects at once.
Share

Tuesday 18 December 2012

Keyboard Shorcuts


Keyboard Shorcuts 

Keyboard Shorcuts (Microsoft Windows)
1. CTRL+C (Copy)
2. CTRL+X (Cut)
...... 3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. 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)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents opensimultaneou sly)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in My Computer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. 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)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a submenu)
32. LEFT ARROW (Open the next menu to the left, or close a submenu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder onelevel up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROMinto the CD-ROM drive (Prevent the CD-ROM from automatically playing)
Dialog Box - Keyboard Shortcuts
1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)
Microsoft Natural Keyboard Shortcuts
1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restorethe minimized windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch FilterKeys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
17. SHIFT five times (Switch the StickyKeys either on or off)
18. NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
25. NUM LOCK+Minus sign (-) (Collapse the selected folder)
26. LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
27. 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:
1. RIGHT ARROW (Move to the rightor to the beginning of the next line)
2. LEFT ARROW (Move to the left orto the end of the previous line)
3. UP ARROW (Move up one row)
4. DOWN ARROW (Move down one row)
5. PAGE UP (Move up one screen at a time)
6. PAGE DOWN (Move down one screen at a time)
7. HOME (Move to the beginning of the line)
8. END (Move to the end of the line)
9. CTRL+HOME (Move to the first character)
10. CTRL+END (Move to the last character)
11. SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)
Microsoft Management Console (MMC)
Main Window Keyboard Shortcuts
1. CTRL+O (Open a saved console)
2. CTRL+N (Open a new console)
3. CTRL+S (Save the open console)
4. CTRL+M (Add or remove a console item)
5. CTRL+W (Open a new window)
6. F5 key (Update the content of all console windows)
7. ALT+SPACEBAR (Display the MMC window menu)
8. ALT+F4 (Close the console)
9. ALT+A (Display the Action menu)
10. ALT+V (Display the View menu)
11. ALT+F (Display the File menu)
12. ALT+O (Display the Favorites menu)
MMC Console Window Keyboard Shortcuts
1. CTRL+P (Print the current page or active pane)
2. ALT+Minus sign (-) (Display the window menu for the active console window)
3. SHIFT+F10 (Display the Action shortcut menu for the selected item)
4. F1 key (Open the Help topic, if any, for the selected item)
5. F5 key (Update the content of all console windows)
6. CTRL+F10 (Maximize the active console window)
7. CTRL+F5 (Restore the active console window)
8. ALT+ENTER (Display the Properties dialog box, if any, for theselected item)
9. F2 key (Rename the selected item)
10. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)
Remote Desktop Connection Navigation
1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. 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.)
9. CTRL+ALT+Plus sign (+) (Place asnapshot of the entire client window area on the Terminal server clipboardand provide the same functionality aspressing ALT+PRINT SCREEN on a local computer.)
Microsoft Internet Explorer Keyboard Shortcuts
1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the browser with the same Web address)
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog box)
10. CTRL+R (Update the current Web )

Share

Struts Interview Questions

Struts Interview Questions
1.What is MVC?
Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data.
  • Model :The model contains the core of the application's functionality. The model encapsulates the state of the application. Sometimes the only functionality it contains is state. It knows nothing about the view or controller.
  • View:The view provides the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.
  • Controller:The controller reacts to the user input. It creates and sets the model.
Share

GWT Interview Questions


GWT Interview Questions

What is Google Web Toolkit?

Google Web Toolkit (GWT) is an open source Java development framework that lets you escape the matrix of 
technologies that make writing AJAXapplications so difficult and error prone. With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice. When you deploy your application to production, the GWT compiler translates your Java application to browser-compliant JavaScript and HTML.
Share

How do I delete the entire history (Recently Used Items) in the dash?


how do i delete the entire history(Recently Used Items) in ubuntu


An alternative way, with a simple interface to remove all record logs of Recently Used files and applications in Ubuntu 12.04 is to follow these simple steps:
  1. Click on the control icon (cog wheel on top right hand corner of display screen);
  2. Select System settings;
  3. Click on All Settings tab at the top of the dialogue window that opens up;
  4. Select Privacy icon;
  5. Select tab Recent Items;
  6. Under "Forget Activities option" listed, select All in the drop-down box on the right-hand side of the option;
  7. Click on Delete History button;
  8. Click on Yes to the confirmation dialogue;
  9. Close System Settings application window;
Job is done!

Share

Monday 17 December 2012

Black preview in GWT Designer in Eclipse on Ubuntu


Black preview in GWT Designer in Eclipse on Ubuntu 


Update: It seems like the problem was fixed. No need to install GWT Designer anymore, you can just install Google Plugin for Eclipse then install libwebkit 1.0, since it’s not installed by default.
libwebkit 1.0 can be installed by running the following command in the terminal (both 32bit and 64bit):
sudo apt-get install libwebkitgtk-1.0-0

see more clickhere.
Share

Saturday 15 December 2012

How to reorder MySQL table columns in MySQL databases


How to reorder MySQL table columns in MySQL databases

The data structure of any application is the hardest part to change. Nevertheless, new needs arise all the time, and so, adding new table columns to an existing MySQL database is a common task.
But what about reordering the table column order in MySQL after you have already created and added the new columns to an existing table? Doing so is an advisable procedure in order to keep together very related data fields in your MySQL table structure.
Share

Friday 14 December 2012

Secure your website with JavaScript, NO RIGHT CLICK for Images


Secure your website with JavaScript, NO RIGHT CLICK for Images

Have you ever worked really hard on graphics for your site only to find later that someone has stolen them as their own. You can help encrypt and protect your site with the following HTML codes. No right click block is 100% effective, but they will help against novices.

Use the script below so when someone right clicks to save an image off your page, a message will come up letting people know that your information is copyrighted.

This script may not work in all browsers, and is not foolproof. If someone really wants something from your page they can find ways around it, but at least it's a warning to people who want to take your graphics. But it certainly is a great start.

Copy and paste the following code, and make sure it comes right after your <HEAD> tag:
<script language=JavaScript> var message="Function Disabled!"; function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") </script>

If you don't like using javascript, you can always use a span tag to position a transparent gif over the top of the image like the example code below. Don't forget, you will need to create a transparent.gif to implement this method.
<span style="background-image: url(images/my_image.jpg)"><img src="images/transparent.gif" width="200" height="150" border="0" alt="Protected Image."></span>


"NO RIGHT CLICK" for Source

Here is a handy little script which will not only protect your images from right clicking, but your whole page. Remember this only stops some visitors from viewing your source. There are ways around it and if someone really wants to view your source they may find a way. There is another trick below to protect your source code, so keep reading.


<script language=JavaScript> var message="Function Disabled!"; function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") </script>

Disable Copy and Paste for greater website security.
One of the most popular questions I recieve here at Hypergurl is "How do you stop visitors from stealing your webpage information?"
Below is a little trick that will stop your visitors from copying and pasting your webpage information. Anyone with experience may know a way around this trick. However it will make it hard enough to discourage them and get them moving on to easier targets.
Add the following html code to your BODY tag: 
Here is how your BODY tag may look once implimented: 
<body bgcolor="#FFFFFF" ondragstart="return false" onselectstart="return false">

ondragstart="return false" onselectstart="return false"
Share

Thursday 13 December 2012

String Operators in database


String Operators in database

Name Description
ASCII()
Return numeric value of left-most character
BIN()
Return a string containing binary representation of a number
BIT_LENGTH()
Return length of argument in bits
CHAR_LENGTH()
Return number of characters in argument
CHAR()
Return the character for each integer passed
CHARACTER_LENGTH()
A synonym for CHAR_LENGTH()
CONCAT_WS()
Return concatenate with separator
CONCAT()
Return concatenated string
ELT()
Return string at index number
EXPORT_SET()
Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string
FIELD()
Return the index (position) of the first argument in the subsequent arguments
FIND_IN_SET()
Return the index position of the first argument within the second argument
FORMAT()
Return a number formatted to specified number of decimal places
HEX()
Return a hexadecimal representation of a decimal or string value
INSERT()
Insert a substring at the specified position up to the specified number of characters
INSTR()
Return the index of the first occurrence of substring
LCASE()
Synonym for LOWER()
LEFT()
Return the leftmost number of characters as specified
LENGTH()
Return the length of a string in bytes
LIKE
Simple pattern matching
LOAD_FILE()
Load the named file
LOCATE()
Return the position of the first occurrence of substring
LOWER()
Return the argument in lowercase
LPAD()
Return the string argument, left-padded with the specified string
LTRIM()
Remove leading spaces
MAKE_SET()
Return a set of comma-separated strings that have the corresponding bit in bits set
MATCH
Perform full-text search
MID()
Return a substring starting from the specified position
NOT LIKE
Negation of simple pattern matching
NOT REGEXP
Negation of REGEXP
OCT()
Return a string containing octal representation of a number
OCTET_LENGTH()
A synonym for LENGTH()
ORD()
Return character code for leftmost character of the argument
POSITION()
A synonym for LOCATE()
QUOTE()
Escape the argument for use in an SQL statement
REGEXP
Pattern matching using regular expressions
REPEAT()
Repeat a string the specified number of times
REPLACE()
Replace occurrences of a specified string
REVERSE()
Reverse the characters in a string
RIGHT()
Return the specified rightmost number of characters
RLIKE
Synonym for REGEXP
RPAD()
Append string the specified number of times
RTRIM()
Remove trailing spaces
SOUNDEX()
Return a soundex string
SOUNDS LIKE
Compare sounds
SPACE()
Return a string of the specified number of spaces
STRCMP()
Compare two strings
SUBSTR()
Return the substring as specified
SUBSTRING_INDEX()
Return a substring from a string before the specified number of occurrences of the delimiter
SUBSTRING()
Return the substring as specified
TRIM()
Remove leading and trailing spaces
UCASE()
Synonym for UPPER()
UNHEX()
Return a string containing hex representation of a number
UPPER()
Convert to uppercase

Share

Wednesday 12 December 2012

How to JOIN on different tables based on column value


How to JOIN on different tables based on column value

PROBLEM:
ads table









phones table






cars table





i have 3 tables ads,cars and phones.

i want to join tables is based on category in ads table.

and i tried this query but no luck,any helps?

SELECT *
  FROM `ads` 
  JOIN `ads.category` ON `ads.id` = `ads.category.id`
** i cant add comment any of your post,but i want it to be automatic based on category in ads table.
for example :- if in table have phones category,i will automatic join phones table then
SELECT *
  FROM `ads` 
  JOIN `phone` ON `ads.id` = `phone.id`
if in table have cars category,i will automatic join cars table
SELECT *
  FROM `ads` 
  JOIN `cars` ON `ads.id` = `cars.id`


SOLUTION:


to get the cars:
SELECT *
FROM ads JOIN cars ON ads.ID = cars.ID
to get the phone:
SELECT *
FROM ads JOIN phones ON ads.ID = phones.ID
to get both use a UNION:
SELECT ads.ID, ads.Title, ads.Desc, ads.category, 'Car' AS AdType, cars.Year AS Col1, cars.cc AS Col2, cars.transmission AS Col3
FROM ads JOIN cars ON ads.ID = cars.ID
UNION ALL SELECT ads.ID, ads.Title, ads.Desc, ads.category, 'Phone' AS AdType, phone.Model AS Col1, phone.Color AS Col2, '' AS Col3
FROM ads JOIN phones ON ads.ID = phones.ID
note: i would advise you to setup foreign keys in your cars and phones tables, to reference the ads.ID instead of using the ID field (Primary key?) of the child tables

For more about the UNION AND UNION ALL.
Share