Thursday, December 11, 2014

No source code is available for type *Class*: did you forget to inherit a required module?

If you found the above titled error in your IDE, probably you are facing the most common error for every GWT beginner. The fact is that,  in GWT you are limited to use only some of the Java classes from whole Java API. You cannot simply use all the available classes in Java with GWT. 

Keeping in mind the fact that GWT compiles Java code to JavaScript  there are multiple reasons and limitations from JavaScript side to limit most of the Java features. So GWT is very choosy with Java API classes and you have to use those classes only.

With GWT it is not possible to convert all the Java classes to JavaScript because there are some functional differences with Java and JavaScript. It is not quite possible to achieve all the functional benefits of Java to JavaScript.

For instance, let see two functional differences, why it is not possible to use those Java classes in Javascript.

Instance 1 :

You cannot use/do IO operations in Javascript since HTML and Javascript cannot have access to file system. That's the reason GWT restrict io classes of Java to use.

Instance 2 : java.lang.Thread

You cannot use/do multi threading in Javascript since it is single thread model. That's the reason GWT restrict Thread related classes to use.

Like above instances, there are other instances to restrict the usage of many classes from Java. Again coming to the solution part, we can't do anything about the restriction and we have to stick to the available classes. You need not to remember all those classes list. Below is the complete list of subset that GWT can emulate.

Below are the packages support in GWT from JRE.


Even from the above packages you cannot use all the classes. Just go through the below link for complete list of classes GWT support from Java library.

When you stumble with the titled error just go through this list and check that you are using the white listed Java classes in GWT or not. If you are not using some other class/classes which are not white listed, you'll end up with the exception/error

Recent post : Why GWT loads slow and tips to load GWT app faster

Sunday, December 7, 2014

10 websites that help Java developers daily.

Though there are hell number of web sites on Internet, when it really need we end up with few sites that really helps. In my experience I found the below websites cracked my problems really quick and I use them regular to solve my problems. On top of learning from book and reading official documentation, I found below sites are very handy in my daily job.

When ever I feel like something crazy going on or whenever I have a question like "why this happening like this", immediately go to the language specification and refer the topic for clarity before jumping into Google. 

Writing code doesn't make you a programmer. Writing good code do that. When ever I start writing code on a new topic, the first thing I do is to go for this site and search for that practice to know what to do and what not to do. Since object oriented programming is easy to use, we easily do mistakes. This site helps you to learn good practises.

Stackoverflow site is a part of  world's largest Q&A site Stackexachange. I use  almost everyday to ask/answer questions there. It not only solves your problem but it explore the problems that fellow programmers facing. The place for Java developers to gather on stackoverlow ocean is Java tagged questions

(My profile on stack, if you want to visit)

Another website in Stackexachange network, which is useful for code review. When you have no seniors around to review your code or if you want an expert suggestions on code blocks you wrote, go ahead and post it here. I'm sure that you get your answer and suggestions in minutes form experts.

When ever I didn't find an answer in stackoverflow, the immediate option is that Java ranch which is quite informative and straight to the point. Since theoretical questions are little off topic in stackverlow, people found javaranch is a perfect site to get the answer they are looking for. It doesn't mean that this site don't have coding related questions.

If you are not updating with time we are no more in this field. When I'm free, I just go through this site and I browse the newly emerging techniques, frameworks and articles written by experts related to Java. Good part is that, you can share your own blogpost's there to the world.

It's almost a Google search for Java classes. If you have a class name and you don't have the Jar related to it, just open this site and paste your class name. Hold it tight for 2 sec, you got the all the Jar's related to that class. Just choose your jar and proceed. This is very useful when dependent jars are missing and you are facing ClassNotFoundException.

Best site to see source code from a .class file. This is actually a Java decompiler project. This project have plugins for almost all popular IDE's and the reason for mentioning here is, it have a on-line decompiler. You just drag and drop your class file and see the source code immediately.

This is another site I use very frequently to show some running code online or to show some compiling errors to other persons. It is not possible to tell some problems without proof. I just copy paste my code there and run it. It even generate a link for you to use in future. Most beautiful thing  here is you can select JDK version. When you want to execute some piece of code in some other JDK which you are not using currently, this site is gold for you.

Another better site to resolve your daily coding problems. There are 2 parts in this site basically. First thing is that the wide range range of it's tutorials and articles on different Java frameworks. Second is it's solutions for the exceptions and errors a Java developer facing. Though it is providing good and quick solutions, I don't like those solutions without proper explanations. 

As @JavinPaul  pointed out in the comments, official forum for Java by Oracle

Though I rarely use it , this is the official forum for Java where you can share your technical problems either by question or answering and can participate in discussions.

Sunday, November 23, 2014

String comparison in Java. == vs equals method.

Just not to make everything Object oriented, primitives has been retained in Java. To resolve performance issues and to keep it as simple as it is, primitives has been introduced in most using OOP language till date. Lets just not discuss all the primitive concepts and sticking to the heading of this articles lets discuss about our favourite and peculiar Object, STRING.

Thursday, November 20, 2014

Identifiers and limit on Identifier length in Java (maximum length of Class,interface, package, method, variable names).

Fun time.

Though it is not a big thing to consider, yet out of curiosity one can interested to know about the limit on Class names, Interface names, Package names, Variables names, Method names etc.

Before going to start with that let me introduce the term identifier . What is it? The above all names so far we mentioned (Class, Interface, Package, Method, Variable names) are identifiers. Do not confuse with the terms literal and identifier and literal. Definition given by Oracle for Identifier is

Wednesday, November 5, 2014

Why GWT loads slow and tips to load GWT app faster.

Why GWT loads very slow for first time:

GWT uses perfect caching technique. The initial loading time is really depends on many factors.

When user/browser requests for the very first time, all the resources related to the page loads. That takes few seconds to load and really depends on your internet speed. Once the complete page loaded and if you are requesting new page/ reloading the current page, all the resources won't load this time.