Java学习笔记(二)不定时更新

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/gu3Z3U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lynG/1mjGbzgrtM6Gctgj/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>
1.首先新建Test.java
  1. public class Test
  2. {
  3. public static void main(String[] args) {
  4. String str = args[0];
  5. System.out.println(str);
  6. }
  7. }

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 你的参数

 
 
下载net.sf.fjep.fatjar_0.0.31   http://pan.baidu.com/s/1sj0uawX
或者参考
 
aaarticlea/png;base64,iVBORw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4+MLMhTGdIjfqZtkjXA6EkVkLY2EYWE7hSJcDYWT2wpjNk2uOtoxwORBGZueodKN3gHnoUenhlwMHX5iJo9LF4A16fuKolwNhZAZGjCCMIIwIIww/+AIOvoAwIowgjAgjCCPCCA6+4OALjC+Mx1hnsbI+o+cxIozMYhiPsc5iw3qMCCMXZio92jqLjYb1GBFGLszBl5HWWSwtomM9Rhx8YYbD2BhpncWaKbf1GBFGLsqIsX6dxUaj/yiL9RgRRi5SGAeuszjq5UAYmZGj0kevs2g9Rhx84WIclc4nyEeus9g7Y/jlQBg552EEYQRhRBjhyIMv4OALwiiMCCMII8IIwogwgoMvOPgCwogwwpjcCYRxguKfsB/DhH/AHsmMN4zhjzBO8nEbfsJ+DBP+AXskM/4wzsd7r+fnfZ7A5/xx6+cxmc/CyITC6MfgJ+wHDKV9jH4MfsJ+wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMD58P8Bi2Q1ZErJC8UAAAAASUVORK5CYII=" alt="" />
在编译和运行时我们也要加上依赖的jar包,需要注意的是,使用 java -cp 有额外的jar的时候:在Linux下面ClassPath前面是一个点号加一个冒号;在Windows下面ClassPath前面是一个点号加一个分号

http://blog.csdn.net/czw698/article/details/44353453

 
Java控制台输出信息console重定向到文件,后恢复到console
 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/WK7r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ACARcGqAgAAAMCiYFUBAAAAYFGwqgAAAACwKFhVAAAAAFgUrCoAAAAALApWFQAAAAAWBasKAAAAAIuCVQUAAACARcGqAgAAAMCiYFUBAAAAYFGwqgAAAACwKFhVAAAAAFgUrCoAAAAALApWFQAAAAAWBasKAAAAAIuCVQUAAACARcGqAgAAAMCiYFUBAAAAYFGwqgAAAACwKFhVAAAAAFiU/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 多线程样例

上一篇:[TLSR8266] 1、搭建tlsr8266编译框架在win服务器中


下一篇:1px和backgroudImage