Insertion Sort Algorithm in Java language

Tuesday, August 9th, 2011 | Web Development with Comments Off
 public class CharuSort (public static void main (String [] args) (int [] sort = (4,6,3,9,5); Sort (sort); for (int i = 0; isort.length ; i + +) System.out.pri …

public class CharuSort (public static void main (String [] args) (
int [] sort = (4,6,3,9,5);
Sort (sort);
for (int i = 0; i
System.out.print (sort [i] + “”);
)

public static void Sort (int [] sort) (
int i; / / to scan times
int j; / / get elements as compared
for (i = 1; i
int temp; / / temp used for temporary data
temp = sort [i];
j = i-1;
while (j> = 0 & & temp
sort [j +1] = sort [j]; / / put all the elements of a position pushed back
j -;
)
sort [j +1] = temp; / / smallest element into the first position
)
)
)

DBSCAN Algorithm Java Implementation

Monday, August 8th, 2011 | Web Development with Comments Off
DBSCAN is a density-based clustering algorithm, and its basic principle is to a given two parameters, ξ and minp, where ξ can be interpreted as the radius, the algorithm will search within a radius of the sample, minp is a ξ To find the radius of the sample number n of constraints, as long as n> = minp, find the sample point is the core of the sample points, the proposed algorithm are described in References 1, below is a java implementation of this algorithm: …
DBSCAN is a density-based clustering algorithm, and its basic principle is given two parameters, ξ and minp, where ξ can be interpreted as the radius, the algorithm will find the sample in this radius, minp is a search radius ξ n number of samples to restrictions, as long as n> = minp, find the sample point is the core of the sample points, the proposed algorithm are described in References 1, below is a java implementation of this algorithm:
First define a Point class, the representative sample points

package com.sunzhenxing;
public class Point (
private int x;
private int y;
private boolean isKey;
private boolean isClassed;
public boolean isKey () (
return isKey;
)
public void setKey (boolean isKey) (
this.isKey = isKey;
this.isClassed = true;
)
public boolean isClassed () (
return isClassed;
)
public void setClassed (boolean isClassed) (
this.isClassed = isClassed;
)
public int getX () (
return x;
)
public void setX (int x) (
this.x = x;
)
public int getY () (
return y;
)
public void setY (int y) (
this.y = y;
)
public Point () (
x = 0;
y = 0;
)
public Point (int x, int y) (
this.x = x;
this.y = y;
)
public Point (String str) (
String [] p = str.split (“,”);
this.x = Integer.parseInt (p [0]);
this.y = Integer.parseInt (p [1]);
)
public String print () (
return “<” + this.x +”,”+ this.y +”>”;
)
)
And then define a utility class, for the algorithm implementation services:
package com.sunzhenxing;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util .*;
public class Utility (
/ **
* Test the distance between the two points
* @ Param p point
* @ Param q point
* @ Return returns the distance between two points
* /
public static double getDistance (Point p, Point q) (
int dx = p.getX ()-q.getX ();
int dy = p.getY ()-q.getY ();
double distance = Math.sqrt (dx * dx + dy * dy);
return distance;
) / **
* Check the given point is not the central point
* @ Param lst The list storage point
* @ Param p the point to be tested
* @ Param ee radius
* @ Param minp density threshold
* @ Return a temporary storage point visited
* /
public static List isKeyPoint (List lst, Point p, int e, int minp) (
int count = 0;
List tmpLst = new ArrayList ();
for (Iterator it = lst.iterator (); it.hasNext ();){
Point q = it.next ();
if (getDistance (p, q) <= e) (
+ + Count;
if (! tmpLst.contains (q)) (
tmpLst.add (q);
)
)
)
if (count> = minp) (
p.setKey (true);
return tmpLst;
)
return null;
)
public static void setListClassed (List lst) (
for (Iterator it = lst.iterator (); it.hasNext ();){
Point p = it.next ();
if (! p.isClassed ()) (
p.setClassed (true);
)
)
)
/ **
Merge
* @ Param a
* @ Param b
* @ Return a
* /
public static boolean mergeList (List a, List b) (
boolean merge = false;
for (int index = 0; index
if (a.contains (b.get (index))) (
merge = true;
break;
)
)
if (merge) (
for (int index = 0; index
if (! a.contains (b.get (index))) (
a.add (b.get (index));
)
)
)
return merge;
)
/ **
* Back to the collection point in the text
* @ Return back to the mid-point of the set text
* @ Throws IOException
* /
public static List getPointsList () throws IOException (
List lst = new ArrayList ();
String txtPath = “src \ \ com \ \ sunzhenxing \ \ points.txt”;
BufferedReader br = new BufferedReader (new FileReader (txtPath));
String str = “”;
while ((str = br.readLine ())!= null & & str !=”"){
lst.add (new Point (str));
)
br.close ();
return lst;
)
)
Finally, in the main program to implement algorithm, as follows:
package com.sunzhenxing;
import java.io. *;
import java.util .*;
public class Dbscan (
private static List pointsList = new ArrayList ();// store the set of all points
private static List > resultList = new ArrayList >();// storage DBSCAN algorithm to return the result set
private static int e = 2; / / e radius
private static int minp = 3; / / density threshold
/ **
* Extract all the points in the text and stored in the pointsList
* @ Throws IOException
* /
private static void display () (
int index = 1;
for (Iterator > it = resultList.iterator (); it.hasNext ();){
List lst = it.next ();
if (lst.isEmpty ()) (
continue;
) System.out.println (“—– s “+ index +” a cluster —–”);
for (Iterator it1 = lst.iterator (); it1.hasNext ();){
Point p = it1.next ();
System.out.println (p.print ());
)
index + +;
)
)
/ / Find all the cluster can be directly
private static void applyDbscan () (
try (
pointsList = Utility.getPointsList ();
for (Iterator it = pointsList.iterator (); it.hasNext ();){
Point p = it.next ();
if (! p.isClassed ()) (
List tmpLst = new ArrayList ();
if ((tmpLst = Utility.isKeyPoint (pointsList, p, e, minp))! = null) (
/ / End point for all clustering to mark
Utility.setListClassed (tmpLst);
resultList.add (tmpLst);
)
)
)
) Catch (IOException e) (
/ / TODO Auto-generated catch block
e.printStackTrace ();
)
)
/ / Direct access to the clustering of all the merger, that is up to the point and find the indirect merger
private static List > getResult () (
applyDbscan ();// find all the direct clustering
int length = resultList.size ();
for (int i = 0; i
for (int j = i +1; j
if (Utility.mergeList (resultList.get (i), resultList.get (j))) (
resultList.get (j). clear ();
)
)
)
return resultList;
)
/ **
* Program main function
* @ Param args
* /
public static void main (String [] args) (
getResult ();
display ();
/ / System.out.println (Utility.getDistance (new Point (0,0), new Point (0,2)));
)
)
Below is a small test, that is used src \ \ com \ \ sunzhenxing \ \ points.txt contents of the file test, points.txt the file contents are:
0,0
0,1
0,2
0,3
0,4
0,5
12,1
12.2
12.3
12,4
12,5
12.6
0,6
0,7
12,7
0,8
0,9
1,1
The final result of the algorithm is:
—– —– 1st cluster
<0,0>
<0,1>
<0,2>
<1,1>
<0,3>
<0,4>
<0,5>
<0,6>
<0,7>
<0,8>
<0,9>
—– —– 2nd cluster
<12,1>
<12.2>
<12.3>
<12,4>
<12,5>
<12.6>
<12,7>
Coordinates we can draw what conclusions the experiment to understand.

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.

what is Malware

Thursday, August 4th, 2011 | Tips and Tricks with Comments Off

Malware is software package intended to infiltrate or hurt a pc technique without the owner’s informed consent.Many typical laptop or computer customers are however nonetheless unfamiliar with the expression, and most in no way use it. As an alternative, “computer virus” is employed in frequent parlance and usually in the general media to explain all types of malware, though not all malware are viruses.

The most costly type of malware in terms of time and income put in in recovery has been the broad category acknowledged as spyware.Spyware plans are commercially made for the function of gathering data about pc consumers, showing them pop-up advertisements, or altering website-browser habits for the financial gain of the spyware creator. For instance, some spyware plans redirect lookup engine final results to compensated ads.