java备忘2

编程入门 行业动态 更新时间:2024-10-13 22:21:27

<a href=https://www.elefans.com/category/jswz/34/1770091.html style=java备忘2"/>

java备忘2

一、不错的学习资源:
1、Data Structure
.htm

学堂在线:数据结构
=%E9%82%93%E4%BF%8A%E8%BE%89&page=1

廖雪峰 java教程

二、常用技术入门:

1.1、java与javax的区别分析(转)
.html
1.2 Tinking in Java(Java编程思想) 第四版全部习题答案
.htm

1.3 Java反编译工具-JD-GUI
.html

下载网址:
/
github网址:

2、Wind10 Tomcat配置,Tomcat第一个网页 Helloworld!

Tomcat入门之helloWorld

安装好Tomcat后,进入其文件夹->webapps->ROOT

新建一个txt文件,命名helloWorld.jsp,打开,在里面输入

<html>
<body>
<center>
Hello World
</center>
</body>
</html>

保存,将后缀改为jsp,打开Tomcat,打开浏览器,输入网址

http://localhost:8080/helloWorld.jsp

就会显示Hello World

3、网页计数

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>统计操作次数</title><script>
var a = 0;
function numCount(){a++;document.getElementById("demo").innerHTML=a;
}
</script>
</head>
<body><h1>我的第一个 JavaScript 程序</h1>
<p>当前计数为:</p>
<p id="demo">0</p><button type="button" οnclick="numCount()">增加计数</button></body>
</html>

4、tomcat部署简单的html静态网页

5、有哪些适合新手练手的Java Web项目?

JavaWeb学习总结 —!!!!!
.html

6、Servlet 实例
.html

java编译错误 程序包javax.servlet不存在javax.servlet.*

javaweb学习总结(六)——Servlet开发(二)
.html

7、【Spring】IntelliJ IDEA搭建Spring环境 (入门实践)

8、spring bean是什么
.html

9、浅谈Java中的hashcode方法 (很适合入门)
.html

10、Java 访问权限控制:你真的了解 protected 关键字吗?

11、windows下安装和配置Redis

Redis【入门】就这一篇!

12、使用阿里巴巴的FastJson的一个例子

