优大网

分类存档: JAVA

图说Java

Top 8 Diagrams for Understanding Java

A diagram is sometimes worth 1000 words. The following diagrams are from Java tutorials on Program Creek, they have received the most votes so far. Hopefully, they can help you review what you already know. If the problem is not clear by the diagram itself, you may want to go to each article to take a further took.

 

1. String Immutability

The following diagram shows what happens for the following code:

String s = "abcd";
s = s.concat("ef");

string-immutability

2. The equals() and hashCode() Contract

HashCode is designed to improve performance. The contract between equals() and hasCode() is that:
1. If two objects are equal, then they must have the same hash code.
2. If two objects have the same hashcode, they may or may not be equal.

java-hashcode

3. Java Exception Class Hierarchy

Red colored are checked exceptions which must either be caught or declared in the method’s throws clause.

Exception-Hierarchy-Diagram

4. Collections Class Hierarchy

Note the difference between Collections and Collection.


5. Java synchronization

Java synchronization mechanism can be illustrated by an analogy to a building.

6. Aliasing

Aliasing means there are multiple aliases to a location that can be updated, and these aliases have different types.

Java Aliasing

7. Stack and Heap

This diagram shows where methods and objects are in run-time memory.

Java-array-in-memory

8. JVM Run-Time Data Areas

This diagram shows overall JVM run-time data areas.

JVM runtime data area

 

http://www.programcreek.com/2013/09/top-8-diagrams-for-understanding-java/

java实现矩形,数字从四周到中心逐渐增大

打印效果:Matrix

public class TestMatrix {
public static void main(String[] args) {
testMatrix();
}

static void testMatrix() {
int row = 5, col = 3, x = 0, y = 0, start = 1000;
int[][] matrix = new int[row][col];
setMatrix(matrix, x, start);
printMatrix(matrix);
}

/**
* 递归实现.<br>
* 从四周到中心,数字逐渐递增
*
*/
static void setMatrix(int[][] matrix, int p, int start) {
int xLen = matrix.length, yLen = matrix[0].length;
int i, doublep = 2 * p;
if (yLen <= doublep || xLen <= doublep)
return;

// 上边
int topMax = yLen – p;
for (i = p; i < topMax; i++) {
matrix[p][i] = start++;
}

// 右边
int rightMax = xLen – p;
int rightY = yLen – p – 1;
for (i = p + 1; i < rightMax; i++) {
matrix[i][rightY] = start++;
}

// 没有右边情况
if (xLen == doublep + 1) {
return;
}

// 下边
int bottomX = rightMax – 1;
for (i = yLen – p – 2; i >= p; i–) {
matrix[bottomX][i] = start++;
}

// 没有下边
if (yLen == doublep + 1) {
return;
}

// 左边
for (i = xLen – p – 2; i > p; i–) {
matrix[i][p] = start++;
}
setMatrix(matrix, p + 1, start);
}

/**
* 打印数组
*/
static void printMatrix(int[][] matrix) {
for (int[] xl : matrix) {
for (int yl : xl) {
System.out.print(yl + ” “);
}
System.out.println();
}
}

自动生成代码工具

背景

很多业务很多功能对应的操作都很接近,很多代码都是共通的,只需改动一部分。如果新建一张表,共通的代码能自动生成就好,不需要拷贝原来的代码还要修改,能节省很多时间。

准备

1、MyBatis使用Generator自动生成代码,工具配置、数据库连接读取等通过它来完成。需要下载mybatis-generator-core-1.3.2

MyBatis生成的是固定格式的的几个模板,而且只能是java相关的代码,并且很多东西还不太灵活,不能满足很多业务。

2、通过velocity生成模板文件。需要下载velocity1.7

设计

1.一个表对应的数据通过MyBatis读取。

2.按一定规则自定义一套模板文件,通过velocity生成每个表对应的模板文件。自定义的模板文件可以满足PHP/JAVA等各种语言的代码生成。

开发语言:java

详细说明及源码

正准备开发中,待续!

 

 

Copyright © 2024 优大网 浙ICP备13002865号

回到顶部 ↑