Java语言画图
package cn.witksy.dev; import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException; /**
* Author: Alfred
* Created: 2015/5/7
*/
public class Main { public void run() {
BufferedImage bufferedImage = new BufferedImage(100,50,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bufferedImage.createGraphics();
g2.setColor(Color.red);
g2.fillRect(0,0,5,5);
g2.setColor(Color.blue);
g2.fillRect(10,20,5,5);
File outputFile = new File("D:\\dev\\java\\workspace\\draw2dtest\\test.png");
try {
ImageIO.write(bufferedImage, "png", outputFile);
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
new Main().run();
}
}
不循环,直接打印List元素
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAc0AAABzCAIAAAB1kM77AAAQSElEQVR4nO2dv27cuBbGtQ+w9b5IECBscl/CpWEYMPgEbg1fGAiQLkoxQJ5gmjGQwrDqGHARGAhSxY2apMhise4WuO3qFvrDc8hzJEoWNTOZ7wcimeFI5BFJfToipeOsmsKXN5cf7kfkN/y4u3i9uum+rlftxo8fzu7+JIWcvG4SK81t3/F0c+Y2Jrs83ZzVFT1+eL35Ulf95lG37OnmbPOFZtxvLtZPlb8js1OyR2e9OqEG9BRL+XF34f00zZ5R5VRV3bC8NN7UrDHF3UlH89rV/hXt7DoiLFbcXkYYJyd942FbTLBzr/rFOwsOh2zCPlojRgx6LsTtOFAF4vGDrMu0QN7BDbuos2Rc7p/Ofnlz6ez3G3PofFYPkPevaOf9hpyZQTfF6uygJbtGrJ171i/Q2XhGObNsHIT9sV59uPfFgmzfqqT/0+OH7pJ7vzkRenRAZ+tLt+csUx108u1GzNPN2eWJbCqxRy//RL1mzKazmj3jddbrTXp+Pt2cDfpNvD3XK9duPf0r2lk93bxpc9i5rW3fzzw6K/TvzETauWf9wtWA2Pn68uS16DD9KozW2ZHOLL0ZOXkdtnKgCOtVMAnANhbnE/gu3Z3U5ku9y9ndnz/uLshdlX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ctgj/1KE/R9kvyrccl50UGz0exHb2Dq277WUtwMcPuUFhd8liOd2BCcfrHaC0MZ0PYfMWoTr64ydlvHyvCtI+Sr1bGw/kEJLNG+xAfP0JOksRezzQI+0+sRAXE4Jd6HpE++RLyeZHtXH2yV8Eq6pwvYvLcZCplJ8bGtc8oyNaOuBgEaadCnRf3B91LCt/JzoNOb6ctlWdJDCruzJNXsbazzSl3Z3FZZ8wHpR+pJWHSzS97RP4vMEP3kQVmzsOf+FLY3wFiJZuQo/Nl8zE8fK5RdyV9urd6nhQ26eabR1sF+Lrz/2ewl48JTQH24paPp2tPPZyMOOBIR71TO0/5ZG+3aFnPKR6rmsnXjOZTWfHr27sMfITFzvPkmfoQY2HqvL8RM1lm9z+O/EewXOIGQ94TwEAAMBEoLMAAJAW6CwAAKQFOgsAAGmBzgIAQFqgswAAkBboLAAApAU6CwAAaYHOAgBAWqCzAACQFugsAACkBToLAABpgc4CAEBaoLMAAJAW6CwAAKQFOgsAAGmBzgIAQFqgswAAkBboLAAApAU6CwAAaYHOAgBAWqCzAACQFugsAACkBToLAABp+T8kFRHm9EoBDAAAAABJRU5ErkJggg==" alt="" />
[12.3, 1.3, 10.3]
<span style="font-size:14px;">打印一个数组中的所有的元素:
1、使用for循环打印
2、将数组转化为有序的List打印出来
package com.inc.test; import java.util.Arrays; public class Test {
public static void main(String[] args) {
String names[] = { "Georgianna", "Tenn", "Simon", "Tom" };
System.out.println(Arrays.asList(names));
}
} </span>
- public class Test
- {
- public static void main(String[] args) {
- String str = args[0];
- System.out.println(str);
- }
- }
2.javac Test.java
3.jar cvf test.jar Test.class
//更新manifest.mf 将自己写的manifest.mf 放到Test.class目录
内容为 Main-Class: Test注意回车
4.jar umf MANIFEST.MF test.jar
5.java -jar test.jar 你的参数
在编译和运行时我们也要加上依赖的jar包,需要注意的是,使用 java -cp 有额外的jar的时候:在Linux下面ClassPath前面是一个点号加一个冒号;在Windows下面ClassPath前面是一个点号加一个分号
import java.io.FileNotFoundException;
import java.io.PrintStream; public class Test { public static void main(String[] args){
PrintStream o = System.out;
try {
System.setOut(new PrintStream("1.txt")); //重定向到文件1.txt
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("line1");
System.setOut(o); //重定向恢复到控制台
System.out.println("line2");
} }
得到指定时间和指定周期的详细日期时间
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; /**
* 得到指定时间和指定周期的详细日期时间
* @author DBClient
*
*/
public class TestTime { private static final SimpleDateFormat df1 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat df2 = new SimpleDateFormat(
"yyyy-MM-dd"); public static void main(String[] args) throws Exception {
// String timeTmp = "00:00";
// Calendar tmpCal = Calendar.getInstance();
// tmpCal.setTime(df2.parse(timeTmp));
// tmpCal.add(Calendar.MINUTE, -5);
//
// //System.out.println(df2.format(tmpCal.getTime()));
// int j = 1;
// while(j <= 2){
// System.out.println(Math.pow(-1, j));
// j++;
// }
String test = "2016-01-23";
// new TestTime().calcTime(test);
new TestTime().getMonth();
new TestTime().getWeek();
new TestTime().getQuarter();
new TestTime().getYear();
} public void calcTime(String testTime) { try { // 周 Date times = df2.parse(testTime);
Calendar cal = Calendar.getInstance();
cal.setTime(times); cal.add(Calendar.DATE, -7);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(df2.format(cal.getTime()));
cal.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
System.out.println(df2.format(cal.getTime())); // 月
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.MONTH, 0);
System.out.println(df2.format(cal.getTime()));
System.out.println(cal.get(Calendar.MONTH) + 1); // 季度 // 年 // cal.add(Calendar.WEEK_OF_MONTH, -1);
// System.out.println(df2.format(cal.getTime()));
// //cal.add(Calendar.MONTH, -1);
// System.out.println(df2.format(cal.getTime()));
// System.out.println(cal.get(Calendar.WEEK_OF_YEAR));
} catch (Exception e) {
e.printStackTrace();
} } /**
* 月
* @throws Exception
*/
public void getMonth() throws Exception { String test = "2015-02-23";
List<String> ret = new ArrayList<String>(); Date times = df2.parse(test);
Calendar cal = Calendar.getInstance();
cal.setTime(times);
cal.add(Calendar.MONTH, -1);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
cal.set(year, month, 1); while(cal.get(Calendar.MONTH) == month){
ret.add(df2.format(cal.getTime()));
cal.add(Calendar.DATE, 1);
}
System.out.println(ret);
} /**
* 周
* @throws Exception
*/
public void getWeek() throws Exception {
String test = "2016-01-09";
List<String> ret = new ArrayList<String>();
Date times = df2.parse(test);
Calendar cal = Calendar.getInstance();
cal.setTime(times); cal.add(Calendar.DATE, -7);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
while(ret.size() < 7){
ret.add(df2.format(cal.getTime()));
cal.add(Calendar.DATE, 1);
} System.out.println(ret);
} public void getQuarter() throws Exception {
String test = "2016-03-01";
List<String> ret = new ArrayList<String>();
Date times = df2.parse(test);
Calendar cal = Calendar.getInstance();
cal.setTime(times);
cal.add(Calendar.MONTH, -3);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
if(month >= 0&& month < 3){
month = 0;
}else if(month >= 3 && month < 6){
month = 3;
}else if(month >= 6 && month < 9){
month = 6;
}else if(month >= 9 && month < 12){
month = 9;
}
cal.set(year, month, 1);
while(cal.get(Calendar.MONTH) <= month + 2 && cal.get(Calendar.YEAR) == year){
ret.add(df2.format(cal.getTime()));
cal.add(Calendar.DATE, 1);
}
System.out.println(ret);
} public void getYear() throws Exception {
String test = "2016-05-09";
List<String> ret = new ArrayList<String>();
Date times = df2.parse(test);
Calendar cal = Calendar.getInstance();
cal.setTime(times);
cal.add(Calendar.YEAR, -1);
int year = cal.get(Calendar.YEAR);
cal.set(year, 0, 1);
while(cal.get(Calendar.YEAR) == year){
ret.add(df2.format(cal.getTime()));
cal.add(Calendar.DATE, 1);
}
System.out.println(ret);
} }
计算指定日期的指定时间段的明细
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA44AAAB9CAIAAABie6rpAAAanklEQVR4nO2dO3brurJF1SoFuzWK3BWnTm+2c6V3qBke48buxO7BewFlCp8qoPChDKvmTM7ZJllVWCwCi5CHdfr79+9//vu///z3f/8AAAAAAFbihFUFAAAAgDVZ1KpeL6fT+f3zZ5J/vp9Pp8v1Z5J38aNy/T5CueZKx414JVa7m6vV87soq4e2A3y+nw9Vrxw/Wq+vlzlrN/2wGmta1aNb35C9vd0/388niSnjKAY/WK7r5Z7socnz3Pw28LmDC6ahudJNiLbfaDFM3gbxTahM1EeImZU0/17lI3pO/333SVnV/fEQ7sdU5vZqw6B+1Wv7P21oRfPxnBVnlo9ajdezqg0jCh6V9IJobuyoKnwK5YZuCG6d/C1hC2M2n6bVI110vZxOrVb1tzxsI3UOr4Nz3siUITz/de96kZ/BZ/TB5/v5dLnkBQwxT8KDHofP97NuVYuVV9fj6WKmJW0zkEkUk3riiJ5rVVVVhbFeL8+aH0d7zz6o6+WX7S+JQ1thn2yFGl6OQ3ZV7bn3bIm9jZfN66XRrcbR0subwoXms9x9prBhExcsvX5aoR5Nz+sFqyqAVc0y/pRV3TSYne2FrWrpjGPElBIaBbapJyV4slWVVf1h3zHceysOahIDTXks9QcYWvlJq6oX0nRQIBlI1L2dg6w9Aaaw6TiUjracVqsnjPH5XrOqn+/nx8nRJ32PHOGB5D3i/H7dDu6bE/e18nFycPVjZOlHtOFVkZph7s46v/PtYd5jlQWnVqG8XyEU8Ei/pVWHoARPf/nSJnJFkzB6xSoIdyEvM72nYj1Z5tPlKj7m92hKJNNRuU7xQwtrm6XR4pOSJ7fc1S1WNXz/VK89SEwxX5zD/pCKOYQMpXlf1fwxGsv9/Zd1bFyDzXTIz1fh7qcdJPZqzxQnDLxrULq8bdN73xxlfYiEgZjnhOYVZ798X+zeL9rspymsfFY6Q20tUejulJYrS5GPTpVocDmQStyviNbr0G5tZ8ltUPjn5donQt2q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TQGL3goNawG3rc490O0t02tBDY1W9b6Nq25KBBsXYUZpPyN8wZSuqdKe66CA30MwVu9Qw9qQ0bA5oFAiGlYDZueI7/5oWApYrRANqwGTIvWFFg1LGpb9HxpWA6ajls3jWhr2/bEq2BBeR6ARNBwHDcdBw3HQcBw0HAcNx1lOQ6xqP8k2OnSAhuOg4ThoOA4ajoOG46DhOAtqKFrVtj1mj9xVQqAB0HAcNBwHDcdBw3HQcBw0HGdVDTOrCgAAAACwBlhVAAAAAFgUrCoAAAAALApWFQAAAAAWBasKAAAAAIuCVQUAAACARcGqAgAAAMCiYFUBAAAAYFGwqgAAAACwKFhVAAAAAFgUrCoAAAAALApWFQAAAAAWBasKAAAAAIuCVQUAAACARcGqAgAAAMCiYFUBAAAAYFGwqgAAAACwKFhVAAAAAFgUrCoAAAAALApWFQAAAAAWBasKAAAAAIuCVQUAAACARcGqAgAAAMCiYFUBAAAAYFGwqgAAAACwKFhVAAAAAFiU/wd9eTnWgjvbhgAAAABJRU5ErkJggg==" alt="" />
Java 依赖包相关运行技巧
有时候不能向服务器上传jar包,或者交涉过于繁琐;只有复制粘贴的权限 可采取:
上传jar包的解压文件,可用zip解压
把自己的源码复制粘贴到解压文件的目录下,即可找到依赖包 或者把jar包添加到java的LibClass path目录下
导出乱码:
1、可能是linux缺少中文
命令:locale
命令:fc-list :lang=zh 2、可能是jdk缺少中文simsun.ttc
放:$JAVA_HOME/jreb/fonts/fallback simsun.ttc下载: http://pan.baidu.com/s/1jHy5Uaq
JAVA多态原理解释
//定义超类superA
class superA
{
int i = 100;
void fun()
{
System.out.println(“This is superA”);
}
}
//定义superA的子类subB
class subB extends superA
{
int m = 1;
void fun()
{
System.out.println(“This is subB”);
}
}
//定义superA的子类subC
class subC extends superA
{
int n = 1;
void fun()
{
System.out.println(“This is subC”);
}
}
class Test
{
public static void main(String[] args)
{
superA a;
subB b = new subB();
subC c = new subC();
a=b;
a.fun(); (1)
a=c;
a.fun(); (2)
}
} /*
运行结果为: This is subB This is subC 上述代码中subB和subC是超类superA的子类,我们在类Test中声明了3个引用变量a, b, c,通过将子类对象引用赋值给超类对象引用变量来实现动态方法调用。也许有人会问:“为什么(1)和(2)不输出:This is superA”。java 的这种机制遵循一个原则:当超类对象引用变量引用子类对象时,被引用对象的类型而不是引用变量的类型决定了调用谁的成员方法,但是这个被调用的方法必须是在超类中定义过的,也就是说被子类覆盖的方法。 所以,不要被上例中(1)和(2)所迷惑,虽然写成a.fun(),但是由于(1)中的a被b赋值,指向了子类subB的一个实例,因而(1)所调用的fun()实际上是子类subB的成员方法fun(),它覆盖了超类superA的成员方法fun();同样(2)调用的是子类subC的成员方法fun()。 另外,如果子类继承的超类是一个抽象类,虽然抽象类不能通过new操作符实例化,但是可以创建抽象类的对象引用指向子类对象,以实现运行时多态性。具体的实现方法同上例。 不过,抽象类的子类必须覆盖实现超类中的所有的抽象方法,否则子类必须被abstract修饰符修饰,当然也就不能被实例化了。
*/ http://developer.51cto.com/art/200909/153887.htm
java多态解释
JAVA多线程样例
public class Test implements Runnable {
private String name;
private static int flag = 0; public Test(String name) {
this.name = name;
} @Override
public void run() {
while (flag < 100) {
flag++;
System.out.println(name + ": " + flag);
}
} public static void main(String[] args) {
long startTime = System.currentTimeMillis(); for (int i = 0; i < 2; i++) {
new Thread(new Test("thread-" + (i + 1))).start();
}
long endTime = System.currentTimeMillis(); System.out.println("spend times: " + (endTime - startTime) / 1000
+ " s");
} }
java 多线程样例