java细节.doc_第1页
java细节.doc_第2页
java细节.doc_第3页
java细节.doc_第4页
java细节.doc_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

l JBS 1.列举出 10个JAVA语言的优势 a:免费,开源,跨平台(平台独立性),简单易用,功能完善,面向对象,健壮性,多线程,结构中立,企业应用的成熟平台, 无线应用 2.列举出JAVA中10个面向对象编程的术语 a:包,类,接口,对象,属性,方法,构造器,继承,封装,多态,抽象,范型 3.列举出JAVA中6个比较常用的包 Java.lang;java.util;java.io;java.sql;java.awt;;java.applet;javax.swing 4.JAVA中的标识符有什么作用和特点 作用:标识符用作给变量、类和方法命名 特点:可以以字母、下划线“_”和”$”符开头 首字符外,可以跟上字母、下划线“_”和”$”符或数字 Java是大小写敏感的,标识符也不例外 5.JAVA中的关键字有什么特点,列举出至少20个关键字 Java中一些赋以特定的含义、并用做专门用途的单词称为关键字(keyword) 所有Java关键字都是小写的,TURE、FALSE、NULL等都不是Java关键字 ; goto和const 虽然从未被使用,但也作为Java关键字保留; 中一共有51个关键字Java abstract assert boolean break byte continue case catch char class const double default do extends else final float for goto long if implements import native new null instanceof int interface package private protected public return short static strictfp super switch synchronized this while void throw throws transient try volatile 6.JAVA中数据类型如何分类? 可分为简单数据类型和引用数据类型: 简单数据类型:数值型(byte,short,int,long,float double),字符型(char),布尔型(boolean); 引用数据类型:类,接口,数组. 7.JAVA中运算符的分类及举例 分割符:,,;,() 算术运算符: +,*,/,%,+, 关系运算符: , =, , 赋值运算符: = 扩展赋值运算符:+=,=,*=,/= 字符串连接运算符: + 造型操作符:() 8.super,this关键字的作用及用法 在Java类中使用super来引用父类的成分 可用于访问父类中定义的属性super 可用于调用父类中定义的成员方法super 可用于在子类构造器中调用父类的构造器super 的追溯不仅于直接父类super 中为解决变量的命名冲突和不确定性问题,引入关键字“this”代表其所在方法的当前对象。Java 构造器中指该构造器所创建的新对象 方法中指调用该方法的对象 关键字的用法this 在类本身的方法或构造器中引用该类的实例变量和方法 将当前对象作为参数传递给其它方法或构造器 用来调用其他的重载的构造器 9.什么是JAVA中的表达式?有什么作用? 表达式是运算符和操作数的结合,它是任何一门编程语言的关键组成部分 表达式允许程序员进行数学计算、值的比较、逻辑操作以及在Java中进行对象的操作。 一些表达式的例子: X X+10 Y=x+10 Arr10 student.geName() 10.做表列出JAVA中所有修饰符和他们的适用范围(能不能修饰构造器,属性,自由块等) class 属性 方法 构建器 自由块 内部类 public Y Y Y Y Y protected Y Y Y Y (Default) Y Y Y Y Y Y private Y Y Y Y final Y Y Y Y abstract Y Y Y static Y Y Y 11.写一个方法,用一个for循环打印九九乘法表 /* *一个for循环打印九九乘法表 */ publicvoid nineNineMultiTable() for (int i = 1,j = 1; j = 9; i+) System.out.print(i+*+j+=+i*j+ ); if(i=j) i=0; j+; System.out.println(); 12.给定一个java.util.Date对象,如何转化为”2007-3-22 20:23:22”格式的字符串 /* *将某个日期以固定格式转化成字符串 *paramdate *returnstr */ public String dateToStr(java.util.Date date) SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss); String str = sdf.format(date); return str; 13.写一个方法,能够判断任意一个整数是否素数 /* *判断任意一个整数是否素数 *paramn *returnboolean */ publicboolean isPrimes(int n) for (int i = 2; i = Math.sqrt(n); i+) if(n%i=0) returnfalse; returntrue; 14.写一个方法,输入任意一个整数,返回它的阶乘 /* *获得任意一个整数的阶乘 *paramn *returnn! */ publicint factorial(int n) /递归 if(n=1) return 1; return n*factorial(n-1); /非递归 / int multi = 1; / for (int i = 2; i = n; i+) / multi*=i; / / return multi; 15.写一个方法,用二分查找法判断任意整数在任意整数数组里面是否存在,若存在就返回它在数组中的索引位置,不存在返回-1 /* *二分查找特定整数在整型数组中的位置(递归) *paramdataset *paramdata *parambeginIndex *paramendIndex *returnindex */ publicint binarySearch(int dataset,int data,int beginIndex,int endIndex) int midIndex = (beginIndex+endIndex)/2; if(data datasetendIndex beginIndexendIndex)return -1; if(data datasetmidIndex) return binarySearch(dataset,data,midIndex+1,endIndex); else return midIndex; /* *二分查找特定整数在整型数组中的位置(非递归) *paramdataset *paramdata *returnindex */ publicint binarySearch(int dataset ,int data) int beginIndex = 0; int endIndex = dataset.length - 1; int midIndex = -1; if(data datasetendIndex beginIndexendIndex)return -1; while(beginIndex = endIndex) midIndex = (beginIndex+endIndex)/2; if(data datasetmidIndex) beginIndex = midIndex+1; else return midIndex; return -1; 16.做一个饲养员给动物喂食物的例子体现JAVA中的面向对象思想,接口(抽象类)的用处 package com.softeem.demo; /* *authorleno *动物的接口 */ interface Animal publicvoid eat(Food food); /* *authorleno *一种动物类:猫 */ class Cat implements Animal publicvoid eat(Food food) System.out.println(小猫吃+food.getName(); /* *authorleno *一种动物类:狗 */ class Dog implements Animal publicvoid eat(Food food) System.out.println(小狗啃+food.getName(); /* *authorleno *食物抽象类 */ abstractclass Food protected String name; public String getName() returnname; publicvoid setName(String name) = name; /* *authorleno *一种食物类:鱼 */ class Fish extends Food public Fish(String name) = name; /* *authorleno *一种食物类:骨头 */ class Bone extends Food public Bone(String name) = name; /* *authorleno *饲养员类 * */ class Feeder /* *饲养员给某种动物喂某种食物 *paramanimal *paramfood */ publicvoid feed(Animal animal,Food food) animal.eat(food); /* *authorleno *测试饲养员给动物喂食物 */ publicclass TestFeeder publicstaticvoid main(String args) Feeder feeder=new Feeder(); Animal animal=new Dog(); Food food=new Bone(肉骨头); feeder.feed(animal,food); /给狗喂肉骨头 animal=new Cat(); food=new Fish(鱼); feeder.feed(animal,food); /给猫喂鱼 17.描述JAVA中异常处理的机制 程序的执行过程中如出现异常,会自动生成一个异常类对象,该异常对象将被提交给Java运行时系统,这个过程称为抛出(throw)异常。Java 当Java运行时系统接收到异常对象时,会寻找能处理这一异常的代码并把当前异常对象交给其处理,这一过程称为捕获(catch)异常。 如果Java运行时系统找不到可以捕获异常的方法,则运行时系统将终止,相应的Java程序也将退出。 程序员通常只能处理违例(Exception),而对错误(Error)无能为力。 问题点数:100 回复次数:251 显示所有回复显示星级回复显示楼主回复 修改 删除 举报 引用 回复 加为好友 发送私信 在线聊天 chaihuoniu 柴火妞 等级: 发表于:2008-06-17 15:26:551楼 得分:0 18.做一个单子模式的类,只加载一次属性文件 package com.softeem.demo; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /* *authorleno *单子模式,保证在整个应用期间只加载一次配置属性文件 */ publicclass Singleton privatestatic Singleton instance; privatestaticfinal String CONFIG_FILE_PATH = E:perties; private Properties config; private Singleton() config = new Properties(); InputStream is; try is = new FileInputStream(CONFIG_FILE_PATH); config.load(is); is.close(); catch (FileNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); publicstatic Singleton getInstance() if(instance=null) instance = new Singleton(); returninstance; public Properties getConfig() returnconfig; publicvoid setConfig(Properties config) this.config = config; l J2SE 19.拷贝一个目录(文件)到指定路径 /* *拷贝一个目录或者文件到指定路径下 *paramsource *paramtarget */ publicvoid copy(File source,File target) File tarpath = new File(target,source.getName(); if(source.isDirectory() tarpath.mkdir(); File dir = source.listFiles(); for (int i = 0; i =money) System.out.println(被取走+money+元!); try Thread.sleep(1000); catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); balance-=money; else System.out.println(对不起,余额不足!); /* *authorleno *银行卡 */ class TestAccount1 extends Thread private Account account; public TestAccount1(Account account) this.account = account; Override publicvoid run() account.withdrawals(800); System.out.println(余额为:+account.getBalance()+元!); /* *authorleno *存折 */ class TestAccount2 extends Thread private Account account; public TestAccount2(Account account) this.account = account; Override publicvoid run() account.withdrawals(700); System.out.println(余额为:+account.getBalance()+元!); publicclass Test publicstaticvoid main(String args) Account account = new Account(); TestAccount1 testAccount1 = new TestAccount1(account); testAccount1.start(); TestAccount2 testAccount2 = new TestAccount2(account); testAccount2.start(); 21.用JAVA中的多线程示例火车站售票问题 package com.softeem.demo; /* *authorleno *售票类 */ class SaleTicket implements Runnable inttickets = 100; publicvoid run() while (tickets 0) sale(); /或者下面这样实现 / synchronized (this) / if (tickets 0) / System.out.println(Thread.currentThread().getName() + 卖第 / + (100 - tickets + 1) + 张票); / tickets-; / / publicsynchronizedvoid sale() if (tickets 0) System.out.println(Thread.currentThread().getName() + 卖第 + (100 - tickets + 1) + 张票); tickets-; publicclass TestSaleTicket publicstaticvoid main(String args) SaleTicket st = new SaleTicket(); new Thread(st, 一号窗口).start(); new Thread(st, 二号窗口).start(); new Thread(st, 三号窗口).start(); new Thread(st, 四号窗口).start(); 22.用JAVA中的多线程示例生产者和消费者问题 package com.softeem.demo; class Producer implements Runnable private SyncStack stack; public Producer(SyncStack stack) this.stack = stack; publicvoid run() for (int i = 0; i stack.getProducts().length; i+) String product = 产品+i; stack.push(product); System.out.println(生产了: +product); try Thread.sleep(200); catch(InterruptedException e) e.printStackTrace(); class Consumer implements Runnable private SyncStack stack; public Consumer(SyncStack stack) this.stack = stack; publicvoid run() for(int i=0;i + stu); ois.close(); s.close(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); catch (ClassNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); class MyServer extends Thread Override public void run() try ServerSocket ss = new ServerSocket(9999); Socket s = ss.accept(); ObjectOutputStream ops = new ObjectOutputStream(s.getOutputStream(); Student stu = new Student(1, 赵本山); ops.writeObject(stu); ops.close(); s.close(); ss.close(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); public class TestTransfer public static void main(String args) new MyServer().start(); new MyClient().start(); l JDBC 24.用dom4j组件解析如下XML格式的文件: aaa 123 1 bbb 444 4 规则: operation 1表insert,2表update,3表delete. handle 1表作为where条件,0表作为操作字段。 要求:按

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论