http://blog.csdn.net/qiyuexuelang/article/details/8823225
填空选择类
shot(短整型) 16 -32768 - 32768 0
int(整型) 32 -2147483648-2147483648
0 long(长整型) 64 -9233372036854477808-9233372036854477808 0
float(浮点型) 32 -3.40292347E+38-3.40292347E+38 0.0f double(双精度) 64 -1.79769313486231570E+308-1.79769313486231570E+308 0.0d
char(字符型) 16 ‘ \u0000 - u\ffff ’ ‘\u0000 ’
boolean(布尔型) 1 true/false false
注意:string不是基本数据类型
2.Integer是java提供的封装类 int是原始类型; Integer的 缺省值 null int的缺省值 0
3.string类提供了数值不变的字符串, 如果操作少量数据用string
而stringBuffer类提供的字符串可修改(动态),多线程操作字符串缓冲区下操作大量数据
4.ArrayList、Vector使用数组存储数据,索引快插入慢
Vector同步线程安全,ArrayList不是线程安全;
Vector在需要增长时默认增长方式为原来的一倍,而ArrayList为原来的一半
LinkedList使用双向链表存储,索引难插入快
5.sleep()线程类方法,导致此线程暂停执行时间,但监控状态依然保持,到时自动恢复 占用CPU
wait()Object类方法,对对此对象调用wait()方法导致线程放弃对象锁,只有对此对象发出 notify()方法后,本线程才进入对象锁对其进行执行。
6.java中以unicode编码,一个char占16个字节,故能放一个中文
7.java常见的类型流:字节流Input/OutputStream 字符流Reader Writer
8.常见的runtime exception:ArrayStoreException BufferOverflowException ClassNotFoundException NumberFormatException IndexOutOfBoundsExceptio n
NullPointerException NoSuchElementException
9.java常用包:java.io.*;java.util.*;java.long.*;java.net.*;java.sql.*;javax.servlet;
java常用类:BufferedReader BufferedWriter FileReader String Integer java.util.Date
system Class List HashMap
java常用接口:Romote List Map Document Modelist Servlet HttpServletRequest HttpServletResponse session
10.switch 作用类型char byte int short
11.Class类是由java编译器自动产生,它伴随着每个类
任何一个java程序都默认引入一个包,这个包叫java.long
java语言中,所有类或接口的父类 java.long.Object
12.java实现序列化的方法是 实现java.io.Serializable
13.Collection框架实现比较要实现 Comparable接口和Comparator接口
14.在try-catch-finally语句中,System.exit()是干掉finally的最佳办法
-
判断改正类
-
比较问答类
栈是一种线性集合,其删除和添加元素的操作应该在同一时间完成。按先进后出的方式处理
堆是栈的一个组成
织 (Object Management Group,缩写为 OMG)标准化。它的组成是接口定义语言(IDL), 语言绑定 (binding: 也译为联编)和允许应用程序间互操作的协议。 其目的为: 用不同的程序设计语言书写 在不同的进程中运行 为不同的操作系统开发 12. 谈谈final, finally, finalize的区别。
final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。finally是异常处理语句结构的一部分,表示总是执行。finalize是 Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。
13. Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实 现)interface(接口)?
-
代码编写类
- public String translate (String str){
- String tempStr = "";
- try{
- tempStr = new String(str.getBytes("ISO-8859-1"),"GBK");
- tempStr = tempStr.trim();
- }catch(Exceptione){
- out.print(e.getMessage());
- }
- return tempStr;
- }
- public class CharuSort {
- public static void main(String[] args){
- int[] sort={4,6,3,9,5};
- Sort(sort);
- for(int i=0;i<sort.length;i++)
- System.out.print(sort[i]+" ");
- }
- public static void Sort(int[] sort){
- int i; //为扫描次数
- int j; //定为比较得元素
- for(i=1;i<sort.length;i++){ //扫描次数为sort.length-1
- int temp; //temp用来暂存数据
- temp=sort[i];
- j=i-1;
- while(j>=0&&temp<sort[j]){ //如果第二个元素小于第一个元素
- sort[j+1]=sort[j]; //把所有的元素往后推一个位置
- j--;
- }
- sort[j+1]=temp; //最小的元素放到第一个位置
- }
- }
- }
- public class BubbleSort {
- private static int c =0;//执行次数
- public static void main(String[] args) {
- int[] a = {60,1 , 35 ,32, 44 , 321 };
- sort(a);
- System.out.println(c);
- for(int i:a){
- System.out.print(i+" ");
- }
- }
- public static void sort(int[] array) {
- int length = array.length;
- int temp;
- boolean isSort;
- for(int i = 1; i < length; i++) {
- c++;
- isSort = false;
- for(int j = 0; j < length - i; j++) {
- if(array[j] > array[j+1]) {
- //交换
- temp = array[j];
- array[j] = array[j+1];
- array[j+1] = temp;
- isSort = true;
- }
- }
- if(!isSort) break; //如果没有发生交换,则退出循环
- }
- }
- }
服务器端:
客户端:
- package test;
- import java.net.*;
- import java.io.*;
- public class Server
- {
- private ServerSocket ss;
- private Socket socket;
- private BufferedReader in;
- private PrintWriter out;
- public Server()
- {
- try
- {
- ss=new ServerSocket(10000);
- while(true)
- {
- socket = ss.accept();
- String RemoteIP = socket.getInetAddress().getHostAddress();
- String RemotePort = ":"+socket.getLocalPort();
- System.out.println("A client come in!IP:"+RemoteIP+RemotePort);
- in = new BufferedReader(new
- InputStreamReader(socket.getInputStream()));
- String line = in.readLine();
- System.out.println("Cleint send is :" + line);
- out = new PrintWriter(socket.getOutputStream(),true);
- out.println("Your Message Received!");
- out.close();
- in.close();
- socket.close();
- }
- }catch (IOException e)
- {
- out.println("wrong");
- }
- }
- public static void main(String[] args)
- {
- new Server();
- }
- };
- package test;
- import java.io.*;
- import java.net.*;
- public class Client
- {
- Socket socket;
- BufferedReader in;
- PrintWriter out;
- public Client()
- {
- try
- {
- System.out.println("Try to Connect to 127.0.0.1:10000");
- socket = new Socket("127.0.0.1",10000);
- System.out.println("The Server Connected!");
- System.out.println("Please enter some Character:");
- BufferedReader line = new BufferedReader(new
- InputStreamReader(System.in));
- out = new PrintWriter(socket.getOutputStream(),true);
- out.println(line.readLine());
- in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- System.out.println(in.readLine());
- out.close();
- in.close();
- socket.close();
- }catch(IOException e)
- {
- out.println("Wrong");
- }
- }
- public static void main(String[] args)
- {
- new Client();
- }
- };
- Double i = Math.random();
- int b = (int)(Math.random()*1000); //0-1000的整随机数
- int c = (int)(Math.random()*(max-min)+min); //产生于两整数间的随机数
- public class Singleton {
- private Singleton(){}
- //在自己内部定义自己一个实例,是不是很奇怪?
- //注意这是private 只供内部调用
- private static Singleton instance = new Singleton();
- //这里提供了一个供外部访问本class的静态方法,可以直接访问
- public static Singleton getInstance() {
- return instance;
- }
- }
- package test;
- public class Search2 {
- public static void main(String[] args) {
- int [] a = new int[]{12,34,44,54,120,131};
- int result = searchByTwo(a,0,a.length-1,120);
- if(result ==-1){
- System.out.println("未找到");}
- else{
- System.out.println("该数据所在位置"+(result+1));
- }
- }
- public static int searchByTwo(int[] array ,int l0,int hi,int x){
- //当a[i] = x,并且i>=0时,返回i,否则返回-1
- if(l0 > hi){
- return -1;
- }
- int i = (l0+hi)/2;
- if(array[i]==x){
- return i;
- }else if(array[i]<x){
- return searchByTwo(array,i+1,hi,x);
- }else{
- return searchByTwo(array,l0,i-1,x);
- }
- }
- }
- public class Hanoi {
- public static void main(String[] args) {
- //汉诺塔
- /*
- 三步走战略:
- 1.将柱x上较小的n-1个盘移到柱Z
- 2.将柱x上的剩余盘移到柱y
- 3.将柱z上的n-1个盘移到柱y
- */
- runHanoi(4, 'A', 'B', 'C');
- }
- public static void runHanoi(int n,char x,char y,char z){
- if(n==1){
- System.out.println("move top disk from peg " + x+" to peg "+z);
- }else {
- runHanoi(n-1,x,z,y);
- runHanoi(1,x,y,z);
- runHanoi(n-1,y,x,z);
- }
- }
- }
- package test;
- public class LongAdd {
- public static String doAdd(String str1,String str2){
- String str ="";//相加后的字符串
- String strTmp = ""; //补零对齐
- int jw = 0; //进位
- int temp; //每一位相加的结果
- int len1 = str1.length();
- int len2 = str2.length();
- int maxLength = (len1>len2)?len1:len2;
- int minLength = (len1<len2)?len1:len2;
- for(int i =maxLength-minLength;i>0;i++){
- strTmp += "0";
- }
- if(maxLength == len1){
- str2 = strTmp +str2;
- }else{
- str1 = strTmp +str1;
- }
- for(int i =maxLength-1;i>=0;i--){
- int temp1 = Integer.parseInt(String.valueOf(str1.charAt(i)));
- int temp2 = Integer.parseInt(String.valueOf(str2.charAt(i)));
- if(temp1+temp2+jw>=10&&i!=0){
- temp = temp1+temp2+jw-10;
- jw = 1;
- }else{
- temp = temp1+temp2+jw;
- jw = 0;
- }
- str = String.valueOf(temp)+str;
- }
- return str;
- }
- public static void main(String[] args) {
- String str1 = "1234567890123456789";
- System.out.println("str1:\n"+str1);
- System.out.println("result:\n"+doAdd(str1,str1));
- }
- }
- public class ThreadTest1{
- private int j;
- public static void main(String args[]){
- ThreadTest1 tt=new ThreadTest1();
- Inc inc=tt.new Inc();
- Dec dec=tt.new Dec();
- for(int i=0;i<2;i++){
- Thread t=new Thread(inc);
- t.start();
- t=new Thread(dec);
- t.start();
- }
- }
- private synchronized void inc(){
- j++;
- System.out.println(Thread.currentThread().getName()+"-inc:"+j);
- }
- private synchronized void dec(){
- j--;
- System.out.println(Thread.currentThread().getName()+"-dec:"+j);
- }
- class Inc implements Runnable{
- public void run(){
- for(int i=0;i<100;i++){
- inc();
- }
- }
- }
- class Dec implements Runnable{
- public void run(){
- for(int i=0;i<100;i++){
- dec();
- }
- }
- }
- }
1.计算文件/文件夹的大小(M)
2.判断操作对象为文件OR文件夹,如果是文件,输出文件内容
否则列出该文件夹下所有目录
- public static void main(String[] args) throws Exception
- {
- getFile(new File("C:\\entityBean"),"\t");
- }
- public static void getFile(File f,String sem) throws Exception
- {
- System.out.println(sem+f.getName());
- File fl[]=f.listFiles();
- if(fl.length>=1)
- {
- for(int i=0;i<fl.length;i++)
- {
- if(fl[i].isDirectory())
- {
- getFile(fl[i],sem+"\t");
- }
- }
- }
- }
- package test.hello;
- public class AllCombString {
- public static int t;//组合个数
- public static void main(String[] args) {
- String str = "abcdefg";
- char[] c = str.toCharArray();
- t++;
- allCombString(c,0);
- System.out.println(t);
- }
- public static void allCombString(char[] c,int s){
- int l = c.length;
- if(l-s==2){
- char temp = c[l-1];
- c[l-1] = c[l-2];
- c[l-2] = temp;
- println(c);
- t++;
- }
- else{
- for(int i=s;i<l;i++){
- moveToHead(c,i,s);
- char ct[] = new char[l];
- System.arraycopy(c, 0, ct, 0, l);//保持其他元素位置不变
- allCombString(ct,s+1);
- }
- }
- }
- public static void moveToHead(char[] c,int id,int s){
- if(id>s&&id<c.length){
- char temp = c[id];
- for(int i=id;i>s;i--){
- c[i] = c[i-1];
- }
- c[s] = temp;
- println(c);
- t++;
- }
- }
- public static void println(char[] c){
- System.out.println(new String(c));
- }
- }
16.请在下面程序相应位置填充合适代码,实现提示功能
public class RightDemo {
public static void main(String[] args) {
int i = 0;
{
//添加一段代码使得控制台输出right
}
if (i + 1 < i) {
System.out.println("right");
} else {
System.out.println("wrong");
}
}
}
public static void main(String[] args) {
int i = 0;
{
//添加一段代码使得控制台输出right
}
if (i + 1 < i) {
System.out.println("right");
} else {
System.out.println("wrong");
}
}
}
- i = Integer.MAX_VALUE;//
java中int占4个字节,存储范围为--214783648 ~- +214783647, 214783647+1会产生溢出,使符号位由0变1,即负数最小值
相关链接 :java 面试