Thursday, December 26, 2013

JStack - Generating stack dump


This would be useful to analyze a root cause, when an application has suddenly stopped working or not responding . There could be a some kind of deadlock or waiting processes or something else. 
JStack would help in getting the stack dump to a currently running java process.

JStack comes along with JDK kit, need not to install separately.

Go to command prompt, type below command with java process id.

>jstack <pid>

To identify the java process id, you can 'jps' command.

>jps  => this will list out the all java process id's.
Output:
5730 main  => this is my java process id.
10800 jps
8732

To get more details about which process ID belongs to which process use below command
> jps -ml

To get the additional information about the locks.
>jps  -l  <pid>

Jstack can also be used to get the thread dump for remotely running processes.
>jps  <remote host name/ip address>

To write stack dump to a file:
>jstack -l 7840 >  D:\Test\kklog.txt

">" is important to write into a file.


Some useful resources on this.
http://www.ibm.com/developerworks/library/j-5things8/
http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstack.html


Monday, December 9, 2013

UseCompressedOops flag with java

Recently one of colleague was unable to launch eclipse, it says ‘Java returned with exit code =1’ , we have tried lot of options by increasing heap memory and all, but finally what worked out for him was by setting a  UseCompressedOops flag in eclipse configuration file.

He was using 64 bit machine and 64 bit JVM.

Here is the story, what compressed flag does.

The -XX:+UseCompressedOops option can improve performance of the 64-bit JRE when the Java object heap is less than 32 gigabytes in size. In this case, HotSpot compresses object references to 32 bits, reducing the amount of data that it must process.

Compressed oops is supported and enabled by default in Java SE 6u23 and later. In Java SE 7, use of compressed oops is the default for 64-bit JVM processes when -Xmx isn't specified and for values of -Xmx less than 32 gigabytes. For JDK 6 before the 6u23 release, use the -XX:+UseCompressedOops flag with the java command to enable the feature.

In summary:
Java version <6u23 - use command to set it.
Java version >=6u23 - by default enabled.
JDK7 - if -xmx not specified or -xmx <32GB => configured bydefault

You might have a question how does 64 bit pointer fits into 32 bit pointer, how it will be compressed. Please go through below link to understand more about it.

This is how JRocket JVM is compressing it, this will give us some understanding.





Java code to Java Heap

This is an excellent article which describes how Java 32 bit and 64 bit processes works with various primitives and objects in Java.

http://www.ibm.com/developerworks/opensource/library/j-codetoheap/index.html

Comparing 2 files


If you wanted to know whether 2 files is having same content or not, you need not to compare two files line by line, instead you can compare checksums of each file.

For this, you need to use Apache common-codec_1.7.jar file.




Example:


package com.kk;

import java.io.FileInputStream;
import java.io.IOException;

import org.apache.commons.codec.digest.DigestUtils;

