一些面试题(转)

Object类中有哪些方法?作用是什么?

protected Object clone()创建并返回此对象的一个副本。
boolean equals(Object obj)指示其他某个对象是否与此对象“相等”。
protected void finalize()当垃圾回收器确定不存在对该对象的更多引用时,由对象的垃圾回收器调用此方法。
Class<?> getClass()返回此 Object 的运行时类。
int hashCode()返回该对象的哈希码值。
void notify()唤醒在此对象监视器上等待的单个线程。
void notifyAll()唤醒在此对象监视器上等待的所有线程。
String toString()返回该对象的字符串表示。
void wait()在其他线程调用此对象的 notify() 方法或 notifyAll() 方法前,导致当前线程等待。
void wait(long timeout)在其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者超过指定的时间量前,导致当前线程等待。
void wait(long timeout, int nanos)在其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者其他某个线程中断当前线程,或者已超过某个实际时间量前,导致当前线程等待。

如何读取src目录下的文件?至少两种!

生成一个文件对象:
File file = new File(getClass().getClassLoader().getResource("test.xml").getPath());

直接得到一个输入流:
InputStream in = getClass().getClassLoader().getResourceAsStream("test.xml");

有两个list集合怎么取无重覆并集?

List<String> list1 =new ArrayList<String>();
list1.add("A");
list1.add("B);

List<String> list2 =new ArrayList<String>();
list2.add("B");
list2.add("C");
2.无重复并集
list2.removeAll(list1);
list1.addAll(list2);

运行结果:A, B, C

将系统时间转化为如2017/5/28

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间

请使用反转排序对字符串"CSDHABSDHBSHDB"进行排序

public static String strReverse(String str){
        StringBuffer sb = new StringBuffer(str);
        return sb.reverse().toString();
    }

页面二级菜单如何实现?如 第一个下拉为省  第二个为市

二级菜单
采用ajax异步刷新,将省份值传递给后台,后台根据省份值,查找对应的表,返回该省份对应的市,以JSON字符串返回

如何模拟实现IOC和DI 

IOD  DI        
//获取方法整体转为字符串,
//截取字符串里()中的内容
//使用  ,   分组转为数组
//建立一个用来存放的新数组,循环之前的数组,将对应的值赋予进新数组
//调用执行方法,将参数传递给执行方法,达到控制反转和依赖注入

后台前端页面获取表单数据的方法?

servlet是通过实现HTTPservlet拦截请求,getParameter获取相对性前台的name的值 
mvc是通过注解@RequestMapping实现拦截 参数对应前台name名获取
struts 是以继承ActionSupport来拦截请求,通过对象及属性方式获取

struts2中action是多例还是单例的?

  IOC控制反转  DI 依赖注入  没有控制反转就没有依赖注入,依赖注入只是控制反转的一个特点

struts2中拦截器如何配置

在struts.xml里面配置   拦截器,在交由拦截器栈处理,
或者直接配置多个拦截器配置自己的拦截器栈,配置拦截器栈的执行顺序

ssh和ssm整合思想是什么有哪些jar包

整合思想为 将MVC里的 M和C层交由容器处理,实现对象解耦,容器控制。
spring-struts    spring-hibernate  springMVC  mybatis-spring 

hibernate的缓存原理是什么?延迟加载原理是什么?

缓存原理是为了解决 大量访问数据库对数据库产生压力,采用的session 和sessionFactory缓存

 输入一个表达式,没有括号,数字小于0-9之间,输出计算结果,所有的中间结果化为整形。 例如: 输入:3+8×2/9-2 输出:2

public class PracticeUtil {  
  
    public static void main(String[] args) {  
        String s = "3+8×2/9-2 ";  
        int result = getMyRet(s);  
        System.out.println("最后结果:" + result);  
    }  
  
    public static int getMyRet(String s1) {  
        int len = s1.length();  
        List<String> list = new ArrayList<String>();  
        for (int i = 0; i < len; i++)  
            list.add(s1.charAt(i) + "");  
        System.out.println("list--->" + list);  
        for (int j = 0; j < list.size(); j++) {  
            if (list.get(j).equals("×")) {  
                int ji = Integer.parseInt(list.get(j - 1))  
                        * Integer.parseInt(list.get(j + 1));  
                list.add(j - 1, ji + "");// 把ji插入到原来x的前一位,原来的后移。从8开始往后移  
                list.remove(j);// 删除8;remove是删除当前位置后后面的前移;故x到了j这个下标位置。  
                list.remove(j);// 删除x  
                list.remove(j);// 删除9  
                System.out.println("list--x后->" + list);// list--x后->[3, +, 16,  
                                                        // /, 9, -, 2, ]  
                j--;// 相当于这次循环木有跳动下一个下标,因为马上要对ji参与运算,而不是跳过  
            } else if (list.get(j).equals("/")) {  
                int shang = Integer.parseInt(list.get(j - 1))  
                        / Integer.parseInt(list.get(j + 1));  
                list.add(j - 1, shang + "");  
                list.remove(j);  
                list.remove(j);  
                list.remove(j);  
                System.out.println("list--/后->" + list);// list--/后->[3, +, 1,  
                                                        // -, 2, ]  
                j--;  
            }  
        }  
        for (int k = 0; k < list.size(); k++) {// 这个时候是新的size  
            if (list.get(k).equals("+")) {  
                int he = Integer.parseInt(list.get(k - 1))  
                        + Integer.parseInt(list.get(k + 1));  
                list.add(k - 1, he + "");  
                list.remove(k);  
                list.remove(k);  
                list.remove(k);  
                System.out.println("list--+后->" + list); // list--+后->[4, -, 2,  
                                                            // ]  
                k--;  
            }  
            if (list.get(k).equals("-")) {  
                int cha = Integer.parseInt(list.get(k - 1))  
                        - Integer.parseInt(list.get(k + 1));  
                list.add(k - 1, cha + "");  
                list.remove(k);  
                list.remove(k);  
                list.remove(k);  
                System.out.println("list--  -后->" + list); // list-- -后->[2, ]  
                                                            // k--;  
            }  
        }  
        int sum = Integer.parseInt(list.get(0));  
        return sum;  
    }  
}  

java统计字符串中每个字符出现的次数

public static void count(String str){
        //将字符串转化为字符数组
        char[] chars = str.toCharArray();
        //创建一个HashMap名为hm
        HashMap<Character,Integer> hm = new HashMap();

        //定义一个字符串c,循环遍历遍历chars数组
        for(char c : chars){
            //containsKey(c),当c不存在于hm中
            if(!hm.containsKey(c)){
            hm.put(c,1);
          }else{ 
          //否则获得c的值并且加1
            hm.put(c, hm.get(c)+1);
            }

        //或者上面的if和else替换成下面这一行
        /*  hm.put(c,hm.containsKey(c) ? hm.get(c)+1:1);*/
        }


        for(Character key: hm.keySet()){
            //hm.keySet()代表所有键的集合,进行格式化输出
            System.out.println(key + "====" + hm.get(key));
        }
    }

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        String str = "abcaaaefdabbhg";
        count(str);
    }

}
public static void count(String str){
    //创建26个空间大小的数组,存放26个字母
        int[] nums = new int[26];
        for(char i: str.toCharArray()){
        //自动将char i转化成ascall码
            if(i>=97 && i<= 122){
            //利用数组的索引进行存储
                nums[i-97]++;
            }
        }

        for(int i = 0; i< nums.length; i++){
            if(nums[i] != 0){
                //i加上97并且再转化为char类型就可以显示相应的字符
                char j = (char)(i+97);
                System.out.println( j + "====" + nums[i]);
            }
        }
    }
原文地址:https://www.cnblogs.com/ttzzyy/p/8622749.html