Showing posts with label JAVA Programming. Show all posts
Showing posts with label JAVA Programming. Show all posts

Tuesday, April 13, 2010

Adding Security Certificate to JVM to handle SecurityCertificateError

Handling SecurityCertificateError exception in JAVA by adding security certificate using Keytools

To add the security certificate for https URL the following steps needs to be followed

  • Take a backup of cacerts file in the following directory (This can be your default JRE directory also) C:\Program Files\IBM\SDP70\runtimes\base_v6\java\jre\lib\security\
  • Save the security certificate in some location for ex c:\certificate.cer
  • Go to Run type cmd
  • Execute CD C:\Program Files\IBM\SDP70\runtimes\base_v6\java\jre\bin (This is the location of the JRE WebSphere uses, in other environments please navigate to the JRE BIN the application uses)
  • Then execute the following command
(SYNTAX Keytool –keystore – import – file -alias<> )

Command
keytool -keystore "C:\Program Files\IBM\SDP70\runtimes\base_v6\java\jre \lib\security\cacerts" -import -file c:\certificate.cer -alias https://your-url.net

  • It will ask for a password , enter changeit
  • The security certificate will be added for the JRE

Now you can access the URL or access the webservice in the URL.

Friday, April 2, 2010

Setting JAVA HOME through Command Line in Windows

Hi all,
If you are working on some old windows machines and want to set JAVA_HOME and PATH environment variables follow the steps.

Start --> Run-->CMD .. In the command prompt first type


echo %JAVA_HOME% , if the JAVA_HOME variable is already set the path will be printed.
eg: c:/Program Files/java1.6

else %JAVA_HOME% will be printed.

You can set JAVA_HOME by typing

SET JAVA_HOME = c:/Program Files/Java (The path where your JRE or JDK is installed)

Then you can set the bin path by typing

SET PATH = %PATH%;%JAVA_HOME%\bin what you are doing here is appending the existing set PATH's with JAVA_HOME/bin.

You can also directly set the path to the JAVA Bin directory instead of the above steps like
SET PATH = %PATH%;c:/Program Files/JAVA/bin

Then if you want to view the set path you can type echo %PATH% ..

Sunday, February 28, 2010

JAVA Jokes - The fun side of JAVA

Too much of JAVA technical stuff , now here is a collection of some JAVA jokes that caught my eye..

---------
9:00 AM
Project manager: ” Where is Joe?”
Java programmer A: ” You know he is always lazy loadded.”

1:00 PM:
Project manager: ” Where is Joe??”
Java programmer B: ” He is in passive mode.”

5:30 PM:
Project manager: ” Could I see Joe in rest of my life ?????”
Java programmer C: “Never, he has been garbage collected.”

————

Why did the Integer drown?
Cos he couldn’t Float!

————

Q: Why did the Java Chicken cross the road?
A: He didn’t, he was just referred to on the other side.

————

yo mama’s so fat… she get an ArrayOutOfBoundException!
yo mama’s so poor… she does garbage collection for a living!
yo mama’s so ugly… her java.lang.reflect took down the mirror site!

————

Two ints and a Float in a bar. They spot an attractive Double on her own. The first int walks up to her. “Hey, baby”, he says, “my VM or yours”. She slaps him and he walks back dejected.

The second int walks over. “Hey, cute-stuff, can I cook you Beans for breakfast”. After a quick slapping, he too walks back.

The Float then ambles over casually. “Were those two primitive types bothering you?”, he remarks.

“Yes. I’m so glad you’re here”, she says. “They just had no Class!”

Tuesday, February 2, 2010

YAHOO Pipes

Yahoo has come up with yet another Web 2.0 gizmo. This one is called Yahoo Pipes. Its like Unix pipes applied to the web!

It goes like this .. anybody with a Yahoo ID can define a “pipe”. A pipe at its most basic form, picks data from “X” source and applies “Y” transform over it and finally provides “Z” output. Here, X could be anything ranging from an RSS/ATOM feed, any URL emiting JSON or XML content (even plain HTML works, I think ..), or it could be user input. Y implies a transform like applying a filter on the data, searching on Yahoo, Google or Flickr etc and Z is the final output you get. The best part is you can do all this “piping” using Yahoo’s web-visual editor (see the pic below), without knowing a thing about XML,HTML,RSS,whatever …

I created a Pipe just for kicks .. its at href="http://pipes.yahoo.com/pipes/pipe.info?_id=jnZ0iPYa3BGXuH3I6kjTQA"

This pipe consumes the RSS feed from digg.com’s technology section and extracts all posts that have the keyword “Google” in it. Simple, but cute ! ;-)


Thursday, January 28, 2010

Accessing Webservices from PHP

Normally, most of the current windows products provides webservice for many of its functionalities. Particularly the sharepoint 2007 server, has lot of webservice that external applications can use it.

Again, accessing those webservices through .NET is pretty easy with its built in function. But, to access it through languages like PHP, requires some analysis, particularly for those who are doing it for first time.
The nusoap.php is a populat choice to access the webservice via Php.

