1.分别写出分支结构,循环结构的语法格式。
循环结构:
while 循环
do…while 循环
for 循环
foreach循环
分支结构:
if 语句
switch 语句
2.写出控制循环结构的相关语句,并描述其作用。
break:在循环体中,使用 break 关键字跳出整个循环。
continue:在循环体中,使用 continue 跳出本次循环,循环还会继续执行。
3.数组初始化的方式有哪些?请举例说明。
静态初始化:int[] arrs = {1, 2, 3, 4};
动态初始化:type[] arrayName = new type[length];
4.请写出一个合理的数组,并使用foreach循环遍历到控制台。
5.类和对象是什么关系?类的命名规范是什么?
类是一群对象的特征母版,对象是类的具体实例。
类是一群对象的抽象。
类名的定义要符合 Java 的标识符命名规范,类名首字母大写,如果多个单词,使用驼峰命名法则(每个独立单词首字母大写)
6.类的成员有哪些?用于成员变量的修饰符有哪些?
类的三大部件:成员变量、方法、构造器。
修饰符: public protected private static final,其中 public protected private 只允许出现一个
7.成员变量包含哪些?命名规范分别是什么?
成员变量包括类变量和实例变量命名可以包括这4种字符:字母、下划线、$、数字;开头不能是数字;不能是关键字
用 static 修饰的为类变量,非 static 修饰的为实例变量。访问变量的语法:
类.成员变量
实例(对象).成员变量
8.请书写定义方法的语法?
[修饰符] 方法的返回值数据类型 方法名(形参列表) {
方法体语句;
}
9.请书写构造器定义的语法?构造器的用途是什么?
[修饰符] 类名([参数列表]) {}
构造器的最大用处就是创建对象,在调用构造器创建对象的时候,系统会为每个对象的实例变量设置默认值,
通过构造器为成员变量定义初始化值,这也是构造器的最最重要的用途之一
10.请简述你对this的理解?写出使用this调用成员变量、方法、构造器的代码示例。
this 关键字,指向调用该方法的对象。根据 this 所在的位置,大致分为两种:
出现在构造器中:引用该构造器正在初始化的对象;
普通方法中:调用该方法的对象。
this调用成员变量,方法.
this调用构造器
11.方法的参数其实传递的是什么类型的数据?如果传入的是基本数据类型,是否原数据的值会发生改变?如果传入的是引用数据类型呢?阐述原因。
参数的传递都是「值传递」,在调用方法的时候,参数会被创造出一个副本,原本的值是不会改变的。
基本数据类型:方法调用时,实际参数把它的值传递给对应的形式参数,方法执行中形式参数值的改变不影响实际参数的值。
引用数据类型:也称为传地址。方法调用时,实际参数的引用(地址,而不是参数的值)被传递给方法中相对应的形式参数,在方法执行中, 对形式参数的操作实际上就是对实际参数的操作,方法执行中形式参数值的改变将会影响实际参数的值。
如果参数类型是原始类型,那么传过来的就是这个参数的一个副本,如果在函数中改变了副本的值不会改变原始的值.
如果参数类型是引用类型,那么传过来的就是这个引用参数的副本,这个副本存放的是参数的地址。如果在函数中没有改变这个副本的地址,而是改变了地址中的值,那么在函数内的改变会影响到传入的参数。
12.方法签名是什么意思?
方法签名:包含方法名、形参列表。
13.什么是方法重载?
a) private String name;
命名分为三层:
第一层是企业的域名的反写
例如:com.ntqingniao
第二层是企业项目的名称
例如:com.ntqingniao.j96、com.ntqingniao.crm
第三层是企业项目模块的名称
例如:com.ntqingniao.j96.oop、com.ntqingniao.crm.base
17.我们一般在什么情况下使用import语句?如果不使用import语句,有什么其他的解决方案?
使用 import 关键字将本类要使用的其他包中的类进行引入。import 不是必须的,我们可以使用类全名的方式进行类的使用(一般不建议,太麻烦)。
18.访问控制修饰符有哪些?分别的控制范围是什么?
19.对象在创建时的成员变量的默认值分别是什么?
如果是类类型的,没有定义默认值,那么成员变量的值为 null,如果是基本数据,没有定义默认值,那么成员变量的值是有意义的,比如 int 就是 0,boolean 就是 false。
20.请至少写出3个常用的JDK包。
java.lang:包含了 Java 语言的核心类库,如 String、System、Math等等,使用该包下的类是不需要显式引入;
java.util:包含了大量的工具类,如 Date、集合框架;
java.net:Java 网络编程的类和接口包;
java.io:Java 输入输出,如流等方面编程的包;
java.text:格式化方面的类;
java.sql:数据库编程方面的类和接口包;
java.awt:图形用户界面方面的类和接口包。
附加题:编程实现
55岁天秤座的张老师在给南通青鸟教育Java100班的学员上Java课
(提示:需要定义的类包括:老师类、学员类、课程类等等,要运用封装的概念,要有类变量的定义。最后需要通过方法在控制台打印出上述语句)
Teacher类
Student类
Course类
School类
循环结构:
while 循环
- (init_statement);
- while (test_expression) {
- body_statement;
- [iteration_statement];
- }
- (init_statement);
- do {
- body_statement;
- [iteration_statement];
- } while (test_expression)
- for ([init_statement]; test_expression; [iteration_statement]) {
- body_statement;
- }
- for (type element : array | collections) {
- element...
- }
if 语句
- if (logic expression) {
- statement;
- }
- if (logic expression) {
- statement;
- } else {
- statement;
- }
- if (logic expression) {
- statement;
- } else if (logic expression) {
- statement;
- } else {
- statement;
- }
- switch (expression) {
- case condition1 : {
- statement;
- break;
- }
- case condition2 : {
- statement;
- break;
- }
- default : {
- statement;
- break;
- } }
break:在循环体中,使用 break 关键字跳出整个循环。
- int flag = 6;
- int sum = 0;
- for (int i = 1; i <= 10; i++) {
- sum = sum + i;
- if (i == flag) {
- break;
- }
- }
- System.out.println(sum); // 21
- int sum = 0;
- for (int i = 1; i <= 10; i++) {
- if (i % 2 == 0) {
- continue;
- }
- sum = sum + i;
- }
- System.out.println(sum); // 25
静态初始化:int[] arrs = {1, 2, 3, 4};
动态初始化:type[] arrayName = new type[length];
4.请写出一个合理的数组,并使用foreach循环遍历到控制台。
- int[] arrs3={1,3,7,9,11};
- for(int a : arrs3) {
- System.out.println(a);
- }
类是一群对象的特征母版,对象是类的具体实例。
类是一群对象的抽象。
类名的定义要符合 Java 的标识符命名规范,类名首字母大写,如果多个单词,使用驼峰命名法则(每个独立单词首字母大写)
6.类的成员有哪些?用于成员变量的修饰符有哪些?
类的三大部件:成员变量、方法、构造器。
修饰符: public protected private static final,其中 public protected private 只允许出现一个
7.成员变量包含哪些?命名规范分别是什么?
成员变量包括类变量和实例变量命名可以包括这4种字符:字母、下划线、$、数字;开头不能是数字;不能是关键字
用 static 修饰的为类变量,非 static 修饰的为实例变量。访问变量的语法:
类.成员变量
实例(对象).成员变量
8.请书写定义方法的语法?
[修饰符] 方法的返回值数据类型 方法名(形参列表) {
方法体语句;
}
9.请书写构造器定义的语法?构造器的用途是什么?
[修饰符] 类名([参数列表]) {}
构造器的最大用处就是创建对象,在调用构造器创建对象的时候,系统会为每个对象的实例变量设置默认值,
通过构造器为成员变量定义初始化值,这也是构造器的最最重要的用途之一
10.请简述你对this的理解?写出使用this调用成员变量、方法、构造器的代码示例。
this 关键字,指向调用该方法的对象。根据 this 所在的位置,大致分为两种:
出现在构造器中:引用该构造器正在初始化的对象;
普通方法中:调用该方法的对象。
this调用成员变量,方法.
- private String name;
- private int age;
- prviate String code;
- Student1(String name, int age, String code) {
- this.name = name;
- this.age = age;
- this.code = code;
- }
- String intro() {
- return "我叫" + this.name + ",我的学号是" + this.code + ",我今年" + this.age + "岁了。";
- }
- void listen() {
- System.out.println("自我介绍:" + this.intro() + " " + this.name + "在上课。");
- return;
- }
- public Client1(int age, String name) {
- this(age);
- this.name = name;
- }
- public Client1(int age) {
- this.age = age;
- }
参数的传递都是「值传递」,在调用方法的时候,参数会被创造出一个副本,原本的值是不会改变的。
基本数据类型:方法调用时,实际参数把它的值传递给对应的形式参数,方法执行中形式参数值的改变不影响实际参数的值。
引用数据类型:也称为传地址。方法调用时,实际参数的引用(地址,而不是参数的值)被传递给方法中相对应的形式参数,在方法执行中, 对形式参数的操作实际上就是对实际参数的操作,方法执行中形式参数值的改变将会影响实际参数的值。
如果参数类型是原始类型,那么传过来的就是这个参数的一个副本,如果在函数中改变了副本的值不会改变原始的值.
如果参数类型是引用类型,那么传过来的就是这个引用参数的副本,这个副本存放的是参数的地址。如果在函数中没有改变这个副本的地址,而是改变了地址中的值,那么在函数内的改变会影响到传入的参数。
12.方法签名是什么意思?
方法签名:包含方法名、形参列表。
13.什么是方法重载?
如果有两个方法的方法名相同,但参数不一致,那么可以说一个方法是另一个方法的重载。 具体说明如下:14.请分别说明类变量、实例变量、局部变量的生命周期?
方法名相同
方法的参数类型,参数个不一样
方法的返回类型可以不相同
方法的修饰符可以不相同
1,局部变量15.请书写标准的对下面两个成员变量的封装方法:
局部变量是指定义在方法或代码块中的变量,局部变量必须初始化,在方法或代码块内有效,之外则无效,方法执行开始入栈时创建,执行完毕出栈时销毁。
2,实例变量
其作用域受限定符限定,Private的只能在本类中使用,protected子类可用,public任何地方都可用。
生命周期从对象创建开始到对象销毁结束。
3,类变量
类变量是指类的static变量,用类名可以直接访问。生命周期从加载类开始,到销毁类结束。
a) private String name;
- 封装:public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
b)private String getStuCode;
- 封装:public String getStuCode() {
- return stuCode;
- }
- public void setStuCode(String stuCode) {
- this.stuCode = stuCode;
- }
16.在企业开发中包名定义的规范是什么?
第一层是企业的域名的反写
例如:com.ntqingniao
第二层是企业项目的名称
例如:com.ntqingniao.j96、com.ntqingniao.crm
第三层是企业项目模块的名称
例如:com.ntqingniao.j96.oop、com.ntqingniao.crm.base
17.我们一般在什么情况下使用import语句?如果不使用import语句,有什么其他的解决方案?
使用 import 关键字将本类要使用的其他包中的类进行引入。import 不是必须的,我们可以使用类全名的方式进行类的使用(一般不建议,太麻烦)。
18.访问控制修饰符有哪些?分别的控制范围是什么?
private | default | protected | public | |
同一个类 | √ | √ | √ | √ |
同一个包 | √ | √ | √ | |
子类 | √ | √ | ||
全局范围 | √ |
19.对象在创建时的成员变量的默认值分别是什么?
如果是类类型的,没有定义默认值,那么成员变量的值为 null,如果是基本数据,没有定义默认值,那么成员变量的值是有意义的,比如 int 就是 0,boolean 就是 false。
20.请至少写出3个常用的JDK包。
java.lang:包含了 Java 语言的核心类库,如 String、System、Math等等,使用该包下的类是不需要显式引入;
java.util:包含了大量的工具类,如 Date、集合框架;
java.net:Java 网络编程的类和接口包;
java.io:Java 输入输出,如流等方面编程的包;
java.text:格式化方面的类;
java.sql:数据库编程方面的类和接口包;
java.awt:图形用户界面方面的类和接口包。
附加题:编程实现
55岁天秤座的张老师在给南通青鸟教育Java100班的学员上Java课
(提示:需要定义的类包括:老师类、学员类、课程类等等,要运用封装的概念,要有类变量的定义。最后需要通过方法在控制台打印出上述语句)
Teacher类
- package com.dodoke.test02;
- /**
- * 创建教师类
- * @author 26966
- *
- */
- public class Teacher {
- //声明教师的姓名,年龄,星座
- private String name;
- private int age;
- private String constellation;
- //创建构造器
- public Teacher(String name, int age, String constellation) {
- super();
- this.name = name;
- this.age = age;
- this.constellation = constellation;
- }
- public Teacher() {
- super();
- }
- //对属性值封装
- 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;
- }
- public String getConstellation() {
- return constellation;
- }
- public void setConstellation(String constellation) {
- this.constellation = constellation;
- }
- }
- package com.dodoke.test02;
- /**
- * 学生类,属性包括姓名,班级
- * @author 26966
- *
- */
- public class Student {
- private String name;
- private String calss;
- public Student() {
- super();
- }
- public Student(String name, String calss) {
- super();
- this.name = name;
- this.calss = calss;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getCalss() {
- return calss;
- }
- public void setCalss(String calss) {
- this.calss = calss;
- }
- }
- package com.dodoke.test02;
- /**
- * 建立课程类,属性为课程名
- * @author 26966
- *
- */
- public class Course {
- private String name;
- //建立构造器
- public Course() {
- super();
- }
- public Course(String name) {
- super();
- this.name = name;
- }
- //封装
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
- package com.dodoke.test02;
- /**
- * 建立shool类,设定类变量name
- * @author 26966
- *
- */
- public class School {
- static String name="南通青鸟教育";
- //构造器
- public School() {
- super();
- }
- }
Main类
- package com.dodoke.test02;
- /**
- * 建立主类,来输出结果
- * @author 26966
- *
- */
- public class Main {
- public static void main(String[] args) {
- //new 出老师,学员,课程对象
- Teacher zh=new Teacher("张老师",55,"天秤座");
- Student stu=new Student("学员","Java100班");
- Course cou=new Course("Java课");
- //输出结果
- System.out.println(zh.getAge()+"岁"+zh.getConstellation()+"的"
- +zh.getName()+"在给"+School.name+stu.getCalss()+"的"+stu.getName()+"上"+cou.getName());
- }
- }