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

相关文章

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

Java对异常的认识与异常的处理小结

《Java对异常的认识与异常的处理小结》Java程序在运行时可能出现的错误或非正常情况称为异常,下面给大家介绍Java对异常的认识与异常的处理,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参... 目录一、认识异常与异常类型。二、异常的处理三、总结 一、认识异常与异常类型。(1)简单定义-什么是

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

SpringBoot排查和解决JSON解析错误(400 Bad Request)的方法

《SpringBoot排查和解决JSON解析错误(400BadRequest)的方法》在开发SpringBootRESTfulAPI时,客户端与服务端的数据交互通常使用JSON格式,然而,JSON... 目录问题背景1. 问题描述2. 错误分析解决方案1. 手动重新输入jsON2. 使用工具清理JSON3.

java中long的一些常见用法

《java中long的一些常见用法》在Java中,long是一种基本数据类型,用于表示长整型数值,接下来通过本文给大家介绍java中long的一些常见用法,感兴趣的朋友一起看看吧... 在Java中,long是一种基本数据类型,用于表示长整型数值。它的取值范围比int更大,从-922337203685477

java Long 与long之间的转换流程

《javaLong与long之间的转换流程》Long类提供了一些方法,用于在long和其他数据类型(如String)之间进行转换,本文将详细介绍如何在Java中实现Long和long之间的转换,感... 目录概述流程步骤1:将long转换为Long对象步骤2:将Longhttp://www.cppcns.c

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

SpringBoot服务获取Pod当前IP的两种方案

《SpringBoot服务获取Pod当前IP的两种方案》在Kubernetes集群中,SpringBoot服务获取Pod当前IP的方案主要有两种,通过环境变量注入或通过Java代码动态获取网络接口IP... 目录方案一:通过 Kubernetes Downward API 注入环境变量原理步骤方案二:通过