版本控制系统:
github:私有化收费
bitbucket:免费但需要翻墙
oschina.net coding.net
svn:方便控制权限,各个目录的访问。也是一种版本控制系统。
牛客网、阿里巴巴、人人网等都使用svn。
开始
java 语言
intelli idea 工具
maven 相关库依赖的工具
语法
public static void print(int index, Object object){
System.out.printlnI(String.format("{%d}, %s", index, object.toString()));
}
public static void main(String[] args){
print(1, "Hello World");
}
结果:
{1}, Hello World
注释://; /* /; /* /; 单行,多行,Java Doc
运算
public static void demoOperation(){
print(1, 5+2);
print(2, 5-2);
print(3, 5*2);
print(4, 5/2);
print(5, 5%2);
print(6, 5<<2);
print(7, 5>>2);
print(8, 5|2);
print(9, 5^2);
print(10, 5==2);
print(11, 5!=2);
}
变量
int a = 11;
double b = 2.2f;
a += 2;
print(14, a);
字符串
String str = "Hello World";
print(1, str.indexOf('e')); //判断某一个字符串中是否存在e,返回位置(不存在返回-1)
print(2, str.charAt(3)); //返回l
print(3, str.codePointAt(1)); //101;ASCLL码
print(4, str.compareToIgnoreCase("HELLO WORLD")); //0; 相同的
print(5, str.compareTo("hello vorld")); // 1;比v大的距离(二进制中的)
print(6. str.compareTo("hello xorld")); // -1;
print(7, str.contains("hello")); //true
print(8, str.concat("!!!"));
print(9, str.toUpperCase());
print(10, str.endsWith("world")); //true
print(11, str.startsWith("hell")); //true
print(12, str.replace('o', 'e'));
print(13, str.replaceAll("o|l", "a"));
print(14, str.replaceAll("hello", "hi"));
print(15, str+str);
不产生新的对象的基础上,对所有类型进行append的操作
StringBuilder sb = new StringBuilder(); // 线程不安全
sb.append('x ');
sb.append(1.3);
sb.append("a");
sb.append(true);
print(16, sb.toString()); //x 1.3atrue
控制流
public static void demoControlFlow(){
int a = 3;
int target = a==2? 1:3;
if(a == 2){
target = 1;
}else{
target = 3;
}
}
String grade = "B";
switch(grade){
case "A":
print(3, ">80");
break;
case "B":
break;
print(2, "60-80");
case "C":
print(1, "<60");
break;
default:
print(6, "未知");
break;
}
for(int i=0;i<4;i++){
print(7, i);
}
while(score<100){
print(8, score);
score+=20;
}
数据结构
ArrayList:可变数组
public static void demoList(){
List<String> strList = new ArrayList<String>(10);
for(int i=0; i<4; i++){
strList.add(String.valueOf(i*i));
}
print(1, strList);
List<String> strListB = new ArrayList<String>();
for(int i=0; i<4; i++){
strList.add(String.valueOf(i));
}
strList.addAll(strListB); //将两个列表合并
print(2, strList);
strList.remove(0);
print(3, strList);
strList.remove(String.valueOf(1));
print(4, strList);
print(5, strList.get(1));
Collections.reverse(strList);
print(6, strList);
Collections.sort(strList);
print(7, strList);
Collections.sort(strList, new Comparator<String>(){
@Override
public int compare(String o1, String o2){
return o1.compareTo(o2);
}
})
print(8, strList);
for(String obj:strList){
print(9, obj);
}
for(int i=0;i<strList.size();i++){
print(10, strList.get(i));
}
int[] array = new int[]{1, 2, 3};
print(11, array[1]);
}
public static void main(String[] args){
demoList();
}
HashMap
public static void demoMapTable(){
Map<String, String> map = new HashMap<String, String>();
for(int i=0;i<4;i++){
map.put(String.valueOf(i), String.valueOf(i*i));
}
print(1, map);
// map<int, int>::iterator it = map.begin();
for(Map.Entry<String, String> entry : map.entrySet()){
print(2, entry.getKey() + "|" + entry.getValue());
}
print(3, map.values()); //[0,1,4,9]
print(4, map.keySet()); //[0,1,2,3]
print(5, map.get("3")); //9
print(6, map.containsKey("A")); //false
map.replace("3", "27");
print(7, map.get("3")); //27
}
Set
public static void demoSet(){
Set<String> strSet = new HashSet<String>();
for(int i=0;i<3;i++){
strSet.add(String.valueOf(i));
}
print(1, strSet); //[0,1,2]
strSet.remove(String.valueOf(1));
print(2, strSet); //[0,2]
print(3, strSet.contains(String.valueOf(1))); //false
print(4, strSet.isEmpty()); //false
print(5, strSet.size()); //2
strSet.addAll(Arrays.asList(new String[] {"A", "B", "C"}))
print(6, strSet);
for (String value: strSet){
print(7, value);
}
}
异常
public static void demoException(){
try{
int k = 2;
k = k/0;
// xxxxx
}catch{
print(2, e.getMessage());
}finally{
print(3, "finally");
}
}
// {2}, / by zero
// {3}, finally
面向对象
封装
public interface Talking{
void say();
}
public class Animal implements Talking{
private String name;
private int age;
public Animal(String name, int age){
this.name = name;
this.age = age;
}
@Override
public void say(){
System.out.print(name + "Animal Say");
}
public static void demo00(){
Animal a = new Animal("jim", 1);
a.say();
}
public static void main(String[] args){
demo00();
}
}
继承
public class Human extends Animal{
private String country;
public Human(String name, int age, String country){
super(name, age);
this.country = country;
}
@Override
public void say(){
System.out.print("This is Human from" + country);
}
}
多态
同一个接口,有不同的实现类。不关心这些实现类
随机数
public static void demoFunction(){
Random random = new Random();
// nextInt = 2
random.setSeed(1);
print(1, random.nextInt(1000)); //0-1000的一个随机数
print(2, random.nextFloat());
List<Integer> array = Arrays.asList(new Integer[]{1, 2, 3, 4, 5});
Collections.shuffle(array); //随机打乱
print(3, array);
Date date = new Date();
print(4, date);
print(5, date.getTime()); //1970年至今毫秒数
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
print(6, df.format(date));
print(7, UUID.randomUUID()); //随机字符串
print(8, Math.log(10));
print(9, Math.min(3, 10));
print(10, Math.max(3, 10));
print(11, Math.ceil(2.2));
print(9, Math.floor(2.2));
}
作业
1.开发环境搭建
2.IntelliJ菜单里每个按钮的使用熟悉
3.Java基础语法练习
4.Java容器类库练习
5.随机数、时间等常用类
6.练习代码提交到Bitbucket
7.时间的自己练习