Tuesday, May 7, 2013

String literal can be replaced by a character literal

The single character string literal can be replaced by a character literal to improve performance.

Example:


Given two functions:
public static String concatString(String cs) {
    return "hello" + cs + "world";
}

public static String concatChar(char cc) {
    return "hello" + cc + "world";
}
after examination of the bytecode it boils down to two AbstractStringBuilder.append(String) vs.AbstractStringBuilder.append(char).
Both methods invoke AbstractStringBuilder.expandCapacity(int)) which will allocate a new char[]eventually and System.arraycopy the old content first.
Afterwards AbstractStringBuilder.append(char) just has to put the given char in the array whereas AbstractStringBuilder.append(String) has to check a few constraints and calls String.getChars(int, int, char[], int) which does another System.arraycopy of the appended string.


Trial:



package kondal.performance;

public class StringTest {

public static void main(String[] args) {

long start = System.currentTimeMillis();

StringBuffer message1 = new StringBuffer("Hello world");
for (int i = 0; i < 1000000; i++) {
message1.append("Program");
message1.append("!");
}
long diff = (System.currentTimeMillis() - start);
System.out.println("Totat time(string) in ms:" + diff);


long start2 = System.currentTimeMillis();

StringBuffer message2 = new StringBuffer("Hello world");
for (int i = 0; i < 1000000; i++) {
message2.append("Program");
message2.append('!');
}
long diff2 = (System.currentTimeMillis() - start2);
System.out.println("Totat time(Char) in ms:" + diff2);

}
}


Results:
Totat time(string) in ms:154
Totat time(Char) in ms:116






Friday, May 3, 2013

Java script - Prototype and new


Basically I was looking for how 'new' and 'prototype' things works out in Java script, and I could find very good site, which has lot of stuff on these areas.

http://ejohn.org/apps/learn/#65

Example #1:


RecordManager= function(){};

RecordManager.prototype.getRecords = function(){
  return true;
};

var manager = new RecordManager();

assert(manager.getRecords(), "status");

OutputPASS status


Example #2:


function RecordManager(){}

RecordManager.prototype.addRecords= function(){
  return true;
};

var manager1 = RecordManager();
assert( manager1 , "Is undefined, not an instance of RecordManager." );

var manager2= new RecordManager();
assert( manager2.addRecords(), "Method exists and is callable." );

Output:

  1. FAIL Is undefined, not an instance of RecordManager.
  2. PASS Method exists and is callable.





Tuesday, April 30, 2013

What skills do tech companies look forr in new hires ??

Interesting article on what tech companies look for in new hires:
http://mashable.com/2012/09/05/tech-skills-hiring/



Everyone knowing their one thing - What's the one thing that you do better than anyone else??


Product minded and want to see their codes launched.
Who take pride in crafting a fantastic product experience, we look risk takers who are willing to fail but really eager to launch things.

How knows how to setup a process  and ability to execute tasks
How has passion in doing things

Wednesday, April 24, 2013

How to setup RFC Destination to SAP System



RFC Destination is one of the way to connect from an ABAP system to an external system. This weblog talks about the basic HTTP connection to external server (type G).
Business usecase from my area of expertise is connecting any R/3 system to a CE ESR (mainly for Proxy generation of Services Modeled in ESR).

Step 1:

Go to transaction SM59.
UI looks like as follows:

Step 2:

As shown in the picture above, select the HTPP connection to external server and click on the Create icon (marked in red).
RFC Connection UI will come up. Fill in the necessary details as shown below:


Note that RFC Name should be unique, connection type should be Type-G.
Other information you need to enter is the host (or IP), Port and the Context root. The following URL should match the service deployed on AS.
A good example to use the RFC destination will be to write a small ABAP code to establish connection to a servlet deployed on AS. User can use HTTP protocol to invoke it from ABAP.

Step 3:

Click on the save icon  and you will recieve an info message stating "HTTP connection may not be secure" which is true.


Press  to continue.

Step 4:

Now most of the application which the RFC destination points to will require some basic authentication. And if it is not provided part of the RFC destination, quite possible when the program uses the RFC Destination, it prompts for username-password! So lets enter the logon & security details as shown below: 

