面试题

 

1、        类成员有几种访问权限?各是什么含义?默认是什么权限?

 

public:  所有成员都可以访问。

Protectd :同包的和不同包的子类可以访问。

Friendly   同包可以访问。

private:  只有自身可以使用。

M默认是 Friendly  

2、        类有几种访问权限?各是什么含义?public权限的类有什么要求?

有两种 public 所有类都能访问。

  缺省 friendly 同包可以访问。

要求:一个源文件中只有有一个public类,不算内部类。 文件名和类名要相同

3、        下面语句有错吗?如果有错,错在哪里,如何修改?

classBase

{

  int iValue0;

  Base(int i) {iValue0=i;}

}

 

classDerive extends Base

{

intiValue1;

  Derive(int i) { iValue0=i;  iValue1=2*i;}

}

Derive(int i) { iValue0=i;  iValue1=2*i;}

这里错了,改为

Derive(int i) {super(i); iValue0=i;  iValue1=2*i;}

或者 在Base加上 无参构造

 

4、        下面的输出是什么?

Strings1 = "abc";

Strings2 = "abc";

String s3 = new String("abc");

String s4 = new String("abc");

System.out.println(s1==s2);  true

System.out.println(s2==s3);false

System.out.println(s3==s4);false

System.out.println(s4==s1); false

System.out.println(s1.equals(s2)); true

System.out.println(s2.equals(s3)); true

System.out.println(s3.equals(s4)); true

System.out.println(s4.equals(s1)); true

5、        实现类的static方法的时候有什么限制?为什么?

Static 方法 只能调用 static 的方法或者static的变量。因为不是static的方法 要实例化。不能直接访问。

 

6、        关键字:final,finally,finalize都是用在什么地方的?

 final 用在声明方法和类,方法不可覆盖,类不可继承,内部类要访问局部变量,局部变量必须定义成final类型

finally用在异常处理语句,总是执行。

finalizeObject类的一个方法,垃圾回收器回收对象会调用。

7、        为什么对String进行一些操作的时候,往往是使用StringBuilder或者StringBuffer?

应为StringBuilder或者StringBuffer不会新建字符串。直接拼接。

8、        下面输出是什么?

byteb=2;

bytee=3;

bytef=b+e;

System.out.println(f);

有错,要强制转为 byte才行。 输出 为5 。byte运算 java会把它先转换为int类型

9、  给定下面的字符串定义:  String s = "Story";   以下哪个表达式是合理的?

A)s+=5;  B) char c=s[1]; C) intlen=s.length;   D) String t=s.toLowerCase

       A D

 

10、     下面哪句有错误?为什么?

class A

{

  intm_a;

  classB {

         publicB(){ m_a = 3; }

  };

  B   CreateB()   {  return new B(); }

}

 

class C

{

  test()

  {

         A.Bab ;

         A    a = new A();

        

         ab= new A.B();

         ab= a.CreateB();

ab =a.new B();

         ab= new a.B();

  }

}

test( ) 要加修饰符

ab = new A.B();正确的:ab = new A().new B(); 创建内部类对象  要先有外部类。

ab = new a.B(); 正确的为ab =  a.newB();

 

11、     Java的类有析构函数吗?为什么没有?finalize()函数在何时会被调用到?为什么需要finalize()函数?

没有析构函数,java有自己的回收机制。

finalize()函数会在gc回收对象时候调用。可以在此方法中自己控制去释放其他资源。

12、     一个比较复杂的类,创建对象的时候,按照什么顺序完成如下工作?

A、调用本类的构造函数

B、按照声明的顺序调用成员的初始化方法

C、调用父类构造函数

C  A  B

13、     List,Set,Queue有什么共性,各自有什么特点?各举一个实现他们的具体类。

 共性:都是Collection的子接口。

List:可以存储不同类型的对象。长度可变。可重复  如 ArrayList ,LInkedList

Set:元素无序,不可重复  如 hashSet

Queue:先进先出的队列。 LinkedList。ArrayBlockingQueue

14、     写一个捕获异常的程序样例,要带有finally部分的

 try {

     

    } catch (Exception e) {

   

    }finally{

     

    }

15、     Executor的作用是什么?其方法newCachedThreadPool,newFixedTreadPool,newSingleThreadPool各有什么特点?

Executor :管理任务

newCachedThreadPool:创建一个不固定的缓存线程池。

newFixedTreadPool:. 创建固定大小的线程池

newSingleThreadPool:创建 单一的线程池

