Browsing Category: "Web Development"

Spring depth of cooperation with Google to open a new chapter in the Spring

Sunday, August 7th, 2011 | Web Development with Comments Off
Spring can be said that the recent moves frequently, first joining VMware, then M GemStone, today the depth of cooperation with Google. 51CTO will further track the progress of all of this. The following is the Spring founder Rod Johnson in his blog on Google and Spring co-related issues statement. A few weeks ago, we announced a low-key (code …

Spring can be said that the recent moves frequently, first joining VMware, then M GemStone, today the depth of cooperation with Google. 51CTO will further track the progress of all of this. The following is the Spring founder Rod Johnson in his blog on Google and Spring co-related issues statement.A few weeks ago, we announced a low-key (Editor note: do not feel low-key) SpringSource joining VMware, today, we have to announce another exciting, tremendous progress.

SaaS in the field because VMforce and the relationship between leader salesforce.com, today we announced a VMforce and between Google, on the Spring framework and SpringSource IDE and RAD tools for cooperation. Spring will be a Google application is the preferred programming model engine. This cooperation is the Spring framework in the field of lightweight programming tremendous recognition for Spring developers with better opportunities and prospects. 

In today’s Google I / O’s keynote presentation and demo applications are Google engineers SpringSource result of months of cooperation, such cooperation open to any developer that is very useful. Highlights: innovative, Spring and GWT (Google Web Toolkit) the depth of integration to build rich client applications more efficient; in the Spring application integration engine Google applications easier; Spring Insight and Google Speed Tracer integration, regardless of or from the browser to the database, enhanced application performance; on the other SpringSource Tool Suite provides an integrated development experience beautiful.

Target
Further discussion at the beginning of technical problems, I still like to emphasize objective problem. The statement highlights the core values of the two issues is the question of production efficiency and portability.

Production efficiency
Spring can be seen the long-term goal is to continue to enhance the productivity of Java. SpringSource has been strongly committed to invest in this area. Meaningful statement today, simply because the owners of two beloved SpringSource. Is the SpringSource Tool Suite and the Spring Roo, these two baby to Java developers with a good development practice, and has been appreciated by Google. STS, is provided by the Eclipse free tool, is to develop the best environment for Spring applications. We have a very ambitious goal, that is a simple download on the development of Java applications can provide all the necessary tools, and is the most appropriate tool.

Spring Roo is to help develop the efficiency of an unusual and to think of application development tools for Spring. If you are a Java developer, you may have heard or even try to use than Roo. Now quick, simple and build Java applications, the time has come. Generally speaking, Spring Roo is an interactive, code generation tools can be reviewed to ensure that programmers write only the code value, Spring Roo can be used to assist formation and maintenance, construction persistence mapping, configuration, JavaBean method toString () method and other heavy labor. Spring Roo’s role is to ensure that developers need only write the code, and by reviewing UI extensions to support early product upgrades and so on.

First, we respect the facts, 在 Spring community, many developers are hoping the benefit, but we still Jian Ding, confident that the Gong Ju Ren Wei Spring Roo Qiangyuelaiyue Zhong Yao (although Roo Mubiao yes those Java developers, Groovy platform on The Grails developers. need to highlight the Grails and Groovy community has demonstrated its technology application in the Google engine value).

Productivity in turn be enhanced and will soon be integrated. With the SpringSource / Google co-operation, you will have the opportunity to download STS, through a simple dialog box, you can create a new Spring Roo project, and by Roo interactive platform to create a complete application. Within minutes, you can create a real application (including database access), and run in the cloud. By integration in the STS in the Roo review, you can not only add new fields for the entity, you can also modify the GWT framework of the application to see Roo, through the GPE of DevMode button, just 2-3 seconds, you can switch to Browse Open View the entire device, including applications, including database changes, completely without restarting the server.

at other transplant between different servers, eliminating the EJB, JTA and other environmental impact of specific API. Today, the deployment environment of choice is extended to the traditional data center and cloud environments. Spring portability, is pushing Java developers to the cloud.
The key issue today is the Spring of portability to the correct treatment Open PaaS: As VMware CTO, Steve Herrod said, where to deploy and run your application, is a very important choice. Very pleased that VMware and Spring’s core values are the same. Also very pleased to see Google make a commitment in the portability area.
Technology Introduction
I have already mentioned the Spring Roo and the STS and other technologies . For other technologies , including GWT, SpringSource and Google analysis tools. Soon after, we are responsible for the work of engineers involved in this process more Jishu details and Roo 1.1.0.M1 and STS 2.3.3.M1 versions to publish, you can conduct a detailed study of these software. Here we only provide a summary of guidance.
GWT
Google Web Toolkit is a very powerful, used to develop rich client applications, Internet technology . HTML5 AJAX and other modern through technology such as phones and other non-traditional clients to develop compelling applications, and provide a good user experience. With the changing needs of the user interface as well as the promotion of non-traditional clients, GWT on Java developers, will become increasingly important.
Show today on Spring, Spring Roo and deep integration GWT application, SpringSource, and Google engineers are well co-months results, also have been looking forward to the Spring community to solve the problem of response. This integration allows developers to GWT applications easier than in the past, but also to the Spring developers of a new, compelling UT choice. GWT is an open source framework and deployment environment independent, so the integration of Spring to all users, regardless of whether they intend to use the Google application engine applications are useful. With the domain model knowledge, Spring Roo and GWT is a natural fit. Today, the integration of Spring Roo and GWT, as developers in the project life cycle to provide a higher productivity; and the deployment of Google applications by Roo engine easier.
We are also the expansion of STS in the Eclipse installation package adds GPE (Google Plugins for Eclipse) installation. GPE to include in the on GWT, DevMode deployment and application engine Google support.
Spring Insight / Google Speed Tracer
Spring Insight is a way for developers to write specific code and configuration without the case, we can tool for insight into other applications.
Insight famous by AspectJ and Spring framework to show application performance information, where such information includes how much time consuming. Insight is part of the server SpringSource tc (tc Server Developer Edition is a free software that is part of STS).
Google Speed Tracer Chrome extension is used to display the time consumption of the application. Including analysis and implementation of javascript, layout, CSS rendering, DOM event handling, loading and other resources.
Today we demonstrate two techniques in combination. Speed Tracer Insight users can see has been seamlessly embedded in the former Speed Tracer screen them, and show the server-side JDBC queries, etc. such as the implementation of efficiency. Speed Tracer and Insight The combination of a strong and unprecedented, this is the first time, the opportunity to see from a global perspective and background of the browser server is how to coordinate work.
What this means
From today announced VMforce announced the cooperation with Google, which occurred a few weeks in the end how much change? Deploy applications in a simple, Java developers have been no suitable target PaaS direction. This is a very dangerous blank area, is likely to affect the long-term development of Java. I am pleased to VMware / SpringSource to lead and fill the white space.
Today’s statement for the Spring developers, is a very important thing. Spring technology value reached a peak today; Spring system is still in the continually growing; Springde core values still guide its direction; and Spring has begun to lead the Java community into the cloud computing era. Whether you want to the existing computer center, private or public Java Java clouds clouds, Spring is the best development model. I am very excited and hope everyone like me excited.

Java SynDemo object to solve the problem of succession

Friday, August 5th, 2011 | Web Development with Comments Off
Java SynDemo object has just appeared in time to have a lot of programmers are headache, this is actually not necessary, and here’s the Xuexi in detail under the related issues. We found that, for the Java SynDemo objects, only synMethord1 run, while synMethord2 is not running. This is to be synchronized in the method-level statement of the l. ..

Java SynDemo object appeared just when many programmers are headache, this is actually not necessary, here we come to study in detail under the relevant issues. We found that, for the Java SynDemo objects, only synMethord1 run, while synMethord2 is not running. This is to be synchronized in the method-level statement will lock the current instance of this class object. So synMethord1 unlock before running the end of the current Java SynDemo object instance is not run synMethord2′s. This method-level synchronized statement and the following approach is equivalent to:


1.package com.cnblogs.gpcuster; / ** * * @ author Aaron.Guo * * /
2.public class SynDemo (public void synMethord1 () (
synchronized (this) (while (true) (try (Thread.sleep (1000);
System.out.println (“synMethord1″);) catch (InterruptedException
e) (/ / TODO Auto-generated catch block
3.e.printStackTrace ();
4.)
5.)
6.)
7.)
8.public void synMethord2 () (synchronized (this) (while (true)
(Try (Thread.sleep (1000); System.out.println (“synMethord2″);)
catch (InterruptedException e) (/ / TODO Auto-generated catch block
9.e.printStackTrace ();
10.)
11.)
12.)
13.)
14.)
Run the program, results and last the same.
If we wish to synchronize two methods are how to deal with? Can refer to this realization:
15.package com.cnblogs.gpcuster; / ** * * @ author Aaron.Guo * * /
16.public class SynDemo (private Object flag1 = new Object ();
private Object flag2 = new Object (); public void synMethord1 ()
(Synchronized (flag1) (while (true) (try (Thread.sleep (1000);
System.out.println (“synMethord1″);) catch (Interrupted
Exception e) (/ / TODO Auto-generated catch block
17.e.printStackTrace ();
18.)
19.)
20.)
21.)
22.public void synMethord2 () (synchronized (flag2) (while (true)
(Try (Thread.sleep (1000); System.out.println (“synMethord2″);)
catch (InterruptedException e) (/ / TODO Auto-generated catch block
23.e.printStackTrace ();
24.)
25.)
26.)
27.)
28.)
Run the program, the results as we expect:
29.main
30.synMethord2
31.synMethord2
32.main
33.synMethord1
34.main
35.synMethord1
36.synMethord2
About Synchronized There were some other topics, such as the static problem, the question of succession, and with use of so volatile, the Internet has a very detailed description will not repeat here introduced. Is on the Java SynDemo more details about the object.

Programming the difference between exceptions and errors

Friday, June 17th, 2011 | Web Development with Comments Off
Exception catch, such as try-catch blocks is a test run when we compile the compiler encounters try-catch blocks, then it will test run the next, that is, the code first checks whether the error, if error under catch to handle errors returned the wrong reasons then we can give you to determine based on erroneous, such as we see a Scanner input = new …
Abnormalities, such as try-catch blocks to capture is the test run
When we compile the compiler in the device if you encounter the words try-catch blocks will be test run Xia, also code Zhong Jiu Shi Jian Cha is the first error occurs, if there is an error on Genju catch Quchu Li error Fanhui error of the Yuan Yin Ji you and Women on to judge according to the error, such as we see a Scanner input = new Scanner (System.in);
But if there is no try-catch, then add it, the compiler will not catch the error to detect.
Such as
Scanner input = new Scanner (System.in);
int x = input.nextInt ();
This time we enter a string “I love you”
This will return an error when
If we are so
try (
int x = input.nextInt (); 
) Catch (Exception ex) (
/ / If you enter non-numerical code on the implementation of here
System.out.println (ex.getMessage); 
)

Java basic process of database operations

Monday, June 13th, 2011 | Web Development with Comments Off

 1.Java a. Database connection 1.Drivermanager link database String className, url, uid, pwd; className = \ ‘Oracle.jdbc.driver.OracleDriver \’; uid = \ ‘scott \’; pwd = \ ‘ tiger \’;…
1.Java
a. 1.Drivermanager link database database connection

String className, url, uid, pwd;

className = \ “Oracle.jdbc.driver.OracleDriver \”;

uid = \ “scott \”;

pwd = \ “tiger \”;

url = \ “jdbc: oracle: thin: @ localhost: 1521: ora92 \”;

Class.forName (classname);

Connection conn = DriverManager.getConnection (url, uid, pwd);

2.JNDI Links Database

String jndi = \ “jdbc / db \”; / / e20-040 9L0-609 data source name

/ / Context is a set of binding names to objects composed of

Hashtable env = new Hashtable ();

Context ctx = (Context) new InitialContext.lookup (\ “env \ “);// context where access to the data source object point

DataSource ds = (DataSource) ctx.lookup (jndi); / / find the data source

Connection conn = ds.getConnection ();//

b. implementation of the sql statement

String sql;

StateMent stat = conn.createStatement ();

ResultSet rs = stat.executeQuery (sql); / / implementation of the data query (select);

stat.executeUpdate (sql); / / implementation of data update statements (inset into, delete, update, drop)

stat.close ();

c. to execute sql statements with preparedStatement

String sql = \ “inset into table (id, name) values (?,?) \”;

PreparedStatement ps = conn.prepareStatement (sql);

ps.setInt (1,001);

ps.setString (2, \ “zhangmanli \”);

ps.executeQuery ();

int count = ps.executeUpdate ();

d. address the implementation of the results

Query, ResultSet object to return recordset

Update statement, return number, said the impact of the number of records updated

javax.sql .*

javax.naming .*;

Data processing:

A close connection to automatically submit

conn.setAutoCommit (false);

2 implementation of a series of sql statements

Statement sm;

sm = conn.createStatement (sql);

sm.executeUpdate ();

sm.close ();

3. Submit:

conn.commit ();

4. Rollback mechanism;

conn.rollback ();

e: Threading:

D: jndi and dataSource to get the database link:

import java.sql.ResultSet;

import java.sql .*;

import javax.sql.DataSource;

import javax.naming.Context;

import javax.naming.InitialContext;

import java.util.Hashtable;

import java.util.Properties;

import java.io. *;

public class BasicExample (

public static void main (String args []) (

Connection conn = null;

try (

Properties prop = new Properties ();

prop.load (new FileInputStream (\ “simple.properties \”));

Hashtable env = new Hashtable ();

env.put (Context.INITIAL_CONTEXT_FACTORY, prop.getProperty (\ “INITIAL_CONTEXT_FACTORY \”));

env.put (Context.PROVIDER_URL, prop.getProperty (\ “PROVIDER_URL \”));

InitialContext ctx = new InitialContext (env);

DataSource ds = (DataSource) ctx.lookup (\ “Book \”);

Conn = ds.getConnection ();

Statement stat = conn.createStatement ();;

ResultSet rs = stmt.executeQuery (sql);

while (rs.next ()) (

int id = Integer.parseInt (rs.getString (\ “userId \”));

String userName = rs.getString (\ “username \”);

)

) Catch (SQLException e) (

e.printStackTrace ();

) Finally (

try (

if (conn! = null) (

conn.close ();

)

) Catch (SQLException e) (

e.printStackTrace ();

)

)

)

);

A common operation tools on the date

Friday, June 10th, 2011 | Web Development with Comments Off

public class DateUtils (/ ** * get the current time and date string * / public static String getCurrentDateStr (DateFormatType dateFormatType) (Date date = getCurrentDat …
public class DateUtils (
/ **

* Get the current time and date string

* /

public static String getCurrentDateStr (DateFormatType dateFormatType) (

Date date = getCurrentDate ();

return (String) OpearationDate (date, dateFormatType.getValue ());

)

/ **

* Time, date format string

* /

public static String formatDate (Date date, DateFormatType dateFormatType) (

return (String) OpearationDate (date, dateFormatType.getValue ());

)

/ **

* From the string parsing into the time, date

* /

public static Date parseDate (String dateStr, DateFormatType dateFormatType) (

return (Date) OpearationDate (dateStr, dateFormatType.getValue ());

)

/ **

* Get the current system time (original format)

* /

public static Date getCurrentDate () (

Date date = new Date (System.currentTimeMillis ());

return date;

)

/ **

* Get the current date of the year, month, day, hour, minute, second

* /

public static int getCurrentTime (TimeFormatType timeFormatType) (

return getTime (getCurrentDate (), timeFormatType);

)

/ **

* Get the specified date of the year, month, day, hour, minute, second

* /

public static int getTime (Date date, TimeFormatType timeFormatType) (

try (

Calendar c = Calendar.getInstance ();

c.setTime (date);

int type = timeFormatType.getValue ();

int i = c.get (type);

return type == 2? i + 1: i;

) Catch (Exception e) (

throw new RuntimeException (“get failed”, e);

)

)

/ **

* Get the number of milliseconds specified date

* /

public static long getMillis (Date date) (

java.util.Calendar c = java.util.Calendar.getInstance ();

c.setTime (date);

return c.getTimeInMillis ();

)

/ **

* Date added together, by operation

*

* Results are returned units: days

* /

public static int operationDate (Date date, Date diffDate, DateOperationType dateOperationType) (

long add = getMillis (date) + getMillis (diffDate);

long diff = getMillis (date) – getMillis (diffDate);

return (int) ((dateOperationType.getValue ()? add: diff) / (24 * 3600 * 1000));

)

/ **

* Add date month, reducing operation

* /

public static Date operationDateOfMonth (Date date, int month, DateOperationType dateOperationType) (

Calendar c = Calendar.getInstance ();

c.setTime (date);

c.add (Calendar.MONTH, dateOperationType.getValue ()? month: month – (month * 2));

return c.getTime ();

)

/ **

* Date of days add up, by operation

* /

public static Date operationDateOfDay (Date date, int day, DateOperationType dateOperationType) (

Calendar c = Calendar.getInstance ();

c.setTime (date);

long millis = c.getTimeInMillis ();

long millisOfday = day * 24 * 3600 * 1000;

long sumMillis = dateOperationType.getValue ()? (millis + millisOfday): (millis – millisOfday);

c.setTimeInMillis (sumMillis);

return c.getTime ();
)

private static Object OpearationDate (Object object, String formatStr) (

if (object == null | | null == formatStr | | “”. equals (formatStr)) (

throw new RuntimeException (“argument can not be empty”);

)

SimpleDateFormat format = new SimpleDateFormat (formatStr);

try (

if (object instanceof Date)

return format.format (object);

else

return format.parse (object.toString ());

) Catch (Exception e) (

throw new RuntimeException (“operation failed”, e);

)

)

public enum DateOperationType (

/ **

* Add operation

* /

ADD (true),

/ **

* Reduction operation

* /

DIFF (false);

private final boolean value;

DateOperationType (boolean operation) (

this.value = operation;

)

public boolean getValue () (

return value;

)

)

public enum TimeFormatType (

YEAR (1), MONTH (2), DAY (5), HOUR (11), MINUTE (12), SECOND (13);

private final int value;

TimeFormatType (int formatStr) (

this.value = formatStr;

)

public int getValue () (

return value;

)

)

public enum DateFormatType (

/ **

* Format: yyyy-MM-dd HH: mm: ss

* /

DATE_FORMAT_STR (“yyyy-MM-dd HH: mm: ss”),

/ **

* Format: yyyyMMddHHmmss

* /

SIMPLE_DATE_TIME_FORMAT_STR (“yyyyMMddHHmmss”),

/ **

* Format: yyyy-MM-dd

* /

SIMPLE_DATE_FORMAT_STR (“yyyy-MM-dd”),

/ **

* Format: yyyy / MM / dd

* /

SIMPLE_DATE_FORMAT_VIRGULE_STR (“yyyy / MM / dd”),

/ **

* Format: HH: mm: ss

* /

HOUR_MINUTE_SECOND (“HH: mm: ss”),

/ **

* Format: HH: mm

* /

HOUR_MINUTE (“HH: mm”);

private final String value;

DateFormatType (String formatStr) (

this.value = formatStr;

)

public String getValue () (

return value;

)

)

)