Pages Navigation Menu

Coding is much easier than you think

Solution for “Could not create the Java Virtual Machine” issue

Posted by on Nov 26, 2013 in Eclipse, Java | 2 comments

 
If you get the below error message while executing java program
 

Error:Could not create the Java Virtual Machine.
Error:A fatal exception has occurres.Program will exit.

 

 
To resolve this issue, following steps are needed to be followed (on Windows XP, Windows 7, Windows 8):

  • Right Click on My Computer Icon and click on Properties
  • Click on Advanced Systems Settings
  • Then Environment Variables
  • Under System Variables, click New
  • In which give Variable Name as: _JAVA_OPTIONS
  • Variable Value: -Xmx1024m
  • Click OK

That’s it, now your Java program should execute properly.

 
Note:
Heap size allocated by the JVM by default can be Increased/Modified by using Java -Xmx/s command line options.

Where 
-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size

 

Click here to know about getting JVM heap size, used memory, total memory using Java Runtime programatically.
 

Read More

How to increase JVM heap size in Eclipse

Posted by on Nov 24, 2013 in Eclipse, Java, Jboss, Tomcat | 1 comment

 
To avoid getting java.lang.OutOfMemoryErrors, while running web application, we should increase heap size allocated by the JVM by using command line options.
 

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

 

To do this, follow these steps:

1. Open the Server Configuration in Eclipse by double-clicking on the Server instance.
 
Server
 

2. Click on “Open launch configuration” link
 
Increase JVM max heap size eclipse
 
3. Click on the Arguments tab and add the following command at the end of VM arguments: -Xms128m –Xmx1024m.
 
Increase JVM max heap size eclipse
 

These values may vary, depending on requirement/available memory

 
If you are not using any server, you can type the following on the command line before you run your program:

java -Xms64m -Xmx1024m MyProgram

 

Note:

  • Do not set -Xmx to too small value
  • Set -Xms to a small value

Setting -Xmx to small value mostly leads to OutOfMemoryErrors, because this is the maximum amount of memory you are allocating for Java and it cannot utilize memory beyond the set value.

Also If you set -Xms to higher value you might run out of memory. So try to keep it to a small value like -Xms16m.
 

Read More

Eclipse Shortcuts for fast coding

Posted by on Jun 10, 2013 in Eclipse | 1 comment

 
eclipse shortcut

List of some Shortcuts for fast coding. Traverse below and improve your coding speed by utilizing Eclipse Shortcuts.

dwd2
Download It – eclipse.pdf

 

File navigation  Short cuts
 

Short cuts  Description
Alt + Shift + n Use this shortcut key to open an new menu.
Ctrl + n   Use this  shortcut key to create a new file
Ctrl+H If you want to search in your program and work space use this short cut .
CTRL + SHIFT + R Open a resource. You need not know the path and just part of the file name is enough.
Ctrl +E Open a file (editor) from within the list of all open files.
CTRL + PAGE UP or PAGE DOWN Go to previous or next edit positions from editor history list.
ALT + <- or ALT + -> If you want to close the all file in editor use this shortcut key.
Ctrl +W If you want to close the all file in editor use this shortcut key.
Ctrl +Shift+W If you want to close the all file in editor use this shortcut key.
F2,Alt +Shift+R It is use for re-name  file .
Ctrl +Shift +G Find the reference variable in workspace.

 

Java Editing Short cuts
 

Short cuts Description
Ctrl+Shift+F This short cut use to formatting  the code .
Ctrl+Space Type assist
Ctrl+O Displays every one of the methods and variables in addition to methods available in the current class that’s selected.
Ctrl+Shift+O                                                            This Shortcut use for Organized  import .
Ctrl+Shift+U Find the reference of a file .
Ctrl+/,Ctrl+7 Single Line comment .
Ctrl+Shift+/ Add block Comment .
Ctrl+Shift+\ Remove the block comment.
F3 Go to the declaration of the variable
F4 Show the type hierarchy of an class.
Ctrl+T Show the inheritance tree of current token .
Shift+f2 Show the Java Doc for current  token.
Alt Shift Z Add the try and catch block

 
Editing Short cuts
 

Short cuts Description
F12 Focus on current editor
Ctrl +L Find the Line number.
Ctrl+D                                      This short cut use for delete the single row.
Ctrl +M This short cut use for maximize and minimize the editor.

 
 
Debug and  Run Eclipse short cuts
 

Short cuts                                                     Description
F11 Start the Debug .
Ctrl+F11 Run the last program or project.
Ctrl .Or , To Navigate  the next and previous error .
F5 Step Into.
F6 Step Over.
F8 Resume .
Ctrl+Q Add Inspect
Ctrl +1 Quick fix code.

 
Some Extra Short cuts
 

Short cuts                                                     Description
Alt +Shift +B Add the toggle breakpoint .
Alt +Shift+c Change the method signature .
Alt +Shift+S,R Generate the setter and getter method .
Alt +Shift+X,J Run As java Application .
Alt +Shift+X,R Run As web application .
Alt +Enter Show The Property.
Alt +Shift+X,A Run As Applet .

 
String to StringBuffer /StringBuilder
 
In order to change the concatenation from String to StringBuffer /StringBuilder, move the cursor to the String variable, and press Ctrl +1, and select ‘Use StringBuffer//StringBuilder for string concatenation’
For eg, String s = “a”+”b”+”c”+”d”;
will change to StringBuffer sB = new StringBuffer();
sB.append(“a”);
sB.append(“b”);
sB.append(“c”);
sB.append(“d”);
String s = sB.toString();
 

Read More

Debugging java application in Eclipse

Posted by on Apr 19, 2013 in Eclipse, Java | 0 comments

 
Debugging In Java
 
In this post let us learn about come of commonly used java debugging tips in eclipse.
 
1) Use conditional breakpoint
 
Eclipse allows you to setup conditional break point for debugging, which is a breakpoint with condition and your thread will only stop at specified line if condition matches instead of just stopping on that line like in case of line breakpoint. To setup a conditional breakpoint just double click on any line where you want to setup a breakpoint and then right click –> properties and then insert the condition. Now program will only stop when that particular condition is true.

 

1

 

2

 
2) Use Exception breakpoint
 
You can setup Exception breakpoint based on java exception like ArrayIndexOutOfBoundException or NullPointerException. You can setup Exception breakpoint from breakpoint window and your program will stop when exception occurs.

 

ecplise debug mode

 

3 ) Inspect and Watch
 
These are two menu options which is used to see the value of expression during debugging java program. To do, just select the statement, right click and inspect and it will show you the value of that statement at debugging time. You can also put watch on that condition, now its value will appear on watch window.

 
4) Step over, Step Into
 
These are simply great debugging options available in any Java IDE, extremely useful if you are debugging multi-threaded application and want to navigate step by step.
 
5) Suspending and resuming thread
 
You can suspend and resume any thread while debugging java program from debug window. Just right click on any thread and select either suspends or resume.
 

Read More

Android Development Environment Setup in Eclipse.

Posted by on Jan 10, 2013 in Android | 0 comments

In this Tutorial, you will learn How to setup Android Development Environment in Eclipse

Here you go!!!!

Read More