16、     关键字synchronized修饰类的方法时的作用,synchronized起作用的内部机制是什么?

实现同步。  锁机制有 对象锁  , class 锁

17、     如何创建一个临界区?

 public synchronizedvoid   method() {}

 synchronized(Object){}

 

18、     一个任务在调用一个类的方法的时候,分别遇到 sleep(), wait(),yield()函数的时候,哪个会导致这个对象的锁被释放?

Wait()

19、      下面语句哪里不合法?为什么?合法语句的输出是什么?

classBase

{

  private void funPrivate()

  {System.out.println("Base:funPrivate");}              //(1)

 

  private void funPublic()

  {System.out.println("Base:funPublic");}        //(2)

 

  final public void funPublicFinal() 

  {System.out.println("Base:funPublicFinal");}       //(3)

}

 

classDerive extends Base

{

  private void funPrivate()

  {System.out.println("Derive:funPrivate");}           //(4)

 

  public void funPublic()

  {System.out.println("Derive:funPublic");}            //(5)

 

  public void funPublicFinal() 

  {System.out.println("Derive:funPublicFinal");}    //(6)

}

 

publicclass test

{

 

  public static void main(String[] args)

  {

         Derive d=new Derive();

         Base b=d;

        

         d.funPrivate();                 //(7)

         d.funPublic();                   //(8)

         d.funPublicFinal();           //(9)

        

         b.funPrivate();                 //(10)

         b.funPublic();                   //(11)

         b.funPublicFinal();           //(12)

  }

}

       6行。Final 方法不能被override

       7行:private 只能在本类当中才能访问。外部不可访问。

       10、11行:父类的方法为私有的方法。子类不能override,子类的和他重名的方法,不是ovverride父类的,是子类本身的方法。此时调用的是父类的方法。这2个方法 都是私有的。不能被访问。

 

合法的输出结果:

Derive: funPublic   Base: funPublicFina   Base: funPublicFinal

20、      程序性能优化有哪些方法?讲讲你的经验?

循环 不做增删。使用 foreach

根据需求 设计程序。使用设计模式。搭建框架。

重用对象。尽量使用局部变量

不要重复初始化变量

尽量不要使用 枚举 浮点

不要在循环中创建对像。和使用 try catch

使用StringBuffer操作字符串。

复制使用 system.arraycopy

ListView 复用 convertview,使用viewholder

使用 线程池 去维护 线程。

耗时任务放在子线程去操作。

及时释放无用的资源。

Android 不使用 get set方法。

 

等等

21、      OOM问题如何处理?讲讲你的经验?

不用的对象置null,进行释放。不要在循环中创建过多的本地变量。不要用static引用一些资源耗费过多的实例。

显示网络的图片可是先显示缩略图。

显示大图。加载到内存前,先算出bitmap的大小,然后通过调节采样率,根据屏幕的大小进行设置。

使用SoftReferenceWeakReference进行二级缓存。

不用的图片及时释放。

以时间或空间

Cursor不用要及时释放。

ListView 使用缓存 currentView、等等

22、      常见Java 数据结构有哪些?插入、删除、查找效率如何?

数组:插入快, 删除 查找慢

栈:插入  删除快。查找慢

队列:插入  删除快。查找慢

链表:插入,删除 快。 查找慢。

二叉树:插入、删除、查找

堆:插入删除 快。

哈希表:插入快查找快

算法和程序设计

1、       使用LinkedList实现一个栈,有pop,push,peek,empty函数

