




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 Java 语言特点是什么 Java 语言具有如下特性 简单性 面向对象 分布式 解释型 可靠 安全 平台无关 可移植 高性能 多线程 动态性等 2 什么叫 Java 虚拟机 什么叫 Java 平台 Java 虚拟机与 Java 平台的关系如何 Java 虚拟机 Java Virtual Machine 简称 JVM Java 虚拟机是一个想象中的机器 在实际的 计算机上通过软件模拟来实现 Java 虚拟机有自己想象中的硬件 如处理器 堆栈 寄存器 等 还具有相应的指令系统 3 Java 程序是由什么组成的 一个程序中必须有 public 类吗 Java 源文件的命名规则是 怎样的 一个 Java 源程序是由若干个类组成 一个 Java 程序不一定需要有 public 类 如果源文件 中有多个类时 则只能有一个类是 public 类 如果源文件中只有一个类 则不将该类写成 public 也将默认它为主类 源文件命名时要求源文件主名应与主类 即用 public 修饰的类 的类名相同 扩展名为 java 如果没有定义 public 类 则可以任何一个类名为主文件名 当然这是不主张的 因为它将无法进行被继承使用 另外 对 Applet 小应用程序来说 其 主类必须为 public 否则虽然在一些编译编译平台下可以通过 在 BlueJ 下无法通过 但运 行时无法显示结果 4 开发与运行 Java 程序需要经过哪些主要步骤和过程 1 下载 安装 J2SDK 2 设置运行环境参数 JAVA HOME PATH CLASSPATH 3 使用文本编辑器编写原代码如 HelloWorld java 4 运行命令 javac HelloWorld java 编译 HelloWorld java 为 HelloWorld class 5 运行 java HelloWorld 生成 HelloWorld exe 5 怎样区分应用程序和小应用程序 应用程序的主类和小应用程序的主类必须用 public 修 饰吗 Java Application 是完整的程序 需要独立的解释器来解释运行 而 Java Applet 则是嵌在 HTML 编写的 Web 页面中的非独立运行程序 由 Web 浏览器内部包含的 Java 解释器来解 释运行 两者的主要区别是 任何一个 Java Application 应用程序必须有且只有一个 main 方法 它 是整个程序的入口方法 任何一个 Applet 小应用程序要求程序中有且必须有一个类是系统 类 Applet 的子类 即该类头部分以 extends Applet 结尾 应用程序的主类当源文件中只有一个类时不必用 public 修饰 但当有多于一个类时则主类 必须用 public 修饰 小应用程序的主类在任何时候都需要用 public 来修饰 6 安装 JDK 之后如何设置 JDK 系统的 PATH CLASSPATH 他们的作用是什么 1 PATH 环境变量 设置环境变量 path 是因为 window xp 是多用户操作系统 支持不 同用户的个性化系统定制 这里设置的信息只影响当前用户 而不会影响其他用户 假如 只有一个用户 只是运行 class 文件 则也不需要设置 path 环境 因为 JDK 安装之后会把 java exe 等几个关键文件复制到 c windows system32 目录中 而此目录已经存在于 path 变 量 所以说用户变量 path 随不同用户而设置的 设置路径 D jdk1 5 bin PATH 环 境变量作用是指定命令搜索路径 在命令行下面执行命令如 javac 编译 java 程序时 它会 到 PATH 变量所指定的路径中查找看是否能找到相应的命令程序 我们需要把 jdk 安装目 录下的 bin 目录增加到现有的 PATH 变量中 bin 目录中包含经常要用到的可执行文件如 javac java javadoc 等待 设置好 PATH 变量后 就可以在任何目录下执行 javac java 等工具 了 2 CLASSPATH 环境变量 作用是指定类搜索路径 要使用已经编写好的类 前提当然 是能够找到它们了 JVM 就是通过 CLASSPTH 来寻找类的 我们需要把 jdk 安装目录下的 lib 子目录中的 dt jar 和 tools jar 设置到 CLASSPATH 中 当然 当前目录 也必须加入 到该变量中 设置 classpath 环境变量是为了运行一些特殊的 java 程序 如以 jar 为后缀的 文件或者是 javac 运行 java 程序 假如不运行这类程序 也就不必要设置 classpath 环境变 量了 设置方法是 安装 jdk 是的目录为 d jdk1 5 那么就在 变量值 文本框中键入 D jdk1 lib dt jar D jdk1 5 lib tools jar 1 试分析基本数据类型和引用数据类型的基本特点 Java 的基本数据类型都有固定的数据位 不随运行平台的变化而变化 基本数据类型包括 byte int char long float double boolean 和 short 引用类型都是用类或对象实现的 引用数据类型包括 类 数组 接口 基本数据类型和引用类型的区别主要在于基本数据类型是分配在栈上的 而引用类型是分 配在堆上的 不论是基本数据类型还是引用类型 他们都会先在栈中分配一块内存 对于 基本类型来说 这块区域包含的是基本类型的内容 而对于对象类型来说 这块区域包含 的是指向真正内容的指针 真正的内容被手动的分配在堆上 2 分析以下程序段 得到什么打印结果 0 1 1 2 System out println 1 1 System out println 1 31 System out println 2 1 System out println 1 5 true 0 0 boolean d a5 System out println e 0 int f 0 d f 0 System out println f 0 5 编写程序 求两个整数的最大公约数 import java util Scanner public class Gcd Lcm public static void main String args Scanner sc new Scanner System in System out println 输入 2 个数 以 隔开 String str sc next split int m Integer parseInt str 0 int n Integer parseInt str 1 int min m n n m int max m n m n int num1 1 int num2 max for int i min i 0 i if m i 0break while true if num2 m 0 num2 m n num2 2 num2 2 m n System out println 最大公约数 num1 最小公倍数 num2 6 编写程序 打印出如下九九乘法表 1 2 3 4 5 6 7 8 9 1 1 2 2 4 3 3 6 9 4 4 8 12 16 5 5 10 15 20 25 6 6 12 18 24 30 36 7 7 14 21 28 35 42 49 8 8 16 24 32 40 48 56 64 9 9 18 27 36 45 54 63 72 81 public class NineByNineMul public static void main String args System out print for int i 1 i 9 i System out print i System out println System out print for int i 1 i 9 i System out print System out println for int i 1 i 9 i System out print i for int j 1 j i j System out print i j System out println 7 下面代码将输出 one two default int i 1 switch i case 0 System out println zero break case 1 System out println one case 2 System out println two default System out println default 8 下面代码将输出 Equal class EqualsTest public static void main String args char a u0005 String s a 0 x0005L Equal Not Equal System out println s 9 编写程序 对 A 30 1 9 70 25 数组由小到大排序 public class booktest public static void main String args int a 30 1 9 70 25 System out print 数组原始顺序 for int i 0 i a length i System out print a i for int i 0 i a length i int lowerIndex i for int j i 1 j a length j if a j a lowerIndex lowerIndex j int temp a i a i a lowerIndex a lowerIndex temp System out print n 数组排序后的顺序 for int i 0 i a length i System out print a i 10 运行下面代码将输出什么内容 one int i 1 switch i case 0 System out println zero break case 1 System out println one break case 2 System out println two break default System out println default 11 编写程序 求 2 1000 内的所有素数 并按每行 5 列的格式输出 public class PrimeTest public static void main String args int num 2 System out print 2 for int i 3 i 1000 i 2 boolean f true for int j 2 j i j if i j 0 f false break if f continue System out print i if num 5 0 System out println 12 编写程序 生成 100 个 1 6 之间的随机数 统计 1 6 每个数字出现的概率 public class RandomTest public static void main String args int randomnum new int 100 int n new int 6 double a for int i 0 i 100 i a Math random 6 a Math ceil a randomnum i new Double a intValue System out print randomnum i switch randomnum i case 1 n 0 break case 2 n 1 break case 3 n 2 break case 4 n 3 break case 5 n 4 break case 6 n 5 break System out println 以下可改为循环输出 System out println 数字 1 出现的概率 n 0 100 0 100 System out println 数字 2 出现的概率 n 1 100 0 100 System out println 数字 3 出现的概率 n 2 100 0 100 System out println 数字 4 出现的概率 n 3 100 0 100 System out println 数字 5 出现的概率 n 4 100 0 100 System out println 数字 6 出现的概率 n 5 100 0 100 13 编写程序 求 1 2 3 15 public class FactorialSum static int f int x if x 0 return 1 else return x f x 1 public static void main String args int sum 0 for int j 1 j 15 j sum f j System out println sum 14 编写程序 分别用 do while 和 for 循环计算 1 1 2 1 3 1 4 的前 15 项的和 for 循环代码 public class For FactorialSum static int f int x if x 0 return 1 else return x f x 1 public static void main String args double sum 0 for int j 1 j 15 j sum 1 0 f j System out println sum do while 循环代码 public class DoWhile FactorialSum static int f int x if x 0 return 1 else return x f x 1 public static void main String args double sum 0 int j 1 do sum 1 0 f j j while j 15 System out println sum 15 编写一个程序 用选择法对数组 a 20 10 55 40 30 70 60 80 90 100 进行从大到小的 排序 分别采用冒泡排序 选择排序和插入排序方法 public class SortAll public static void main String args int a 20 10 55 40 30 70 60 80 90 100 System out println 冒泡排序的结果 maoPao a System out println System out println 选择排序的结果 xuanZe a System out println System out println 插入排序的结果 chaRu a 冒泡排序 public static void maoPao int x for int i 0 i x length i for int j i 1 j x j int temp x i x i x j x j temp for int i x System out print i 选择排序 public static void xuanZe int x for int i 0 i x length i int lowerIndex i 找出最小的一个索引 for int j i 1 j x length j if x j x lowerIndex lowerIndex j 交换 int temp x i x i x lowerIndex x lowerIndex temp for int i x System out print i 插入排序 public static void chaRu int x for int i 1 i 0 j if x j x j 1 int temp x j x j x j 1 x j 1 temp for int i x System out print i 16 编写程序 产生 30 个素数 按从小到大的顺序放入数组 prime 中 public class PrimeArray public static void main String args int primearry new int 30 primearry 0 2 int num 1 System out print 2 for int i 3 i 1000 i 2 boolean f true for int j 2 j i j if i j 0 f false break if f continue primearry num i System out print i if num 5 0 System out println if num 30 break 17 一个数如果恰好等于它的因子之和 这个数就称为 完数 分别编写一个应用程序 和小应用程序求 1000 之内的所有完数 public class Wanshu public static void main String args int sum 0 i j for i 1 i 1000 i for j 1 sum 0 j i j if i j 0 sum sum j if sum i System out print 完数 i 其因子是 for int k 1 k sum 2 k if sum k 0 System out print k System out println 18 从键盘读取若干个数 以 1 结束 按从小到大的顺序排序 import java util Scanner public class sc num public static void main String args Scanner scanner new Scanner System in int scnum 0 i 0 int scarry new int 30 System out println 输入整数 1 结束 while scnum 1 scarry i scanner nextInt scnum scarry i i xuanZe scarry i 1 选择排序 public static void xuanZe int x int n for int i 0 i n i int lowerIndex i for int j i 1 j n j if x j x lowerIndex lowerIndex j int temp x i x i x lowerIndex x lowerIndex temp for int i 0 i n i System out print x i 1 接口是否可继承接口 抽象类是否可实现 implements 接口 抽象类是否可继承实体类 concrete class 1 接口可以继承接口 但是要使用 extends 而不是用 implements 如 interface a interface b extends a 2 抽象类可以实现接口 比如 java util 中的 AbstractCollection 类就是实现的 Collection 接口 3 抽象类可以继承实体类 下面这段执行无误的代码说明的所有的问题 interface MyInterface interface AnotherInterface extends MyInterface class EntityClass abstract class AbstractClass extends EntityClass implements MyInterface 2 是否可以从一个 static 方法内部发出对非 static 方法的调用 static 方法内部不能直接调用非静态方法 可以在调用之前实例化非静态方法所在的类 再用类点方法来调用 例 非静态方法是 className 类里面的 method className cn new className cn method 这样就可以了 3 HashMap 和 Hashtable 的区别是什么 Hashtable 和 HashMap 的区别 1 Hashtable 是 Dictionary 的子类 HashMap 是 Map 接口的一个实现类 2 Hashtable 中的方法是同步的 而 HashMap 中的方法在缺省情况下是非同步的 即是说 在多线程应用程序中 不用专门的操作就安全地可以使用 Hashtable 了 而对于 HashMap 则需要额外的同步机制 但 HashMap 的同步问题可通过 Collections 的一个静态 方法得到解决 Map Collections synch
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 46075.6-2025电子束焊机验收检验第6部分:束斑位置稳定性的测量
- 大学生心理健康教育 课件 第十一章大学生的网络心理辅导
- 资料员之资料员基础知识能力检测试卷(考点提分)附答案详解
- 2024河北省辛集市中考数学复习提分资料【重点】附答案详解
- 自考专业(建筑工程)考试历年机考真题集【B卷】附答案详解
- 耐药菌感染的预防护理与控制策略
- 2024山东科技职业学院单招《英语》模考模拟试题【学生专用】附答案详解
- 旅游上班合同(标准版)
- 中策职业学校钱塘学校轨道交通虚拟现实驾驶体验中心项目招标文件
- 信息网络运行维护管理规范方案
- XB/T 903-2002烧结钕铁硼永磁材料表面电镀层
- 参军入伍保留学籍申请表(模板)
- 食品安全事故案例课件-002
- 电力客户的分级和分类及管理讲解课件
- 领导干部压力管理与心理调适概论课件
- 表面工程学第十二章-表面微细加工技术
- 基于AI的智能运维解决方案
- 2022年甬统表全套
- 法理学原理与案例完整版教学课件全套ppt教程
- 智能IT运维监控平台解决方案
- 山东大学工程流体力学(杜广生)课件第5章 粘性流体的一维流动
评论
0/150
提交评论