Thursday 27 August 2015

Reduce Compilation time for GWT 2.5

A ‘normal’ build is one where you get 6 basic permutations, one for each category of browser. These have been selected by the GWT team as related enough to always treat as the same.
These browsers are:

·         Firefox, all versions
·         All Webkit browsers (Safari, Chrome, Android Browser, etc)
·         IE6 and IE7
·         IE8
·         IE9 (and IE10)
·         Opera9

It is possible to collapse all properties to decrease the amount of time spend compiling a module for testing/development purposes by adding the following:

<collapse-all-properties />

Which result in taking less time for compilation , no matter how many permutations you had configured before this line, only one file will be created. This is especially handy for very fast builds or cases where you want to keep the build size small but still it will works for all the browser which we have configured.


Monday 20 April 2015

Classic Dev Mode(GWT) Will not support in Latest Chrome Browser

As per the GWT Announcements (Release note 2.6),
  •  GWT Development Mode will no longer be available for Chrome sometime in 2014, so we improved alternate ways of debugging. There are improvements to Super Dev Mode, asserts, console logging, and error messages.
  • So Lunching the Application in Chrome Newer Version with Classic Dev Mode is Disabled, because they have disabled NPAPI Plug-in in Chrome Newer Version. Now it’s time to use Super Dev Mode.
SuperDev mode as default in GWT 2.7:

The Main feature in GWT 2.7 is SuperDev mode(SDM), with Dev mode now deprecated. You use the browser’s built in debugger and don’t need to use any browser plugins. With SDM, all of your debugging happens right inside your browser, making it easier to debug mixed Java/Javascript code. If you are familiar with Super Dev Mode in 2.6, you will also notice that you no longer need any bookmarklets to enable/recompile when using Super Dev Mode, the code is recompiled automatically when you reload the page.


Other Workaround to Launch the Apps in Chrome Newer Version With Classic Dev Mode is to Enable NPAPI Flag, Follow the Below Steps
 
1.Open New Tab and Enter chrome://flags/#enable-npapi
 
2.Enable this Enable NPAPI Mac, Windows
 
3.Then bottom of the page click "Relunch" button.
 
**NPAPI  is scheduled to be removed from Chrome(version 45) in September 2015 and this workaround will be supported up to chrome 44 version only.

Saturday 18 April 2015

Interface Versus Abstract Classes

Difference Between Interface and Abstract Class:
Interface
Abstract Class
1.       If we don’t know anything about implementation just we have requirement specification, then we can use Interface
If we know partial Implementation(not full) then we can use Abstract Class.
2.       Every Method in interface is public abstract, that why interface is Pure abstract class (100%).
In addition to the abstract method Abstract class can also have Non abstract Method(concrete method).
3.       Methods in interface are public and abstract modifiers we can’t use private,protected,final,static,synchronized,native and strictfp modifiers.
There is no restriction for Methods modifiers in  Abstract class.
4.       By Implicitly, variable in interface will be public static final.
In abstract class the variable can be of any data types.
5.       Since variables in interface is public static final we can’t use as private or protected ,transient or volatile modifiers.
There is no restriction for Variable in Abstract class
6.       We should assign the value to variable at the time of declaration otherwise compiler will give error. public static final int x=3;
There is no such restriction in Abstract class.
7.       We can’t declare any instance or static method inside the interface.
Can have instance or static method inside the abstract class.
8.       We can’t have constructor inside the interface, since the variable is static
We can have constructor inside the Abstract class.
9.       Interface can extend more than one interface, Interface C extends A,B
Abstract class can extend class or Abstract class
10.   Interface Car{
public static final int x=10;
public int speed();
}
abstract class Engine{                                                                    public abstract void engineType(String carType);
 public String engineColor(){          return "red";                                           }



Tuesday 24 March 2015

Custom Widget in GWT

GWT Provides ways to create Custom User Interface.They are 3 ways to Create Custom Widgets which are listed below.

  1. By Extending Composite Class
  2. Wrap JavaScript inside Widget using JSNI
  3. Creating Widget from Scratch Using GWT DOM API.

By Extending Composite Class:
               The most effective way of creating custom widget is by extending composite class.Create a class which extend composite class and pass the constructed widget inside the initWidget() Method. 
For Example:
 Creating a TextField component like TextBox with Label

 public class TextField extends Composite{
     public TextField(){

       HorizontalPanel panel=new HorizontalPanel(); // to Create HorizontalPanel

        Label lbl=new Label();    //to Create Label
        lbl.setText("NAME");     

       TextBox box=new TextBox();  //to Create TextBox

        panel.add(lbl);     //Add label into HorizontalPanel
        panel.add(box);    //Add textbox into HorizontalPanel

        initWidget(panel);      //Pass the HorizontalPanel into initWidget of Composite Class

}
}
Which gives the Custom Widget see the Screen Shot
Custom Widget:TextField Component



Wrapping JavaScript into Widget Using JSNI:
This is the one more approach to create custom widget, Use JavaScript and Wrapped inside into GWT Component using Java Script Native Interface(JSNI).
Syntax for JSNI:
public static native void customWidget()/*-{
           //JavaScript Code
  }-*/; 

Creating Widget from Scratch Using GWT DOM API:
This is the third approach to create custom widget , using Java code from Scratch it is some what trickier since it has be created from lower level.Many of the GWT Basic widgets are written by using  this approach like TextBox,Button.

Finally,Its recommanded and most effective way to create custom widget is by extending Composite Class.









Monday 23 March 2015

String in Java