public class CompareFiles {

public static boolean compare(String oldFile, String newFile) throws IOException {
FileInputStream fis1 = new FileInputStream(oldFile);
String oldmd5 = DigestUtils.md5Hex(fis1);// old file checksum
FileInputStream fis = new FileInputStream(newFile);
String latestmd5 = DigestUtils.md5Hex(fis); // new file checksum
return oldmd5.equals(latestmd5);
}
public static void main(String[] args) {
String oldFile = "D:\\Work\\test\\js\\kklibrary.js";
String newFile = "D:\\Work\\test\\kklibrary.js";
try {
boolean compare = compare(oldFile, newFile);
System.out.println("Both files are: "+ compare);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Tuesday, November 26, 2013

Eclipse Mac: Cocoa SWT

Recently I started working on Mac eclipse, and i was trying to understand what is the underlying SWT library.

They are using Cocoa SWT.

Cocoa is Apple's native object-oriented application programming interface (API) for the OS X operating system.

More @ http://en.wikipedia.org/wiki/Cocoa_(API)


SWT will have 2 plugins:

org.eclipse.swt  => swt core plugin
org.eclipse.swt.cocoa.macosx => Native interface calls to Mac OS X


Seems to be cocoa is supported from eclipse 3.5 version
More @ http://www.eclipse.org/swt/cocoaport.php

Download @ http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.3-201306052000/swt-4.3-cocoa-macosx.zip

Android SDK tools Windows registry keys

Below are the keys registered in windows registry, if you have installed through android sdk exe file.

For 32 bit machines
HKEY_LOCAL_MACHINE\Software\Android SDK Tools

For 64 bit machines
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Android SDK Tools




Eclipse Plugin spy for menu items

All we know that (Alt+shift+F1) is used to identify the class which is used in the eclipse workbench based on the active selection.

I recently realized that, (Alt+shift+F2) can be used with menu items.
Press Alt+shift+F2, then click on menu item that you want to identify.

Download from @ http://www.eclipse.org/pde/incubator/spy/

Opening eclipse in debug console mode


1.        If you have specified java in in vm arguments, modify javaw.exe to java.exe
Javaw.exe is a window process
Java.exe is a console process

-vm
C:/KK/jdk1.6.0_32/bin/java.exe

Eclipse by default make use of javaw.exe process.

2.       You can find directly eclipsec.exe in your eclipse folder, this will open up a console to print all console level messages. By default this will invoke java.exe process.

To get the debug statements, add –debug parameter in the command prompt.

Example:
Ø  eclipsec –debug

     You can also try this.
Ø  eclipse –debug -consolelog

To understand more about java.exe and javaw.exe @ http://javapapers.com/core-java/java-vs-javaw-vs-javaws/






Friday, November 22, 2013

E325: ATTENTION Found a swap file by the name ".git/.MERGE_MSG.swp"

I was facing this issue while pulling the code from the git central server.

Basically error says, 2 things.

(1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r .git/MERGE_MSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".git/.MERGE_MSG.swp"
    to avoid this message.



I have verified (1), could not find any other terminal which was accessing this file.

I am not sure about (2), so I went ahead and deleted directly '.git/.MERGE_MSG.swp' file.

Yes, Now it worked without any issues!!!



Thursday, November 14, 2013

Ampersand (&) is not shown on tooltips in Eclipse

To show '&' as part of tooltip information, You need to follow the rules of doubling an ampersand when you want a single ampersand for tool tip text.  All platforms follow this rule and strip out the underscore.

Example:
String tooltip = "Hello & World"; => Hello && World"

Look at the code below.

import org.eclipse.jface.window.DefaultToolTip;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;


public class MyToolTip extends DefaultToolTip {

public MyToolTip(Control control) {
super(control);
}

@Override
protected String getText(Event event) {
int x = event.x;
int y = event.y;

String tooltip = "Hello & World"; //only for test
//TODO: build tooltip info here.
if (tooltip.contains("&")) {
tooltip = tooltip.replace("&", "&&"); //without double ampersand replacement tooltip info will be shown as 'Hello _World' by replacing & by _.
}
return tooltip;
}
}

Wednesday, November 13, 2013

Cloud Computing - IAAS,PAAS and SAAS


http://www.rackspace.com/knowledge_center/whitepaper/understanding-the-cloud-computing-stack-saas-paas-iaas

In simple terms:
SaaS (Software as a Serviceapplications are designed for end-users, delivered over the web 
PaaS (Platform as a Service) is the set of tools and services designed to make coding and deploying those applications quick and efficient 
IaaS (Instrastructure as a Service) is the hardware and software that powers it all – servers, storage, networks, operating systems

Friday, November 8, 2013

New to JavaScript - Tryout Google chrome + F12 = JavaScript Console

If you are a beginner, and want to try out some Java script code , you can think of Google Java script console. This comes with Google chrome browser.


Just press F12 to launch in js console.

New to Mac - Shortcut key for Sleep

To do this, head to System Preferences > Security & Privacy > General. Check the box next to “Require Password”.

Find the screenshot below for this.




Now, you can make use of below keys.
Command + Option + Eject (On the top right corner button in macBook pro).
Command + Option + Power (Power button).


I am a beginner for Mac system, so I am trying to post my learnings and experience with it!!!

Wednesday, November 6, 2013

SAP JCo libraries for Mac OS

SAP JCo(Java Connectors) libraries would be required to connect to the SAP server.  Basically it will have sap JCo ‘jar’ file as well as sap JCo native library file.
For example. If you are connecting using JCo3 jars, below would be required based on the operating system.
§  sapjco3.jar: JCo Java runtime libraries – This would be same for 32 bit and 64 bit systems
§  [prefix]sapjco3.[extension]: JNI runtime library that contains JCo native code. The target operating system determines the prefix and file name extension:
§  Windows: sapjco3.dll
§  MacOS: libsapjco3.jnilib

Note: Ensure that the libraries you use are correct for your 32-bit or 64-bit system.
.


Navigation view scrollbar is not visible in Eclipse Mac OS but visible in windows OS

Have you ever encountered an issue with scrollbars in eclipse, especially in navigation views or application views, which is visible in windows or but does not appear in Mac OS system.

Then reason could be with the Mac system preferences. Please follow below steps to enable the scrollbar in Mac.

1. Go to Mac Menu( Apple icon), you will find this in the top left corner of the system.
2. Click on 'System Preferences'.
3. Click on 'General' item from the ‘Personal’ section.
4. You can find 'Show scroll bars’ section.
5. Select ' Always' radio button.

This will enable the scrollbar in the navigation view, without this option also scrollbar will be there, just that you will not be able to realize that there is a scrollbar unless you start dragging in navigation view.


Please find the screenshot for system preferences configuration.


New to Mac - Print screen shorcuts

Command+Shift+3: Takes a screenshot of the full screen (or screens if multiple monitors), and save it as a file to the desktop

Command+Shift+4: Brings up a selection box so you can specify an area to take a screenshot of, then save it as a file to the desktop

Command+Shift+4, then spacebar, then click a window: Takes a screenshot of a window only and saves it as a file to the deskto

Tuesday, November 5, 2013

Java was started by returned exit code=1

Possible causes include:  The eclipse.ini configuration, wrong JAVA version, incorrect or corrupted JAVA installation and incompatibility between an eclipse plugin and the JAVA version.

Following are some links that list some of the causes and possible solutions for this error:

1.  Add the command -XX:-UseCompressedOops  at the end of the eclipse.ini file.  See the following link where this action is reported to resolve this issue:

http://www.eclipse.org/forums/index.php/m/653614/#msg_653614

2.  Remove and reinstall both the JAVA JDK and JRE.  See the following link where this action is reported to resolve this issue:

http://anmolanand.wordpress.com/2011/06/19/eclipse-java-was-started-but-returned-exit-code-1/

3.  Check to make sure that a JAVA update did not cause the error.  See the following links where a JAVA update is reported to have caused the issue:

http://www.coderanch.com/t/503269/vc/Eclipse-start-but-return-exit

http://stackoverflow.com/questions/4587518/eclipse-error-on-startup-windows-7

4.  Some eclipse plugin may not be compatible with the installed JAVA version.  See the following link where this situation is reported to have caused the issue:

http://www.eclipse.org/forums/index.php/t/266786/

Java/Eclipse Source code download

Any jar files source code
http://grepcode.com/

Eclipse related: SWT, JFace, etc..
http://archive.eclipse.org/eclipse/downloads/

Any Java related jars:
http://www.java2s.com/

Wednesday, October 30, 2013

Reading windows registry using Runtime.getRuntime().exec(..) command

In my previous post @ http://exploreeclipse.blogspot.in/2013/10/reading-windows-registry-values-using.html , I was talked about reading windows registry using JNA library. But Java also provides support to read the windows registry through Java Runtime command execution.

In this article will focus on how to read win registry using Runtime.getRuntime().exec(..) command.

Basically you need these 3 parameters to hit the registry.
1. What is the Location ?
2. What is the registry key type ?
3. What is the key you want to read ?

Example:
I want to read the following parameters.
Location = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Android SDK Tools";
Key = "Path";
Registry Type = "REG_SZ"

Above parameters basically tells, what is the Andriod SDK Tools 'Path' directory ? That is what i want to figure it out.

Below piece of code, which will help you to get the Andriod sdk tools path directory.


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class WindowsRegistryReader {

public static void main(String[] args) {

String location = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Android SDK Tools";
String key = "Path";
String regType = "REG_SZ";

try {
String value = read(location, key, regType);
System.out.println("==========Output=================");
System.out.println("location: " + location);
System.out.println("Type: " + regType);
System.out.println("key: " + key + "  value: " + value);
System.out.println("=================================");

} catch (IOException e) {
e.printStackTrace();
}
}

public static String read(String location, String name, String regType) throws IOException {

Process p = Runtime.getRuntime().exec("reg QUERY \"" + location + "\" /v \"" + name + "\"");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String out = "";
while ((out = in.readLine()) != null) {
if (out.matches("(.*)\\s+REG_(.*)")) {
break;
}
}
in.close();
if (out != null) {
int indexOf = out.indexOf(regType);
if (indexOf != -1) {
String value = out.substring(indexOf + regType.length()).trim();
return value;
}
}
return null;
}
}


Output:
==========Output=================
location: HKEY_LOCAL_MACHINE\Software\Wow6432Node\Android SDK Tools
Type: REG_SZ
key: Path  value: C:\Program Files (x86)\Android\android-sdk

=================================

Various Windows registry type values can be found @ http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx

Monday, October 28, 2013

Programmatically gettting Eclipse installation path directory

You might have some properties file or some other file at your eclipse home directory and you want to read that, for this you required a eclipse home directory path.

Below is the piece of code which helps you to get that.

public class EclipseLocation {

@SuppressWarnings("unchecked")
public static <T> T getService(Class<T> clazz, String filter) {
BundleContext context = MyPlugin.getDefault().getBundle().getBundleContext();
ServiceTracker tracker = null;
try {
tracker = new ServiceTracker(context, context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + clazz.getName() //$NON-NLS-1$ //$NON-NLS-2$
+ ")" + filter + ")"), null); //$NON-NLS-1$ //$NON-NLS-2$
tracker.open();
return (T) tracker.getService();
} catch (InvalidSyntaxException e) {
return null;
} finally {
if (tracker != null)
tracker.close();
}
}
}

Invocation:
EclipseLocation.getService(Location.class, Location.INSTALL_FILTER)


Output:
C:/myInstallations/Eclipse



You can also achieve the same thing using the system property 'eclipse.launcher'.

//this returns C:/myInstallations/Eclipse/eclipse.exe
String launcherLocation = System.getProperty("eclipse.launcher");  //

if (launcherLocation != null ) {
File launcherLocationFile = new File(launcherLocation);

//get the parent of eclipse.exe file->C:/myInstallations/Eclipse
String eclipseDir = launcherLocationFile.getParent();

//your piece of logical code resides here
                   }



Hope this helps.

Thursday, October 24, 2013

Reading Windows registry values using java


This can be done using JNA(Java Native Access) library.

Use this link to download @ https://github.com/twall/jna#readme

Required jars: 

Piece of code to test:

Here I am trying to read Android installation path from windows registry.


public static void main(String[] args) {

try {
Map<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Android SDK Tools");
for (String value : values.keySet()) {
System.out.println(value + "   " + values.get(value));

}
} catch (Exception e) {
e.printStackTrace();
}

}

public static void main(String[] args) {

try {
Map<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Android SDK Tools");
for (String value : values.keySet()) {
System.out.println(value + "   " + values.get(value));

}
} catch (Exception e) {
e.printStackTrace();
}

}


Output:
Path   D:\Work\Android\adt-bundle-windows-x86-20130522\adt-bundle-windows-x86-20130522

Friday, October 18, 2013

Java VM PermGen space

The Java VM memory is split up to 3 memory spaces:

  • The Java Heap. Applicable for all JVM vendors, usually split between YoungGen (nursery) & OldGen (tenured) spaces.
  • The PermGen (permanent generation). Applicable to the Sun HotSpot VM only (PermGen space will be removed in future Java 7 or Java 8 updates)
  • The Native Heap (C-Heap). Applicable for all JVM vendors.

The Java HotSpot VM permanent generation space is the JVM storage used mainly to store your Java Class objects.  The Java Heap is the primary storage that is storing the actual short and long term instances of your PermGen Class objects.

The PermGen space is fairly static by nature unless using third party tool and/or Java Reflection API which relies heavily on dynamic class loading.
It is important to note that this memory storage is applicable only for a Java HotSpot VM; other JVM vendors such as IBM and Oracle JRockit do not have such fixed and configurable PermGen storage and are using other techniques to manage the non Java Heap memory (native memory).

Below diagram showcases various heap memories and how we can configure them using vm arguments.




Understanding how the JVM uses native memory on Windows

JVM: Permgen is a non-heap


In Oracle's JVM, the permanent generation is not part of the heap. It's a separate space for class definitions and related data. In Java 6 and earlier, interned strings were also stored in the permanent generation. In Java 7, interned strings are stored in the main object heap.


From above link, we can understand these terms:

Eden Space (heap): The pool from which memory is initially allocated for most objects.

Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.

Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.

Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.

Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.



Finding java process id's

Go to command prompt and type jps, this will provide the currently running java process id's in your system.




Troubleshooting Memory Leaks

http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/memleaks.html


Meaning of OutOfMemoryError

One common indication of a memory leak is the java.lang.OutOfMemoryError error. This error is thrown when there is insufficient space to allocate an object in the Java heap or in a particular area of the heap. The garbage collector cannot make any further space available to accommodate a new object, and the heap cannot be expanded further.
When the java.lang.OutOfMemoryError error is thrown, a stack trace is printed also.
java.lang.OutOfMemoryError can also be thrown by native library code when a native allocation cannot be satisfied, for example, if swap space is low.
An early step to diagnose an OutOfMemoryError is to determine what the error means. Does it mean that the Java heap is full, or does it mean that the native heap is full? To help you answer this question, the following subsections explain some of the possible error messages, with reference to the detail part of the message:

Sizing the Java heap


Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.
Introduction
An incorrectly sized Java heap can lead to OutOfMemoryError exceptions or to a reduction in the performance of the Java application.
If the Java heap is smaller than the memory requirements of the application, OutOfMemoryError exceptions are generated because of Java heap exhaustion. If the Java heap is slightly larger than the requirements of the application, garbage collection runs very frequently and affects the performance of the application.
You must correctly size the Java heap based on the real memory usage of the Java application.
Sizing the heap based on application memory utilization
Set the maximum Java heap size, using the -Xmx command-line option, to a value that allows the application to run with 70% occupancy of the Java heap.
The Java heap occupancy often varies over time as the load applied to the application varies. For applications where occupancy varies, set the maximum Java heap size so that there is 70% occupancy at the highest point, and set the minimum heap size, using the -Xms command line option, so that the Java heap is 40% occupied at its lowest memory usage. If these values are set, the Java memory management algortihms can modify the heap size over time according to the application load, while maintaining usage in the optimal area of between 40% and 70% occupancy.
Maximum possible heap size and maximum recommended heap size (32-bit Java)
The memory space provided by the operating system to the Java process varies by operating system and is used for two separate memory areas: the Java heap and the native heap. Because a finite amount of memory is provided by the operating system, and that memory is shared between the two heaps, the larger the amount of memory that is allocated to the Java heap, using the -Xmx setting, the smaller the native heap becomes. If the native heap is too small, an OutOfMemoryError occurs when it is exhausted, in the same way as for the Java heap.
PlatformAdditional optionsMaximum heap sizeRecommended heap size limitAdditional notes
AIXNone3.25 GB2.5 GBMaximum heap size is not required to be, but should ideally be, a multiple of 256 MB
LinuxNone2 GB1.5 GB
Hugemem Kernel3 GB2.5 GB
WindowsNone1.8 GB1.5 GB
/3GB1.8 GB1.8 GB
The table shows both the maximum Java heap possible and a recommended limit for the maximum Java heap size setting. The use of a maximum Java heap setting up to the recommended limit is unlikely to reduce the native heap size to a point that the native heap is exhausted.
Before setting a Java heap size greater than the recommended limit, you must understand the level of usage of the native heap, to ensure that the native heap does not become exhausted.
If you are running an application that has particularly high numbers of threads or makes heavy use of Java Native Interface (JNI) code, for example, Type 2 JDBC drivers, you might experience problems relating to the native heap with smaller Java heap sizes than the recommended limit.
Maximum possible heap size and maximum recommended heap size (64-bit Java)
When running 64-bit Java, the memory space provided by the operating system to the Java process is very large. You can therefore assume that no limit is imposed on the maximum size of the Java heap because of the contention of memory resource between the Java heap and the native heap.
Java heap size and amount of physical memory available
It is important to have more physical memory than is required by all of the processes on the machine combined to prevent paging or swapping. Paging reduces the performance of the system and affects the performance of the Java memory management system.
When increasing the Java heap size, ensure that enough unused physical memory is available on the machine to cover the increase. If sufficient physical memory is not available, either install additional memory or take into account the effect on overall performance that occurs.
This requirement does not apply to operating systems running on System z.

Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.



Memory Limits for Windows Releases

http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx


Physical Memory Limits: Windows 8

The following table specifies the limits on physical memory for Windows 8.
VersionLimit on X86Limit on X64
Windows 8 Enterprise
4 GB
512 GB
Windows 8 Professional
4 GB
512 GB
Windows 8
4 GB
128 GB


Physical Memory Limits: Windows 7

The following table specifies the limits on physical memory for Windows 7.
VersionLimit on X86Limit on X64
Windows 7 Ultimate
4 GB
192 GB
Windows 7 Enterprise
4 GB
192 GB
Windows 7 Professional
4 GB
192 GB
Windows 7 Home Premium
4 GB
16 GB
Windows 7 Home Basic
4 GB
8 GB
Windows 7 Starter
2 GB
N/A



Understanding 32-bit vs. 64-bit systems with Java Heap

Eclipse Mac OS: Hyperlinks are not working in welcome page

Have you ever come across the issue, where hyperlinks is not working in Mac OS Eclipse but it works in Windows OS.

We had faced this issue with the welcome page, where hyper links are not working. The reason was, href links with target=”_blank” is causing the issue.

We couldn't see any other solution other than removing it.


To understand about target attribute in html @ http://www.w3schools.com/tags/att_a_target.asp

Similar thread on the same topic @  https://code.google.com/p/android/issues/detail?id=41109

Thursday, October 17, 2013

SAP Transaction codes

You can find all transaction codes @ http://www.tcodesearch.com/


SE37 - ABAP Function Modules
SE16 - Data Browser(Table search)
SE11 - ABAP Dictionary Maintenance

GIT: Finding a commit based on SHA1 ID

> git show <sha1-id>

Example: > git show e43db49

This will display the complete changes including the with commit message.

Adding a new menu item in Eclipse Help Menu

As shown in the image below, if you want to add 'Tutorials' menu item in the Help Menu in Eclipse.




Adding command extension:

      <command
            defaultHandler="com.kk.help.TutorialsHelpHandler"
            id="com.kk.command.tutorialshelp"
            name="Tutorials">
      </command>


Adding menu extension:

 <menuContribution
            allPopups="false"
            locationURI="menu:help?after=intro">
         <separator
               name="slot1"
               visible="true">
         </separator>
         <command
               commandId="com.kk.command.tutorialshelp"
               label="Tutorials"
               style="push">
         </command>
         <separator
               name="slot2"
               visible="true">
         </separator>
      </menuContribution>


Handler implementation:

public class TutorialsHelpHandler extends AbstractHandler implements IHandler{

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//implemention here

retun null;

}
}

Launching a URL in external browser from an eclipse plugin

public class HelpHandler extends AbstractHandler implements IHandler{


public static final String HELP_LIBRARY = "http:/kk.com/KKLibrary/";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(HELP_LIBRARY ));
} catch (PartInitException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
}

Tuesday, October 15, 2013

toArray Dynamic behaviour

public class ToArrayTest {

public static void main(String[] args) {

ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");

//what happens here??, since I have allocated new String[0] for single element, will it return single element or all elements ??
String[] array = arrayList.toArray(new String[0]); 
System.out.println(array.length);

}
}


Output:  4


As per spec, it's going to create a new array, if it does not fit in.
Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. 

Wednesday, October 9, 2013

Understanding how Eclipse plug-ins work with OSGi

Install the plug-in bundle in the Equinox console


  1. Install the plug-in bundle in the Equinox console.
    osgi> install file:///<path to bundle>
    Equinox lists the bundle ID for the newly installed bundle:
    Bundle id is 17
  2. Enter the following line to start the bundle in the Equinox console, where <id> is the bundle ID assigned when the bundle was installed:
    osgi>  start <id>
  3. Retrieve the service status in the Equinox console to verify that the bundle started:
    osgi> ss
    When the bundle starts, the bundle lists the ACTIVE state, for example:
    17      ACTIVE      com.mycompany.plugin.bundle_xx

Eclipse Equinox and OSGI

Go through this article to get the understanding on Eclipse Equinox
http://www.theserverside.com/news/1365049/Eclipse-Equinox-and-OSGi

Understanding UML Class diagrams


http://msdn.microsoft.com/en-us/library/dd409437%28VS.100%29.aspx



Three classes showing relationships and properties
Shape
Element
Description
1
Class
A definition of objects that share given structural or behavioral characteristics. For more information, see Properties of Types in UML Class Diagrams.
1
Classifier
The general name for a class, interface, or enumeration. Components, use cases, and actors are also classifiers.
2
Collapse/ Expand control
If you cannot see the details of a classifier, click the expander at upper-left of the classifier. You might also have to click the [+] on each segment.
3
Attribute
A typed value attached to each instance of a classifier.
To add an attribute, click the Attributes section and then press ENTER. Type the signature of the attribute. For more information, seeProperties of Attributes in UML Class Diagrams.
4
Operation
A method or function that can be performed by instances of a classifier. To add an operation, click the Operations section and then pressENTER. Type the signature of the operation. For more information, see Properties of Operations in UML Class Diagrams.
5
Association
A relationship between the members of two classifiers. For more information, see Properties of Associations in UML Class Diagrams.
5a
Aggregation
An association representing a shared ownership relationship. The Aggregation property of the owner role is set to Shared.
5b
Composition
An Association representing a whole-part relationship. The Aggregation property of the owner role is set to Composite.
6
Association Name
The name of an association. The name can be left empty.
7
Role Name
The name of a role, that is, one end of an association. Can be used to refer to the associated object. In the previous illustration, for any OrderOO.ChosenMenu is its associated Menu.
Each role has its own properties, listed under the properties of the association.
8
Multiplicity
Indicates how many of the objects at this end can be linked to each object at the other. In the example, each Order must be linked to exactly one Menu.
* means that there is no upper limit to the number of links that can be made.
9
Generalization
The specific classifier inherits part of its definition from the general classifier. The general classifier is at the arrow end of the connector. Attributes, associations, and operations are inherited by the specific classifier.
Use the Inheritance tool to create a generalization between two classifiers.
Package containing interface and enumeration
Shape
Element
Description
10
Interface
A definition of part of the externally visible behavior of an object. For more information, see Properties of Types in UML Class Diagrams.
11
Enumeration
A classifier that consists of a set of literal values.
12
Package
A group of classifiers, associations, actions, lifelines, components and packages. A logical class diagram shows that the member classifiers and packages are contained within the package.
Names are scoped within packages so that Class1 within Package1 is distinct from Class1 outside that package. The name of the package appears as part of the Qualified Name properties of its contents.
You can set the Linked Package property of any UML diagram to refer to a package. All the elements that you create on that diagram will then become part of the package. They will appear under the package in UML Model Explorer.
13
Import
A relationship between packages, indicating that one package includes all the definitions of another.
14
Dependency
The definition or implementation of the dependent classifier might change if the classifier at the arrowhead end is changed.
Realization shown with conector and lollipop
Shape
Element
Description
15
Realization
The class implements the operations and attributes defined by the interface.
Use the Inheritance tool to create a realization between a class and an interface.
16
Realization
An alternative presentation of the same relationship. The label on the lollipop symbol identifies the interface.
To create this presentation, select an existing realization relationship. A Action tag appears near the association. Click the action tag, and then clickShow as Lollipop.