Public class Strack<T>{

private LinkedList<T> s;

public Strack (){

s = new LinkedList<T>();

}

Public Tpop(){

 If(empty()){

Return null;

}else{

Retrun s.removeFrist();

}

}

 

Pubic void push(T t){

 s.addFrist(t);

}

Public T peek(){

If(empty()){

Return null;

}else{

Return s.getFrist();

}

}

Public Boolean empty(){

Return s.isEmpty();

}

2、       使用LinkedList实现一个BlockingQueue

Publicclass BlockingQueue<T>{

privateLinkedList<T> s;

publicBlockingQueue (){

s= new LinkedList<T>();

}

Publicvoid add(T t){

s.addFirst(t);

}

PublicT get(){

Returns.removeLast();

}

 

 Public Boolean empty(){

Returns.isEmpty();

}

 

3、       写一个二叉树广度优先遍历的程序

 public class Tree {

  public static Queue<Tree> que = newLinkedList<Tree>();

  public int data;

  public Tree leftNode = null;

  public Tree rightNode = null;

  public Tree temp = null;

  public Tree() {

    data = new Random().nextInt(20);

  }

 

  public void display() {

    System.out.print(data + ",");

  }

  public void initTree(int count) {

    que.add(this);

    while ((temp = que.poll()) != null) {

      if (count - 2 > 0) {

        temp.leftNode = new Tree();

        que.add(temp.leftNode);

        count--;

        temp.rightNode = new Tree();

        que.add(temp.rightNode);

        count--;

      } else if (count == 0) {

        break;

      } else if (count == 1) {

        temp.leftNode = new Tree();

        count--;

        break;

      } else {

        temp.leftNode = new Tree();

        temp.rightNode = new Tree();

        count -= 2;

      }

 

    }

  }

广度优先遍历

  public void bianLi() {

    que.clear();

    que.add(this);

    while ((temp = que.poll()) != null) {

      temp.display();

      if (temp.leftNode != null) {

        que.add(temp.leftNode);

      }

      if (temp.rightNode != null) {

        que.add(temp.rightNode);

      }

    }

  }

}

4、       实现一个单向链表反转程序(不考虑多线程)

反转方法

publicvoid turn() {

    last.next = head;

    head = last;

   

    for (int i = 1; i < size(); i++) {

      get(size()).next = get(i).next;

      get(i).next = get(size());

    }

    get(size()).next = null;

  }

 

 

 public class LinkedList {

  Node head = null;

  Node last = null;

  int size = 0;

 

  public void add(Object o) {

    Node n = new Node(o, null);

    if (head == null) {

      head = n;

      last = n;

    }

    last.next = n;

    last = n;

    size++;

  }

 

  public int size() {

    return size;

  }

 

  public Node get(int index) {

    Node node = head;

    int i = 1;

    // 找到第index

    while (node != null && i <index) {

      node = node.next;

      i++;

    }

    return node;

  }

 

  public void turn() {

    last.next = head;

    head = last;

   

    for (int i = 1; i < size(); i++) {

      get(size()).next = get(i).next;

      get(i).next = get(size());

    }

    get(size()).next = null;

  }

 

}

 

5、       实现一个生产者消费者模型

 public class PublicResource {

  Lock lock = new ReentrantLock();

  Condition condition1 = lock.newCondition();

  public int number = 0;

 

  /**

   * 生产

   */

  public void put() {

    lock.lock();

    try {

        while (number == 2) {

          try {

            condition1.await();

          } catch (InterruptedException e) {

            e.printStackTrace();

          }

        }

        number++;

        System.out.println("生产 = "+number);

        condition1.signal();

    } catch (Exception e) {

    }finally{

      lock.unlock();

    }

 

  }

 

  /**

   * 消费

   */

  public void take() {

    lock.lock();

    try {

      while (number == 0) {

        try {

          condition1.wait();

        } catch (InterruptedException e) {

          e.printStackTrace();

        }

      }

      number--;

      System.out.println("消费 = "+number);

      condition1.signal();

    } catch (Exception e) {

      // TODO: handle exception

    }finally{

      lock.unlock();

    }

  

  }

}

内容概要:本书《Deep Reinforcement Learning with Guaranteed Performance》探讨了基于李雅普诺夫方法的深度强化学习及其在非线性系统最优控制中的应用。书中提出了一种近似最优自适应控制方法,结合泰勒展开、神经网络、估计器设计及滑模控制思想,解决了不同场景下的跟踪控制问题。该方法不仅保证了性能指标的渐近收敛,还确保了跟踪误差的渐近收敛至零。此外,书中还涉及了执行器饱和、冗余解析等问题,并提出了新的冗余解析方法,验证了所提方法的有效性和优越性。 适合人群:研究生及以上学历的研究人员,特别是从事自适应/最优控制、机器人学和动态神经网络领域的学术界和工业界研究人员。 使用场景及目标:①研究非线性系统的最优控制问题,特别是在存在输入约束和系统动力学的情况下;②解决带有参数不确定性的线性和非线性系统的跟踪控制问题;③探索基于李雅普诺夫方法的深度强化学习在非线性系统控制中的应用;④设计和验证针对冗余机械臂的新型冗余解析方法。 其他说明:本书分为七章,每章内容相对独立,便于读者理解。书中不仅提供了理论分析,还通过实际应用(如欠驱动船舶、冗余机械臂)验证了所提方法的有效性。此外,作者鼓励读者通过仿真和实验进一步验证书中提出的理论和技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值