It can be downloaded from the following sourceforge URL.

href="http://sourceforge.net/project/showfiles.php?group_id=57663

Here is the code snippet to access it

require_once( '/nusoap.php');

$client = new soapclient('http://ctsgvcchannel1/_vti_bin/SearchWebService.asmx',false,$proxyhost, $proxyport, $proxyusername, $proxypassword);

$client->setcredentials($username,$password);

$err = $client->getError();

if ($err) {

echo '

Constructor error

' . $err . '
';

}

// Doc/lit parameters get wrapped

$param = array('strKeyWord' => 'java','pageLength'=>(int)'5');

$result = $client->call('SimpleSearch', $param, '', 'http://tempuri.org/SimpleSearch', false, true);

// Check for a fault

if ($client->fault) {

echo '

Fault

';

print_r($result);

echo '
';


} else {

// Check for errors

$err = $client->getError();

if ($err) {

// Display the error

echo '

Error

' . $err . '
';


} else {

// Display the result

echo '

Result

';

print_r($result);

echo '
';


}

}

echo '

Request

' . htmlspecialchars($client->request, ENT_QUOTES) . '
';


echo '

Response

' . htmlspecialchars($client->response, ENT_QUOTES) . '
';

Saturday, January 23, 2010

Web Services - How does it work and where to use ?

Web Service has been the new buzz word in the past few years. In this post we will explore the basic elements of it and where it can be applied.

Consider this scenario a JAVA application running in a server and has an access to a stock price data base, where the recent stock prices are updated and you have a stand alone .NET stand alone application running in your computer from which you want to access the stock prices and display it in your computer. Remember you cannot be provided access to their database. So what is the solution ???

You face 2 problems

  • You dont have access to their database
  • The application that has access to the database is totally a different platform
How do you overcome such a situation? .. The answer is webservice.
If the a JAVA method that could fetch the data is exposed to the outside world that listens to the incoming requests and sends back the requested data that would be perfect isn't it?..

WebService uses HTTP protocol to send the request and response in SOAP (Simple Object Access Protocol) format.

There should be a contract to access the webservice this is provided by WSDL -Web Services Definition Language, it is also a XML file containing the method names and their return types and lot more. To learn more about webservice visit this page.

Friday, January 15, 2010

Know the core libraries in Java

Java differs from other languages in that the number of classes and interfaces in its standard libraries is very large.Beginners to Java should take note that very many common tasks have already been implemented in the libraries. The most widely used packages are probably java.lang, java.util, java.sql, and java.io.

As well, the libraries

* are built by experts
* generally improve their performance over time
* are widely used, and form defacto standards

Implementing something which already exists in the libraries is probably wasted effort.Significant changes and additions to the standard libraries occur in each major release, and it pays to keep current. For example, the 1.4 release of the JDK includes regular expressions, assertions, logging services, and more, in its list of new features. The Java 5 release has several major new features, including generics, an enhanced for loop, enums, autoboxing, and metdata. The Java 6 release has no new language features, and is not as dramatic as the 1.5, but it still has some interesting new features, such as scripting, the JConsole monitoring tool, and various Swing improvements.

Sunday, January 10, 2010

You can compare String objects in a variety of ways, and the results are often different. The correctness of your result depends largely on what type of comparison you need. Common comparison techniques include the following:

  • Compare with the == operator.
  • Compare with a String object’s equals method.
  • Compare with a String object’s compareTo method.
  • Compare with a Collator object.
  • Comparing with the == Operator
The == operator works on String object references. If two String variables point to the same object in memory, the comparison returns a true result. Otherwise, the comparison returns false, regardless whether the text has the same character values. The == operator does not compare actual char data. Without this clarification, you might be surprised that the following code snippet prints The strings are unequal.

String name1 = “Michèle”;
String name2 = new String(”Michèle”);
if (name1 == name2) {
System.out.println(”The strings are equal.”);
} else {
System.out.println(”The strings are unequal.”);
}

The Java platform creates an internal pool for string literals and constants. String literals and constants that have the exact same char values and length will exist exactly once in the pool. Comparisons of String literals and constants with the same char values will always be equal.

Comparing with the equals Method
The equals method compares the actual char content of two strings. This method returns true when two String objects hold char data with the same values. This code sample prints The strings are equal.

String name1 = “Michèle”;
String name2 = new String(”Michèle”);
if (name1.equals(name2) {
System.out.println(”The strings are equal.”);
} else {
System.out.println(”The strings are unequal.”);
}

Comparing with the compareTo Method
The compareTo method compares char values similarly to the equals method. Additionally, the method returns a negative integer if its own String object precedes the argument string. It returns zero if the strings are equal. It returns a positive integer if the object follows the argument string. The compareTo, method says that cat precedes hat. The most important information to understand about this comparison is that the method compares the char values literally. It determines that the value of ‘c’ in cat has a numeric value less than the ‘h’ in hat.
String w1 = “cat”;
String w2 = “hat”;
int comparison = w1.compareTo(w2);