  • Sequence of character is Called a String
    • Example:  "abc","xyz","pqr$","4lkm"
  • Strings are immutable (non mutable) meaning once the string object is created can't change the value of string object.
  • They are two ways to create string object
    • by declaring a variable (using assignment operator)
      • Example: String s="abc";
    • by creating a instance of a class
      • Example: String s=new String("pqr");
  • The Difference between the creating of string object using assignment and creating instance is that in First case"Memory" will be allotted in Free pool of Memory (Method Area) and in the second case"Memory" will be alloted in Heap Memory.
  • If string object is created using assignment operator which contain the same value as other like


String s1="abc";
String s2="abc";












See in the above example,String s1 is created which contains the value "abc" again String s2 which contain the same value "abc" will point to the same memory address.In these case the memory addresses of this content will be equal (s1==s2) true.
  • If the String object is created using new instance then what ever it may be case it will create a new object like 
String s3=new String("abc");
  • then it will create new instance of  object in heap memory.
  • Finally if lot of manipulation in string is required then its not recommended to use string, In this case need to use StringBuffer.

Tuesday 10 March 2015

GWT 2.7 Features

GWT 2.7 Include following feature which are listed Below,

SuperDev mode as default
The Main feature in GWT 2.7 is SuperDev mode(SDM), with Dev mode now deprecated. You use the browser’s built in debugger and don’t need to use any browser plugins. With SDM, all of your debugging happens right inside your browser, making it easier to debug mixed Java/Javascript code. If you are familiar with Super Dev Mode in 2.6, you will also notice that you no longer need any bookmarklets to enable/recompile when using Super Dev Mode, the code is recompiled automatically when you reload the page.

Incremental compilation
If you have a large GWT project, you will instantly notice the incremental compilation feature of GWT 2.7. No longer will Super Dev Mode recompile your full project but instead only recompile the changed parts. The speedup in development is significant.

Easier Javascript integration
The new annotation based JsInterop allows you to quickly and easily integrate your GWT classes with Javascript. Instead of writing JSNI methods/JSO classes, you can simply annotate (@JSType, @JSProperty) which Javascript should be mapped to your Java file.
An example of JSInterop , by reducing the amount of code from
class Window extends JavaScriptObject {
  public native void alert(String msg)/-*{
    this.alert(msg);
  }-*/;
  public native boolean void confirm(String msg)/-*{
    this.confirm(msg);
  }-*/;
  public native boolean addEventListener(String event, EventListener listener)/-*{
    var callback = function(evt) {
    listener.@com.google.gwt.user.client.EventListener::onBrowserEvent(*)(evt);
    };
    this.addEventListener(event, callback);
  }-*/;
}
to just this
@JsInteface
interface Window {
  void alert(String msg);
  boolean confirm(String msg);
  void addEventListener(String event, EventListener listener);
}
Do note that JsInterop is still experimental in GWT 2.7 and will likely change in the future. You will need to add an X flag to the compiler to enable it in GWT 2.7

New GSS resources
CssResource is using Flute to parse the CSS, but it only supports CSS2 and a couple of features added for Gwt. With GssResource, GWT comes to a new era, not only supporting modern CSS syntax but also the Closure Stylesheets semantics. Now it will be even easier to write CSS since the closure processor adds variables, functions, conditionals, mixins and much more to the standard CSS3.
@def PADDING_RIGHT 50px;
@def PADDING_LEFT 50px;

@defmixin size(WIDTH, HEIGHT) {
  width: WIDTH;
  height: HEIGHT;
}

.class-name {
    @mixin size(add(PADDING_RIGHT, 150px, PADDING_LEFT), 50px);
    padding-right: PADDING_RIGHT;
}
Both CssResources and GssResources will live together in 2.7.0 for backward compatibility, but the old one will be removed in a future release.

For more Information see the Release note www.gwtproject.org

Friday 30 January 2015

JDBC Connection using postgresql Driver Example Code

Folks,
Below is the Example code for JDBC Connection Using postgresql Driver.

import java.sql.*;

public class JdbcPostgreConnection {

public static void main( String args[]) throws SQLException {

Connection con = null ;
try {

    // Load the Driver class.
    Class.forName("org.postgresql.Driver");  //Step 1
    // If you are using any other database then load the right driver here.

    //Create the connection using the static getConnection method
    con = DriverManager.getConnection ("jdbc:postgresql://localhost:5432/dbName","username","password");//Step 2

    //Create a Statement class to execute the SQL statement
    Statement stmt = con.createStatement();//Step 3

    //Execute the SQL statement and get the results in a Resultset
    ResultSet rs = stmt.executeQuery("select * from dbName.user");//Step 4

    // Iterate through the ResultSet, displaying two values
    // for each row using the getString method

    while (rs.next())
        System.out.println("Name= " + rs.getString("user_name") + " Date= " + rs.getString("user_password"));
}
catch (SQLException e) {
    e.printStackTrace();
}
catch (Exception e) {
    e.printStackTrace();
}
finally {
    // Close the connection
    con.close();//Step 5
}
}
}

CSS Selectors

  CSS Selectors In CSS, selectors are patterns used to select the element(s) you want to style There are 3 different types of CSS selectors ...