Posts Tagged ‘Learn’

What’s New in the compiler of the JDK 7

Monday, September 7th, 2009

JavaLogo_060909

Darcy Joseph tells us of the developments that have the compiler in JDK 7. They are usually minor changes discussed at the forums, which include various amenities in the language syntax.

The news of the JDK 7 will be:

  • Switch to objects of type String
  • Automatic resource management
  • Improved type inference for the creation of Generics
  • Invocation of methods with varargs simplified
  • Improvements in numeric literals
  • Language Support for Collections
  • Language support for JSR 292

Let’s see in detail these features.

Switch to objects of type String

It will be possible to use the switch operator with objects of type String. This will avoid potential “if-then-else”. So this new feature would allow us to:

  String s = ...
  switch (s) {
   case "A1":
      processA1 (s);
      // And continue ...
 
    case "A2":
    case "A3":
      processA2A3 (s);
      break;
 
    case "A4"
       processA4 (s);
      // And continue ...
 
    default:
      processDefault (s);
      break;
  }

Automatic resource management

A “resource” is an object that must be closed manually, such as java.io.InputStream, OutputStream, Reader, Writer, Formatter;
java.nio.Channel; java.net.Socket; java.sql.Connection, Statement, ResultSet among others. These resources are usually open in a try block and close in a finally.

Recursos automatic management is a special form of the operator where you try one or more state resources. The scope of these resources is limited to the block. When the block ends, either normally or abruptly, all declared resources are automatically closed.

The main advantage is that it eliminates the need for manual closing, and it causes errors. Furthermore, it “prevents” the second exception (the close ()), always leaving the exception of the block that is usually more interesting.

