Java复习笔记

这篇博客主要涵盖了Java中的核心概念,包括字面量、DOM解析XML、JDBC连接、二叉树的广度优先搜索、数学类Math、栈和队列的操作、注解、继承、泛型以及数组和Map的使用。此外,还提到了Java实例方法和类方法的区别以及String类的字符数组转换。
摘要由CSDN通过智能技术生成

输入逗号(特定符号间隔的数字)
以字符串的形式输入,通过split(‘punctuation’)分割,通过字符串数组保存分割到的 == 数字字符串==,利用Integer.parseInt()并将结果存入数组中。

	Scanner scan = new Scanner (System.in);	
	String in = scan.nextLine();
	String numS[]=in.split(",");
	int[] num = new int [numS.length];
	for(int i = 0 ; i < numS.length;i++)
	{
   
		num[i]=Integer.parseInt(numS[i]);
	}
	for(int i=0;i<numS.length;i++)
	{
   
		System.out.println(num[i]);
	}
	System.out.print(num);   		///hahah
		

literals (字面上,文本)
You may have noticed that the new keyword isn’t used when initializing a variable of a primitive type. Primitive types are special data types built into the language; they are not objects created from a class. A literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation. As shown below, it’s possible to assign a literal to a variable of a primitive type:

boolean result = true;
char capitalC = 'C';
byte b = 100;
short s = 10000;
int i = 100000;

long 型数据需要在后面加上l或L 默认使int
float 后面加上F或f 默认使double

long
long类型的整数常数结尾一定为l或L(不区分大小写)。
♂DOM解析XML文件♂
转载:https://blog.csdn.net/a1353206432/article/details/80583302

public class Exercise{
   
 public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException {
   
  DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  DocumentBuilder builder=factory.newDocumentBuilder();
  Document doc = builder.parse("src\\HelloXML.xml");
  NodeList node = doc.getElementsByTagName("linkman");
  for(int i=0;i<node.getLength();i++)
  {
   
   Element e = (Element)node.item(i);
   System.out.println("name "+e.getElementsByTagName("name").item(0).getFirstChild().getNodeValue());
   System.out.println("email "+e.getElementsByTagName("mail").item(0).getFirstChild().getNodeValue());
  }
  
 }
}

JDBC JDK8 MySQL8.0.18 Connection/J 8.0.18
使用Connection/J中的驱动的时候需要修改Class.forName()中的参数为“com.mysql.cj.jdbc.Driver”
这里一定要注意Driver中的D需要大写!
url需要显示端指定关闭ssl即useSSL=false;
同时需要配置时区即&serverTimezone=地点
转载:https://blog.csdn.net/kikock/article/details/80413475

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.cj.xdevapi.Statement;

public class BataBase {
   

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
   
		// TODO Auto-generated method stub
		//System.out.println("ShuZhiYuan");
		
		/*
		 * JDBC 四大配置参数
		 * >driverClassName: com.mysql.jdbc.Driver
		 * >url:jdbc:mysql://localhost:3306/数据库名
		 * >username:root
		 * >password:123456
		 */
		String url="jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
		//  ? 起连接作用,通过?来带参数,连接域名何参数
		//& 不同参数的间隔符
		String username="root";
		String password="123456";
		try {
   
			Class.forName("com.mysql.cj.jdbc.Driver");
		}catch(Exception e) {
   
			System.out.println("加载驱动类失败");
		}
		//DriverManager class manage the establishment of connections
		//use Class.forName() to implements the java.sql.Driver interface .If with connector/J ,use the com.mysql.cj.jdbc.Driver.
		//obtain a Connection instance to connect particular database By DriverManager.getConnection()
		//To create a Statement instance ,use the createStatement()method on the Connection Object.
		//using JDBC Statement Object to Execute SQL 
		//retrieve the results through the ResultSet Class
		
		Connection con = DriverManager.getConnection(url,username,password);
		ResultSet rs ;
		java.sql.Statement sql;
		sql=con.createStatement();
		rs=sql.executeQuery("Select * from first_table");
		while(rs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值