Archive for the ‘Java’ Category

Page 1 of 3123




How to migrate preferences of one Eclipse workspace to another?

Posted on August 29th, 2011 in Java, Tutorials | 8 Comments »

When you switch to a new workspace for the same project in Eclipse you generally have a lot of work to do before you start import or creating projects. This work majorly involves setting of preferences and other settings to your new workspace. This sometimes becomes painful and tiresome especially if you have a lot or project specific preferences to be applied to the workspace or have customized many of the default ones.

Also, it is many a times, error prone since you might forget some preferences and end up factoring why your code is not behaving the same way as it used to in your earlier workspace.

The secret to make this easier is to find out where does eclipse store this settings and thankfully it is easy enough. Eclipse stores all preferences in text format, properly separated for each individual plugin. So, migrating the settings from one workspace to another is just simple, copy-paste the setting files.

The location where the preferences are kept is :
<workspace_location>\.metadata\.plugins\ org.eclipse.core.runtime\.settings

eclipse_workspace_preferences

Check the folder and try to see what is within each file and you will see all your plugin settings in it.

So what you would need to do is to copy org.eclipse.core.runtime folder and paste it in your other workspace inside \.metadata\.plugins. Do not copy any other folder or else it may lead to some unusual workspace behavior.

If you want to transfer only the preference for a particular plugin then you just need to copy that individual file alone, from within this folder.

Action Steps:

  • Switch your existing workspace to a temporary workspace.
  • Close eclipse
  • Copy the above folder and start eclipse with the temporary workspace
  • Now check all your earlier settings will be reflected

Simple, isn’t it? Let me know if it worked for you.

Reflection in Java – Simplified

Posted on November 24th, 2008 in Concepts, Featured, Java | 33 Comments »

There are times when you wish you had some access to the information present in your Java classes. Information, such as which fields, methods and constructors are defined in it. This information is called as the metadata of a class and there is a way in which you can access easily without doing tedious coding or resorting to any hacks. It is called as Reflection.

Reflection in Java is done by using using the java.lang.Class class. This class provides access to all the information within your own applications classes or even the regular java library classes. Let’s say you have a class in a package called com.tt.company.Employee then if you need the metadata of the Employee class you would have to first assign it to the Class as :

Class c = Class.forName(“com.tt.company.Employee);

Accessing Fields, Methods and Constructors with Reflection

If you are not sure which fields and methods are declared in a class and you don’t have access to the source code then you can easily get this information by simple looping.

For example, if I wanted to access the fields and methods declared in the class Employee then its as simple as the below code.

Field[] fields = c.getFields();
 
Method[] methods = c.getMethods();
for (Field f : fields)
 
System.out.println("Field: " + f.getName());
 
for (Method m : methods)
 
System.out.println("Method:" + m.getName());

You might get some additional methods if you use the getMethods() method. This is because Read the rest of this entry »

Mystery of Accessibility in Local Inner Classes

Posted on April 14th, 2008 in Concepts, Java | 26 Comments »

Here is an interesting concept which I came across just recently and considered it worth sharing. I was reading about inner classes concepts where in, there is a type of inner class called the local inner class. Local inner classes are those classes which reside within the function of a method belonging to an outer class. The code can be something shown like this.

public class LocalInnerClassTest {
	public void defineInnerClass() {
		class MyLocalInnerClass {
			public void doSomething() {				
			}
		}
 
	}
}

Now lets suppose we want to pass a variable in the defineInnerClass() and pass it to the doSomething() for some computation, then according to the specifications on local inner classes methods we must declare the variables as final or else it will result in a compile time error. So the resulting code must be something as follows: Read the rest of this entry »

Resolving the “Unsupported major.minor version 49.0” Error

Posted on October 10th, 2007 in Issues, Java, Java EE | 26 Comments »

Many a times I have come across my friends who get this error and are clueless because this error is not something related to the programming logic neither to the server which shows this error either on accessing a servlet or a service. You have to know that this error comes when a class compiled on a newer version is being tried to run on an older JVM i.e. If you try to run a JDK 1.5 compiled class in an environment having JRE 1.4 the JRE will give you the error,

 Unsupported major.minor version 49.0

