1、package
package it.heima.loop3.loo1;
import it.heima.loop3.loo2.demo;
import java.util.Random;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
// 其他包里面的类
demo d = new demo();
d.print();
// 本包里的其他类
demo11 d1 = new demo11();
d1.printa();
// java拓展库
// java.long 不需要导入
Scanner sc = new Scanner(System.in);
Random r = new Random();
// 不同包下面的同名类,只能在import头部调用一个,倘若要用多个,就直接如下使用全名称就行;不必在import中写
it.heima.loop.demo dd = new it.heima.loop.demo();
dd.prints();
}
}
2、String
package it.heima.loop4;
public class demo1 {
public static void main(String[] args) {
String st1 = "heihei";
System.out.println(st1);
String st2 = new String();
System.out.println(st2);
String st3 = new String("heihei");
System.out.println(st3);
char[] chars = new char[]{
'a', 'b', 'h'};
String st4 = new String(chars);
System.out.println(st4);
byte[] bytes = {
97,98, 99};
String st5 = new String(bytes);
System.out.println(st5);
}
}
output
heihei
heihei
abh
abc
1. What is String and what can it do?
Represents a string, which can be used to create an object to encapsulate string data and process it
2. How many ways does the string class create objects to encapsulate string data?
Method 1: Directly use double quotation marks "..."
Method 2: new String class, call the constructor to initialize the string object