import java.util.List;
import java.util.ArrayList;
import com.alibaba.fastjson.JSON;/*** 使用阿里巴巴FastJson将对象转换成json字符串、将json字符串装换成对象** @author CodeCraft* @2019-12-14*/
public class FastJsonDemo {public static void main(String[] args) {// 构建用户geustUser guestUser = new User();guestUser.setName("guest");guestUser.setAge(28);// 构建用户rootUser rootUser = new User();rootUser.setName("root");rootUser.setAge(35);// 构建用户组对象UserGroup group = new UserGroup();group.setName("admin");group.getUsers().add(guestUser);group.getUsers().add(rootUser);//将对象转换为json字符串String jsonString = JSON.toJSONString(group);System.out.println("jsonString:"+jsonString);//将json字符串转换成对象UserGroup group1 = JSON.parseObject(jsonString, UserGroup.class);System.out.println(group1);//数组装换为json字符串User[] users = new User[2];users[0] = guestUser;users[1] = rootUser;String jsonString1 = JSON.toJSONString(users);System.out.println("jsonString1:"+jsonString1);//json字符串转换为ListList<User> user2 = JSON.parseArray(jsonString1, User.class);System.out.println(user2);}private static class User {private String name;private int age;public User() {super();// TODO Auto-generated constructor stub}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString(){return "User={ "+"name:"+this.name+", age:"+this.age+" }";}}private static class UserGroup {private String name;private List<User> users  = new ArrayList<User>();public String getName() {return name;}public void setName(String name) {this.name = name;}public List<User> getUsers() {return users;}public void setUser(List<User> users) {this.users = users;}public UserGroup() {super();// TODO Auto-generated constructor stub}@Overridepublic String toString(){return "UserGroup:{ name="+this.name+", user="+this.users+" }";}}
}

13、Fastjson内幕 – wenshao

14、idea中查看方法的调用链

IntelliJ IDEA中可以在主菜单中选择Navigate | Call Hierarchy命令查看一个Java方法调用树(caller和callee两个方向),但是不像Eclipse那样可以查看类成员变量的调用树。

15、Spring 框架简介
.html

16、keepalived原理、配置解析及其应用案例(keepalived双机热备实现)

/

nginx实现请求的负载均衡 + keepalived实现nginx的高可用
.html

17、时间的3种格式:long/date/String

import java.text.SimpleDateFormat;
import java.util.Date;public class Main {public static void main(String[] args) {//时间的3种格式:long/date/StringLong millSec = System.currentTimeMillis();System.out.println(millSec);Date date = new Date(millSec);System.out.println(date);String dateFormat = "yyyy-MM-dd HH:mm:ss";SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);System.out.println(sdf.format(date));//date2longSystem.out.println(date.getTime());}

参考:java Data、String、Long三种日期类型之间的相互转换
.html
Java 把long 转换成 日期 再转换成String类型
.html

18、sed 之 \1-9 的作用(设定9种模式)

sed 之 \1-9 的作用
\1 就代表被匹配到的第一个模式,sed 一共可以记录9个模式。这些模式在某些场景下会非常有用,下面就介绍一下怎样使用。
模式? 就是正则表达式用 () 扩起来的内容
命令行模式下用到了转义字符 和和
先看一行命令:
[www@]$ echo hello123|sed "s/\([a-z]*\).*/\1/"
hello这里我们看到的是正则匹配到的部分是 hello 这个字符串,替换的模式里面是 \1 , 那么 \1 实际上代表的就是 hello 这个字符串,接下来我们看另外一行命令:[www@]$ echo hello123|sed 's/\([a-z]*\)\([0-9]\{3\}\)/\2\1/'
123hello
看到没? 本来应该输出 hello123 的,现在被替换成了123hello
这行命令里面有两个模式 ([a-z]*) 对应的是 \1 模式1
([0-9]{3}) 对应的是 \2 模式2, 最后替换的内容里面 \2\1 代表的是
模式2 放到模式1 的前面,这就达到了颠倒字符串的目的。这样是不是很有趣,记住现在是sed最多可以记录9个模式。

19 、mybatis
.html

20、Java占位符

具体如何使用可以参考官方API文档
/

import java.text.MessageFormat;
import java.util.Date;public class test01 {public static void main(String[] args) {System.out.println("hello");// print hello// %s占位符,输出字符串String username = "user1";int num = 3;System.out.printf("%s您好,您是第%s位访客\n", username, num); // prints user1您好,您是第3位访客// %f占位符double d = 1.2;float f = 1.2f;System.out.printf("%f %f", d, f); // prints 1.200000 1.200000// %1$s占位符//%n$ms:代表输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置m个0 System.out.println(String.format("我是%1$s,我来自%2$s,今年%3$s岁", "中国人", "北京","22"));// prints 我是中国人,我来自北京,今年22岁// {}占位符,{}内的数字代表第几个参数,参数从0开始String url = "www.baidu";int count = 1000;System.out.println(MessageFormat.format("该网站{0}被访问了 {1} 次.", url, count));// prints 该网站www.baidu被访问了 1,000 次.// {}占位符String template = "Welcome {0}!  Your last login was {1}";String output = MessageFormat.format(template, new Object[] { "Python",new Date().toString() });System.out.println(output);// prints  Welcome Python!  Your last login was Fri Oct 10 20:47:00 CST 2014}
}

21、Java基础——从键盘(控制台)输入字符串(数据)的几种方式详解

(1) Scanner类的调用

package FIRST_Chapter;import java.util.Scanner;public class TestScanner { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("请输入字符串:"); while (true) { String line = s.nextLine(); if (line.equals("ok")) break; System.out.println(">>>" + line); } } 
}

(2) BufferedReader类的调用

package FIRST_Chapter;import java.io.*;class test{public static void main(String[] Args){try{  System.out.println("please input the content that you want to show,end with new line <ok>");InputStreamReader isr = new InputStreamReader(System.in); //这样是为了将数据传入流中,相当于数据流的入口BufferedReader br = new BufferedReader(isr);while(true){String temp = new String(br.readLine());System.out.println(">>>"+temp);if(temp.equals("ok")) break; //注意这个地方不能用等号,用equals }System.out.println("the content from your keyboard has been written correctly");}catch(IOException e){System.out.println("the file has not record correctly");}}
}

22、Java中BufferedReader与Scanner读入的区别

  java.util.Scanner类是一个简单的文本扫描类,它可以解析基本数据类型和字符串。它本质上是使用正则表达式去读取不同的数据类型。Java.io.BufferedReader类为了能够高效的读取字符序列,从字符输入流和字符缓冲区读取文本。

23、java经典实例 第三版 PDF 下载
.html

24、基于Java数组实现循环队列的两种方法小结
.htm

25、Java finally 的用法,看这一篇就够了 --明明如月君 2020年01月06日

26、Java—List的用法与实例详解

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;public class   TestList {/*** 测试add/remove/size/isEmpty/contains/clear/toArrays等方法*/public static void   test01() {List<String> list = new ArrayList<String>();boolean b = list.isEmpty();System.out.println(b);   // true,容器里面没有元素list.add("高淇");System.out.println(list.isEmpty());   // false,容器里面有元素list.add("高小七");list.add("高小八");System.out.println(list);System.out.println("list的大小:" +   list.size());System.out.println("是否包含指定元素:" +   list.contains("高小七"));System.out.println("指定元素的index:" +   list.indexOf("高小七"));System.out.println("get指定index的元素:" +   list.get(1));list.remove("高淇");System.out.println(list);Object[] objs = list.toArray();System.out.println("转化成Object数组:" +   Arrays.toString(objs));list.clear();System.out.println("清空所有元素:" +   list);}public static void   main(String[] args) {test01();}
}

27、Java中的LinkedList的方法的应用

import java.util.LinkedList;public class LinkedListMethodsDemo {public static void main(String[] args) {LinkedList<String> linkedList = new LinkedList<>();linkedList.push("first");linkedList.push("second");linkedList.push("second");linkedList.push("third");linkedList.push("four");linkedList.push("five");System.out.println("linkedList: " + linkedList);System.out.println("linkedList.contains(\"second\"): " + linkedList.contains("second"));System.out.println("linkedList.contains(\"six\"): " + linkedList.contains("six"));System.out.println("linkedList.element(): " + linkedList.element());System.out.println("linkedList: " + linkedList);System.out.println("linkedList.set(3, \"set\"): " + linkedList.set(3, "set"));System.out.println("linkedList: " + linkedList);System.out.println("linkedList.subList(2,4): " + linkedList.subList(2,4));System.out.println("linkedList: " + linkedList);}
}

28、由浅入深理解java集合(一)——集合框架 Collection、Map

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;public class IteratorExample {public static void main(String[] args){//创建集合,添加元素Collection<Integer> days = new ArrayList<Integer>();for(int i =0;i<10;i++){days.add(i);}//获取days集合的迭代器Iterator<Integer> iterator = days.iterator();while(iterator.hasNext()){//判断是否有下一个元素int next = iterator.next();//取出该元素//逐个遍历,取得元素后进行后续操作System.out.println(next);}}}

29、Java transient关键字使用示例

import java.io.Serializable;public class Employee implements Serializable {private static final long serialVersionUID = -1L;private String firstName;private String lastName;private transient String confidentialInfo;public void setFirstName(String str) {firstName = str;}public void setLastName(String str) {lastName = str;}public void setConfidentialInfo(String str) {confidentialInfo = str;}public String getFirstName() {return firstName;}public String getLastName() {return lastName;}public String getConfidentialInfo() {return confidentialInfo;}
}
import java.io.*;public class TransSerializationTest {public static void main(String[ ] args) throws FileNotFoundException {try {Employee emp = new Employee();emp.setFirstName("Chen");emp.setLastName("ShuaiShuai");emp.setConfidentialInfo("password");System.out.println("Read before Serialization:");System.out.println("firstName: " + emp.getFirstName());System.out.println("lastName: " + emp.getLastName());System.out.println("confidentialInfo: " + emp.getConfidentialInfo());ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:/chenss.txt"));//Serialize the objectoos.writeObject(emp);oos.close();} catch (Exception e) {System.out.println(e);}try {ObjectInputStream ooi = new ObjectInputStream(new FileInputStream("E:/chenss.txt"));//Read the object backEmployee readEmpInfo = (Employee) ooi.readObject();System.out.println("Read From Serialization:");System.out.println("firstName: " + readEmpInfo.getFirstName());System.out.println("lastName: " + readEmpInfo.getLastName());System.out.println("confidentialInfo: " + readEmpInfo.getConfidentialInfo());ooi.close();} catch (IOException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();}}
}

更多推荐

java备忘2

本文发布于:2024-02-12 11:58:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1687699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!