Step 5: 

Click on the save icon  and now press on the connection test button to see whether the server is available or not. Incase the entries point to the correct system, output should be somewhat similar as shown below: 
  
More info:
- Incase wrong entries are provided error message comes at the status bar:
- Connection test DO NOT check the credentials. Even if wrong credentials are passed this information is not validated.
Next steps... write small abap code to invoke a servlet...!!! Sounds simple & interesting.





Friday, April 19, 2013

Controlling number of parallel jobs based on number of available processors for JVM



//No. of processors available for JVM
private static final int NO_OF_PROCESSORS = Runtime.getRuntime().availableProcessors();
private static final String JS_FAMILY = "js_typechecking_family"; //$NON-NLS-1$


Override belongsTo method in Job.
@Override

public boolean belongsTo(Object family) {
return family == JS_FAMILY;
}


Execution call:


try {
monitor.beginTask("Project: " + project.getName(), jsModules.size());

//Create number of parallel jobs based on the number of processors available to the Java virtual machine.
IJobManager jobManager = Job.getJobManager();
for (IFile iFile : jsModules) {
Job[] find = jobManager.find(JS_FAMILY);
if (find.length == NO_OF_PROCESSORS) {
while (true) {
try {
Thread.sleep(100);//sleep for some time buddy!!
} catch (InterruptedException e) {
//nothing
}
Job[] queueJobs = jobManager.find(JS_FAMILY);
if (queueJobs.length < NO_OF_PROCESSORS) {
break;
}
}
}

if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
monitor.setTaskName("Identifying xxx: " + iFile.getName());
try {
startExecution(...);//args here
} catch (Exception e) {
EditorPlugin.logError(e);
}
monitor.worked(1);
}

} finally {
monitor.done();
}






Thursday, April 18, 2013

What is SAP JCo and where can i get it ?


Setting up a SAP connection

This section describes how to set up a SAP connection, if you plan to develop mobile applications using the SAP framework.
To set up the SAP connection you must:
·  Configure the SAP connection using the SAP Java Connector (SAP JCo). SAP JCo is a toolkit that allows a Java application to communicate with any SAP system. The SAP Java Connector can be downloaded from the SAP Service Marketplace Web site by a registered SAP customer.

Configuring the SAP Java connector
1.     Open a Web browser window and enter the SAP Marketplace URL, which currently is:
2.  https://websmp204.sap-ag.de/swdc or  http://service.sap.com/connectors --> SAP Java Connector
The Client Authentication window displays.
3.     Select the certificate to use when connecting, and click OK. The Enter Network Password window displays.
4.     Enter your registered SAP customer user name and password in the User Name and Password fields, and click OK. The SAP Software Distribution Center window displays.
5.     In the You Are Here navigation bar on the left side of the page, navigate to Download | SAP Connectors | SAP Java Connector | Tools and Services. Click the link for SAP JCo Release 3.0.X to download the SAP Java Connector.
6.     Follow the installation instructions provided by SAP. When prompted, copy the .jar and .dll files to these locations:

Configuring the SAP environment for Eclipse Studio

To configure SAP Environment for IDE   Copy the following files from the SAP installation and place them in <JDK_Installation_Path>/jre/ lib/ext folder:
  1. sapjco3.dll
    sapjco3.jar
    Note: If you have a Windows OS, copy the sapjco3.dll file. If you have a Linux or Unix environment, copy the sapjco3.so file.

  2. Modify the config.ini file and add the following line at the end of the file:
    osgi.parentClassloader=ext
    This file is available at <Eclipse_Installation_Path>/configuration.

      Incase of Mac OS, keep sapjco3.dll and libsapjco3.jnilib files in the java/extensions folder.
  1.     Restart Eclipse. 



Identifying deadlocks in your Eclipse RCP

Add following parameters in eclipse.ini file


-Dcom.sun.management.jmxremote.port=1436 <any free port>
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false


Open  JConsole.exe: which can found in the following directory
C:\Program Files (x86)\Java\jdk1.6.0_31\bin


Enter the remote host and port details:
localhost:1436

We can find the thread details in Thread section.