This error is given because the new features introduced in the newer version of Java are not present in the older version. So you have to be careful for using such class files on older environments. For resolving this error you have to follow some simple tips as follows:

  1. Check you java version by running the command java – version
  2. Check your environment variable JAVA_HOME and the path associated with it
  3. Check your server installation if it was installed on an older version
  4. Check which path exists in the environment entries

These are the quick tips you would need to do in order to get rid of the error. Sometimes Read the rest of this entry »

Understanding XSD Namespaces With Concepts of Java

Posted on September 19th, 2007 in Concepts, Java, XML | 7 Comments »

This article is aimed at developers who are good at programming languages like Java and want a quick jump on the XSD bandwagon by understanding some important concepts like namespaces. Hope that this article helps to make you understand namespaces quite easily.

What is a namespace?

A namespace is an identifier for elements. XML and XSD use the concept of namespaces to define a relationship between the elements and their hierarchy. It means that when their are multiple elements to be defined then it might be possible that some of the elements may tend to have the same name. But having the same name often leads to collision just as the in the case of classes with same names although in different packages but referenced by name alone in a Java program. Hence the concept of namespaces is used in order to distinguish such elements.

Why are namespaces used?

XML and XSD are never meant for human reading. You have to remember that even though XML is a data representation markup language, it would be rare that you will actually be parsing through an XML file to use the data in your application through your own code.

Such parsing is often supplied through the use of API’s like SAX, DOM, JAXB, etc. You would have till now actually used these libraries while dealing with web services since it is field which uses XML, XSD to the maximum. The concept of namespace has no relevance until and unless an XML instance is associated with an XML Schema (XSD). This is because, XSD defines what do the elements in the XML instance actually mean. A standalone XML just makes the data easier to understand to you but to an XML parser it is nothing but a set of elements in some heirarchy.

For example if suppose you have the following XML format: Read the rest of this entry »

And I thought I Knew How Java Worked!

Posted on September 3rd, 2007 in Concepts, Java | 4 Comments »

I did till today, and realized that many concepts are still unknown to me as well as some of my friends who have worked on Java EE for a long time now. I have learnt many frameworks along the course from the day I started my professional work in J2EE (now christened JEE). Java in its core form never came across me as I was eager to find out the challenges that I faced while working with JEE. It is sometimes interesting to see your much loved aspect, turning out on your face and looking like a complete stranger to you.

It was in the morning that my colleague asked me that he had taken an interview where he asked the question to the interviewee,

What is the difference between JVM and JRE?

Of course, it was Java Virtual Machine and Java Run Time Environment, I said without a second thought. But it doomed to me like never before, what next was their difference? Was it something that SUN had planned to demystify my confidence in the world of Java. Reluctantly, yet diplomatically I said to him that I knew the difference but I would like his point of opinion. He said something which I half heartedly believed, putting on a note in my mind the quest for the day to find the interesting answer to this seemingly easy but notorious question. The answer he relented was, Read the rest of this entry »

J2EE or JEE, Java 5 or Java 1.5 – Is SUN Crazy?

Posted on August 1st, 2007 in Concepts, Java, Java EE | 22 Comments »

Will they take a J2EE professional or a JEE professional now is the thing I am worrying about. It is obvious for a technical person to know that J2EE and JEE are one and the same except for the HR persons! How do we go about convincing them? Many people including me, still are confused about the version and the mysterious number attached to the “Java” word. Let’s try to explore what actually goes on behind these mysteries. Check this out!

The product confusion

If you are still thinking that Java 2 meant version 2 of Java then you are being duped. Java 2 means version 1.4 of Java. I am still dumbfounded as to where Java 3 and Java 4 disappeared but I guess with the success of Java 5 they were buried in debris even before they born!

I was still in bewilderment until the web started to roar about Java 6. It took me a lot of time to actually sink in the fact whether Java 5 referred to version 1.5 of Java and Java 6 referred to version 1.6 of Java. This confusion was due to the use of Java 5.0 in some places. Are Java 5.0 and version 1.5 of Java one and the same?

The fact is that Sun makes use of dual naming convention for the same thing. One naming convention if for the product and one is for the developer. The official documents mentions Read the rest of this entry »

Page 1 of 3123