An example usage would be:

 static String readFirstLineFromFile(String path) throws IOException {
 
        try (BufferedReader br = new BufferedReader(new FileReader(path)) {
 
           return br.readLine();
 
        }
 }

As we see, the try block () declares a resource, is then used within the block. When finished, it closes automatically. It is also possible to declare more than one resource:

try (InputStream in = new FileInputStream(src);
     OutputStream out = new FileOutputStream(destination)) {
 
            byte[] buf = new byte[8192];
            int n;
            while ((n = in.read(buf)) >= 0)
                out.write(buf, 0, n);
}

Improved type inference for the creation of Generics

This also includes the possibility to infer the types for instantiation using Generics. In cases parameterized types are obvious from the context, this parameter in the constructor can be omitted and replaced with an empty set <>.

For example, the following line:

 Map<String, List<String>> testmap = new HashMap<String, List<String>>();

can be replaced by:

Map<String, List<String> testmap = new HashMap<>();

Improvements in numeric literals

Just as we can declare decimal numeric literals, octal and hexadecimal literals now we can declare binary. This is very useful in certain areas. For this, use the prefix 0b, which is also the same compilers that use C / C + +, Ruby and Python. For example:

// A literal 'byte' 8-bit
byte wcByte = (byte)0b00100101;
 
// A literal 'short' 16-bit
short wcShort = (short)0b1010000101010101;
 
//  More literal 'int' of 32-bit 'int'
int wcInt1 = 0b10100001010001011010000101000101;
int wcInt2 = 0b101;

These variables are then used normally, for example:

class A2 {
public static void main(String[] args) {
    System.out.println("The decimal value of 10100101 is " + 0b10100101);
}

On the other hand, added the possibility to use an underscore (_) separator of numbers, to facilitate the reading of them. Thus, the compiler will ignore the character “_” when used in numeric literals. For example:

int numberOfTelephone = 757_757_7575;
long CreditCard = 1234_5678_9123_4567L;
long bundle = 777_77_7575L;
float money = 12_345_132.75;
long hexBytes = 0xFF_EC_AE_5E;
long hexWords = 0xFFEC_AE5E;
long maxLong = 0x7fff_ffff_ffff_ffffL;
long bytes = 0b11010010_01101001_10010101_10010010;

Language Support for Collections

It adds language support to treat like Arrays Collection.

For example, you can write the following to declare an immutable List:

final List wcDigits = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9];

It will also be possible to access lists and maps using array syntax:

public class Main {
  public static void main(String[] arguments) {
    List wcArrayList = Arrays.asList(new String[] {"a","b","c"});
    String fristElement = wcArrayList[0]
 
    Map testmap = new HashMap(4);
    testmap[Integer.valueOf(1)] = "One";
}

Language support for JSR 292

This low-level change made minor changes to the Java language to be simpler to work with some features of the JVM. This will allow Java code to interoperate and / or implement libraries in other languages. That is, will ensure greater integration between Java and code in other languages. For more information read the proposal of support for JSR 292.

5 ways to use Ajax with jQuery

Tuesday, August 25th, 2009

The people of Nettuts publishes an interesting article on using  jQuery with Ajax. Specifically the 5 ways that jQuery allows us to send asynchronous requests.

  • $.load()
  • $.get()
  • $.post()
  • $.getJSON()
  • $.getScript()

$. load ()

This is the feature I like most about jQuery already makes one of the most common tasks of developing with Ajax is as simple and straightforward as we shall see in this example:

$("#div_links").load("/Main_Page #jq-p-Getting-Started li");

This example brought to the documentation page on jQuery, it manages to launch a request to the URL /Main_Page (usa URL Rewrite) HTML response and take the #jq-p-Getting-Started li and inserted into #div_links
Just great, comfortable and fast.

$. get ()

This is the simple function with which we can launch the server via GET requests Ajax.

$.get("test.cgi", { name: "Venu", time: "7pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

By passing 3 options, 2 of which are options (rather conditional) you can request to launch the file (1) with parameters (2) and treat the response through a callback (3rd).

$. post ()

Like the above, this feature lets you send POST requests using Ajax.

$.post("test.php", { name: "Venu", time: "7pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

As easy as above.

$. getJSON ()

Although the above are able to specify the type of return, the best option is to use this method to obtain the response in JSON evaludada the callback function.

$.getJSON("test.js", { name: "Venu", time: "7pm" }, function(json){
  alert("JSON Data: " + json.users[3].name);
});

Taking into account the browser, the object will use native JSON or use a system based on eval().

$. getScript ()

Although technically not an Ajax request is a request to the server and therefore has a place in the post.

$.getScript("test.js", function(){
  alert("Script loaded and executed.");
});

With this method we can load a file asynchronously using JavaScript and the parameter (2) callback can execute Javascript code that is using the js file that we want to load (1).

Everything you ever wanted to know about JSON

Monday, August 24th, 2009

JSON is short for JavaScript Object Notation and is a way of storing information in an organized and easily accessible.

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
};

At first glance you get a very clear and that helps your understanding. In this example we have defined a small JSON object called wcVenuThomas composed of a series of attributes. In this way, we can subsequently use to follow the following structure.

alert("Venu Thomas is " + wcVenuThomas.age );

Functions (not to carry information)

Thanks to the versatility of the variables in JavaScript it is possible to match one of these attributes to a function, creating a method of the object itself:

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
    "salute" : function(strString) {
    	alert("hello, " + strString + "! I'm Venu Thomas from " + this.hometown + ", How are you?");
    },
};

Now you can salute() :-D

 var usrName = "John James"
wcVenuThomas.salute(usrName);

As part of the JSON object, we can make use of the attributes from the same method by using this operator.

The functions do not make sense to use JSON as a conveyor of information, so we leave it alone as a curious object notation :-D

Arrays

Another option to the JSON is the ability to insert arrays as attributes and in turn define elements within JSON:

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
    "salute" : function(strString) {
    	alert("hello I'm Venu Thomas from " + this.hometown + ", How are you? " + strString + "?");
    },
    "projects":[
    	{
    		"name" : 	"Apple News and Analytics ",
    		"url"		 : 	"http://apple.wisecodes.com"
    	},
    	{
    		"name" :	"Life Style Blog",
    		"url"		 :  "http://telegraph.wisecodes.com"
    	}
    ]
};

In this way we can travel an arrays are:

var projects = wcVenuThomas.projects, html = '';
for (var x = 0 ; x < projects.length ; x++) {
html += '<li><a href="' + projects[x].url + '">' + projects[x].name + '</a></li>';
}

JSON object chaining

Another way of grouping elements is to use JSON JSON objects embedded within other objects JSON:

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
    "salute" : function(strString) {
    	alert("hello I'm Venu Thomas from " + this.hometown + ", How are you? " + strString + "?");
    },
    "projects":{
    	"applenews": {
    		"url"		 : 	"http://apple.wisecodes.com"
},
  	  "lifestyleblog": {
    		"url"		 :  "http://telegraph.wisecodes.com"
}
    }
};

As we can see, really the only thing we have done is to insert an object into a JSON attribute father, so we can access it as follows:

var URL = wcVenuThomas.projects.applenews.url;

Practical uses

As data storage system, is ideal for transporting from one page to another, even a website to another. A very simple and is used to obtain data from Flickr using jQuery to get data.

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
        function(data){
          $.each(data.items, function(i,item){
            $("<img/>").attr("src", item.media.m).appendTo("#images");
            if ( i == 3 ) return false;
          });
        });

In this example, taken from the documentation of jQuery, as we launched a call for the latest images sent to Flickr that have been scheduled with the tag “Cat”. The result will be evaluated and processed to the end to reach us within data, a variable that can go as if we were talking about a variable.

Native JSON

One of the problems encountered with JSON is the assessment of code, since it must be transformed into a variable to use, and this requires the use of eval() which makes the process time is increased considerably .

// Eval
var myObject = eval('(' + myJSONtext + ')');

// Native JSON
var myObject = JSON.parse(myJSONtext);

// Mix
var myObject = (JSON)?JSON.parse(myJSONtext): eval('(' + myJSONtext + ')');

Fortunately, modern browsers (IE8, FF3.5, WebKit, ….) Features are implemented to forget eval() and improve the process time.

What we can do ajax

Tuesday, July 14th, 2009

* Modifications to the browser, adding buttons, toolbars, bookmarks, icons, ….
* Access to local files
* Running music files or apply effects
* HotKeys gives conflicts in other browsers
* Access Hardware
* Comnicaciones extended HTTP and other protocols.
* Interaction with the Operating System

Anyway time to time 

What is HTML5

Wednesday, June 3rd, 2009

HTML 5 (Hyper Text M Language Version 5) is the fifth largest in the revision of basic language World Wide Web, HTML. HTML 5 specifies two variants of the same language: a ‘classic’ HTML text/html the variant known as HTML 5 and a variant XHTML called XHTML 5. This is the first time in HTML and XHTML have been developed in parallel.
The development of this code is governed by the Consortium W3C.

New Elements

HTML 5 provides a number of new elements and attributes that reflect the typical use of modern web sites. Some of them are technically similar to the labels
<div> and <span> but have a semantic meaning, eg <mav> (block site navigation) and <footer> Other elements provide new functionality through an interface such as elements <audio> and <video>
Some elements of HTML 4.01 are obsolete, including purely presentation as <font> and <center> whose effects are handled by the CSS. There is also a renewed emphasis on the importance of scripting DOM for behavior on the web.

HTML 4

html4

HTML 5

html5

External Link: via W3C

An Introduction to Adobe Flex

Wednesday, May 20th, 2009

Adobe Flex (Macromedia Flex) is a term that covers a range of technologies published since March 2004 by Macromedia to support the development and deployment of rich Internet applications based on its proprietary platform Flash.
The traditional application developers see it as a challenge to adapt the metaphor of animation on the platform which was originally built Flash. Flex elegantly minimizes this problem by providing a workflow and programming model that is familiar to application developers.

Flex was initially released as an implementation of J2EE or library label JSP to compile the Flex markup language (MXML) and run through ActionScript Flash applications (binary SWF files). Later versions of Flex support the creation of files that are compiled, and can be distributed online without the need for a server license.

The purpose of Flex is to allow developers to build Web applications quickly and easily Rich Internet Applications, also called RIAs. In a multi-layer, Flex applications are the level of presentation.

Flex emphasizes the development of graphical user interfaces using an XML language called MXML. Flex has several components that provide functionality and features such as Web services, remote objects, drag and drop, ordered columns, graphics, animation effects and simple interactions. The client only loads the application once, thereby improving the flow of data from applications based on HTML (eg. PHP, ASP, JSP, CFMX) which require executing templates on the server for each action. The language and structure of files looking for Flex decoupling of the logic and design.

The Flex server also acts as a gateway allowing the client to communicate with web services XML and remote objects (such as Coldfusion CFCs, Java classes, and anyone who supports the Action Message Format).

Alternatives to Flex are Google Web Toolkit, data centers, OpenLaszlo and Silverlight from Microsoft.

For those working with opensource software adobe also available on this site http://opensource.adobe.com/ where the Flex SDK and includes projects by developers.

Directory structure of a project in Flex Builder.
When creating a project in Flex Builder automatically creates a directory structure

This application consists of an application directory that contains different types of files required to compile and run the application, these are:

introtoflex01
. Settings: Contains settings for the flex builder
bin-debug: debug contains the swf and the files needed for debugging
html-template contains the files to be used specifically for detecting the player
src: the sources of the mxml files
libs: Library to implement the desired application. 

Link: Via Officical Site , OpenSource (Via Adobe) , LiveDoc (Via Adobe), Flex Components (Via Flex.org), Adobe Flex Help (Via Adobe), 36 Cool Flex Tools (Via Seantheflexguy), Flex Developer Center (Via Adobe),

What is RSS?

Tuesday, May 12th, 2009

The RSS is an XML data set from which we can report the news and content to a web users who have subscribed.

Of course the best way to stay informed about updates to our favorite websites. And as an image, in this case a video is worth a thousand words we rolled over and leave you this video that explains clearly what the RSS.

Intro to Transact-SQL (T-SQL)

Thursday, April 30th, 2009

Transact-SQL (T-SQL) is an extension of the SQL standards by Sybase and Microsoft and includes error handling, row processing and variable declaration.

Usage:
You can programs (stored procedures) on the database server and thus extend the database functionality, each user of the database can call up these programs and use. The permissions may be established for each Transact-SQL procedure to an individual user basis.

External links:

  1. Transact-SQL Reference by Microsoft for MS-SQL 2008
  2. Transact-SQL Reference for Sybase Adaptive Server Enterprise 12.5.1
  3. T-SQL Factsheet for developers as PDF

Visual Studio 2008 Shortcuts

Wednesday, April 15th, 2009

I was asked today about shortcuts in Visual Studio 2008 and have recovered a “old” document listing the essential mouse critics (myself included).

Here I leave the link on the Microsoft page. Click here to Download

visual-studio-2008-shortcuts

Linking remote servers in SQL Server

Monday, April 13th, 2009

To the point:

See the linked servers that have:

exec sp_linkedservers

Add a new remote server to your links:

EXEC sp_addlinkedserver
@ server = 'server'
@ srvproduct ='product_name'
@ provider = 'provider_name'
@ datasrc = 'data_source'

Add credentials to access a remote server:

EXEC sp_addlinkedsrvlogin 'RemoteServerName', 'false', NULL, 'username', 'password'

And Hale, to throw the linked server.

More info on MSDN, here and here.

Happy Programming!!