兼职内容就是帮这个公司把书画装进画框,挂起来调好位置,贴上标签,打好灯光之类的一系列工作。
前期准备工作一共做了五六天,装了大概二百张字画。
还有两天展览之后就是拍卖,然后我们再把字画取出来:)就完事啦----
其实还蛮辛苦的:-I
不过呢,做兼职挣钱是一方面,更多的还是接触到更多的人事物,见识到其他行业,了解它们的日常,最终开拓自身的视野。
package test;
import java.util.Stack;
/**
* Title:StackToQueue
* Description:两个栈实现一个队列
* @author LeslieTian
* @date 2018-10-30 下午8:18:43
* @version 1.0
*/
public class StackToQueue {
Stack stack1 = new Stack();
Stack stack2 = new Stack();
public static void main(String[] args) {
StackToQueue s = new StackToQueue();
s.add(3);
s.add(4);
s.add(5);
System.out.println(s.delect());
System.out.println(s.delect());
System.out.println(s.delect());
System.out.println(s.delect());
}
/**
* 队列入队
* @param x
*/
public void add(int x){
stack1.push(x);
}
/**
* 队列出队
*/
public int delect(){
if((stack2.size()+stack1.size())!=0){//队列不为空
if(stack2.isEmpty()){//stack2为空,stack1不为空
//stack to stack2
stack1Tostack2();
return stack2.pop();
}else{//stack2不为空
return stack2.pop();
}
}
else {//队列为空
System.out.println("队列为空!");
return -1;
}
}
public void stack1Tostack2(){//stack1 元素倒入stack2中
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
}
}
输出:3 4 5 队列为空! -1
package test;
import java.util.ArrayList;
import java.util.LinkedList;
/**
*
* Title:AddTime
* Description:arraylist和linkedlist添加元素速度对比
* @author LeslieTian
* @date 2018-10-14 下午5:12:32
* @version 1.0
*/
public class AddTime {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
LinkedList linkedList = new LinkedList();
long ArrStart = System.currentTimeMillis();//获取ArrayList循环开始前时间
for(int i=0;i<10000;i++){
arrayList.add(i);
}
long ArrEnd = System.currentTimeMillis();//获取ArrayList循环结束的时间
long LinkStart = System.currentTimeMillis();//获取LinkedList循环开始前时间
for(int j = 0;j<10000;j++){
linkedList.add(j);
}
long LinkEnd = System.currentTimeMillis();//获取LinkedList循环结束的时间
if((ArrEnd-ArrStart)>(LinkEnd-LinkStart)){//时间对比
System.out.println("ArrayList慢");
}else {
System.out.println("LinkedList慢");
}
}
}
输出:LinkedList慢所以说ArrayList对越靠近尾部的元素进行增删时效率其实要比LinkedList要高。
package test;
/**
*
* Title:A
* Description:static 静态块
* @author LeslieTian
* @date 2018-10-14 下午4:52:11
* @version 1.0
*/
class A{
static{
System.out.println("A.static");
}
public A() {
System.out.println("A");
}
}
class B extends A{
static {
System.out.println("B.static");
}
public B(){
System.out.println("B");
}
}
public class Static {
public static void main(String[] args) {
new B();
new B();
}
}
运行的结果是:
A.static
B.static
A
B
A
B
为什么会出现这样的结果呢?
static{}(即static块),会在类被加载的时候执行且仅会被执行一次,所以在类A与类B加载时执行static块输出
A.static
B.static
但是之后的创建类B的实例化对象时实例化了两个,只输出打印了一个,这是因为在虚拟机的生命周期中一个类只被加载一次;又因为static{}是伴随类加载执行的,所以,不管你new多少次对象实例,static{}都只执行一次。
另外,输出打印 ABAB 是因为子类在构造是会先执行父类的无参构造函数,又因为实例化两次,所以输出两次AB。
byte a = 5;
byte b = 4;
int c = a+b;//自动类型提升
a+=b;//自加没有自动类型提升问题
char char1 = 4;
char char2 = 4;
char cadd = (char) (char1 + char2);//自动类型提升
char1 += char2;//自加没有自动类型提升问题
short s = 4;
short t = 5;
int con = (s + t) ;//自动类型提升
s += t;//自加没有自动类型提升问题
byte bt = 1;
char ch = 5;
short sh = 5;
int i = 6;
long l =5l;
float f = 6.6f;
double j = 5.7;
long add = l + i ; //long + int 结果为long型
long add2 = l + sh ;//long + short 结果为long型
float add3 = l + f; //long + float 结果为float型
double add4 = l + j;//long + double 结果为double型
float add5 = i + f; //int + float 结果为float型
double add6 = i + j;//int + double 结果为double型
int add7 = i + ch;
int add8 = i + sh;
int add9 = i + bt;//int +(byte,short,char) 结果为int型
但是有一点要注意,final修饰的byte, short, char变量相加后不会被自动提升。
final char fch = 5;
final char fch1 = 6;
char fch2 = fch + fch1;//类型没有提升
byte bt = 1;
char ch = 5;
short sh = 5;
ch = (char) bt;//byte转char需要强制转换
sh = bt; //byte 转short是隐式转换
sh = (short) ch;//short 与 char 之间转换也是强制转换
ch = (char) sh;
我们知道char和short类型都占两个字节,为什么会出现这种情况呢?实际上虽然都是占两字节,但是表示的范围却不一样。
byte表示的范围是-2ˆ7~2ˆ7-1;
char表示的范围是0~2ˆ16-1;
short表示的范围是-2ˆ15~2ˆ15-1;
通过这几个范围我们就可以明白为什么byte转short是隐式转换,转char就要是显式转换。因为byte的表示范围在short表示范围内,但不再char的表示范围内。
char和short表示的范围不同,所以它们之间需要强制转换。
package test;
/**
* Title:ShellSort
* Description:希尔排序
* @author LeslieTian
* @date 2018-9-29 下午5:06:59
* @version 1.0
*/
public class ShellSort {
public static void shellSort(int[] arr){
int h = arr.length/2;//初始步长取排序数组长度的一半
if(h==0){
return;
}
while(h>=1){
for(int i = h; i < arr.length;i++){
for(int j = i; j >= h && arr[j] < arr[j-h];j -= h){
swap(arr,j,j-h);
}
}
System.out.print("步长为" +h+ ": ");//输出一次循环后的数组
for(int word : arr){
System.out.print(word + " ");
}
System.out.println("\n");
h -= 1;
}//while
}//method-shellSort
public static void swap(int arr[],int x,int y){
int temp;
temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
public static void main(String[] args) {
int arr[]= {5,3,6,2,1,7,9,8,0,4} ;
shellSort(arr);
}
}
运行结果:
步长为5: 5 3 6 0 1 7 9 8 2 4
步长为4: 1 3 6 0 2 4 9 8 5 7
步长为3: 0 2 4 1 3 5 7 8 6 9
步长为2: 0 1 3 2 4 5 6 8 7 9
步长为1: 0 1 2 3 4 5 6 7 8 9
package test;
import java.util.Map;
import java.util.TreeMap;
public class TreeMapTest {
public static void main(String[] args) {
Map tree = new TreeMap();
int [] a={9,8,7,6,5,4,3,2,1,0};
for(int i=0; i<10 i<10;i++){
tree.put(a[i],i );
}
for(Integer key:tree.keySet()){
System.out.print(tree.get(key) + " ");
}
}
}
输出结果是:
9 8 7 6 5 4 3 2 1 0
可以发现,TreeMap把它保存的记录按照键进行了排序,并且是按升序排序。
| 排序 | 稳定性 | 时间复杂度 | 空间复杂度 |
|---|---|---|---|
| 气泡排序(bubble sort) | 稳定 | 最差、平均为O(n²),最好为O(n) | 1 |
| 插入排序(insertion sort) | 稳定 | 最差、平均为O(n²),最好为O(n) | 1 |
| 归并排序(merge sort) | 稳定 | 最差、平均和最好都是O(nlog n) | O(n) |
| 二叉树排序(Binary tree sort) | 稳定 | O(nlog n) | O(n) |
| 选择排序(selection sort) | 不稳定 | 最差、平均都是O(n²) | 1 |
| 堆排序(heapsort) | 不稳定 | 最差、平均和最好都是O(nlog n) | 1 |
| 快速排序(quicksort) | 不稳定 | 平均是O(n log n),最坏情况O(n²) | O(log n) |
String S1 = “This is only a” + “ simple” + “ test”;
StringBuffer Sb = new StringBuilder(“This is only a”).append(“ simple”).append(“ test”);
你会惊讶的发现,生成 String S1 对象的速度简直太快了,
而这个时候 StringBuffer 居然速度上根本一点都不占优势。其实这是 JVM对String类进行的优化处理,在JVM眼里,这句生成 String S1 对象的代码相当于String S1 = “This is only a simple test”;
synchronized(x){
x.notify()
//或者wait()
}
4.
sleep必须捕获异常,而wait,notify和notifyAll不需要捕获异常
| 抽象类 | 接口 |
|---|---|
| 抽象类可以有抽象和非抽象方法。 | 接口只能有抽象方法。 从Java 8开始,它也可以有默认和静态方法。 |
| 抽象类不支持多重继承。 | 接口支持多继承。 |
| 抽象类可以有final,非final,静态和非静态变量。 | 接口只有静态和final变量。 |
| 抽象类可以提供接口的实现。 | 接口不能提供抽象类的实现。 |
| abstract关键字用来声明抽象类。 | interface关键字用于声明接口。 |