unit1_开发工具和Java语言介绍

2024-02-07 00:32

本文主要是介绍unit1_开发工具和Java语言介绍,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

版本控制系统:

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>(){@Overridepublic 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")); //9print(6, map.containsKey("A")); //falsemap.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))); //falseprint(4, strSet.isEmpty()); //falseprint(5, strSet.size()); //2strSet.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;}@Overridepublic 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;}@Overridepublic void say(){System.out.print("This is Human from" + country);}
}
多态
同一个接口,有不同的实现类。不关心这些实现类
随机数
public static void demoFunction(){Random random = new Random();// nextInt = 2random.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.练习代码提交到Bitbucket7.时间的自己练习

这篇关于unit1_开发工具和Java语言介绍的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/686008

相关文章

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

Java Spring 中 @PostConstruct 注解使用原理及常见场景

《JavaSpring中@PostConstruct注解使用原理及常见场景》在JavaSpring中,@PostConstruct注解是一个非常实用的功能,它允许开发者在Spring容器完全初... 目录一、@PostConstruct 注解概述二、@PostConstruct 注解的基本使用2.1 基本代

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