Java选择题(二十四)

1.How should servlet developers handle the HttpServlet’s service() methond when extending HttpServlet?
(当扩展HttpServlet时,servlet开发者应该如何处理HttpServlet的service()方法?)
正确答案: D 你的答案: D (正确)
A.They should override the service()method in most cases;
(大多数情况下,它们应该覆盖service()方法;)
B.They should call the service()method from doGet()or doPost();
(它们应该从doGet()或doPost()调用service()方法;)
C.They should call the service()method from the init()method;
(它们应该从init()方法调用service()方法;)
D.They should override at least one doXXX()method(such as doPost())
(它们应该覆盖至少一个doXXX()方法(比如doPost()))

解释:
开发者在开发servlet继承HttpServlet时如何处理父类的service方法,一般我们都是不对service方法进行重载 (没有特殊需求的话),而只是重载doGet()之类的doXxx()方法,减少了开发工作量。但如果重载了service方法,doXXX()方法也是 要重载的。即不论是否重载service方法,doXXX()方法都是需要重载的。D说至少需要重载doXXX()方法是对的。

2.关于Java以下描述正确的有( )

正确答案: A 你的答案: A (正确)
A.native关键字表名修饰的方法是由其它非Java语言编写的
B.能够出现在import语句前的只有注释语句
C.接口中定义的方法只能是public
D.构造方法只能被修饰为public或者default

解释:
A:native是由调用本地方法库(如操作系统底层函数),可以由C,C++实现,A正确
B:import是用于导包语句,其前面可以出现package,用来声明包的,B错误
C:接口方法的修饰符可以是:public,abstract,default,static(后两者需要有{}),C正确
D:构造方法可以用private,protected,default,private,D错误

3.Given the following code:

public class Test {
    private static int j = 0;
 
    private static boolean methodB(int k) {
        j += k;
        return true;
    }
 
    public static void methodA(int i) {
        boolean b;
        b = i < 10 | methodB(4);
        b = i < 10 || methodB(8);
 
    }
 
    public static void main(String args[]) {
        methodA(0);
        System.out.println(j);
    }
}

What is the result?
正确答案: B 你的答案: E (错误)
A.The program prints”0”
B.The program prints”4”
C.The program prints”8”
D.The program prints”12”
E.The code does not complete.

解释:
这道题主要考的是"|“与”||"的区别
用法:condition 1 | condition 2、condition 1 || condition 2
"|"是按位或:先判断条件1,不管条件1是否可以决定结果(这里决定结果为true),都会执行条件2
"||"是逻辑或:先判断条件1,如果条件1可以决定结果(这里决定结果为true),那么就不会执行条件2

4.JDK中提供的java、javac、jar等开发工具也是用Java编写的。

正确答案: A 你的答案: A (正确)
A.对
B.错

解释:
除了jre中的JVM不是用java实现的,jdk的开发工具包应该都是用java写的

5.关于访问权限说法正确 的是 ? ( )

正确答案: B 你的答案: B (正确)
A.外部类前面可以修饰public,protected和private
B.成员内部类前面可以修饰public,protected和private
C.局部内部类前面可以修饰public,protected和private
D.以上说法都不正确

解释:
1.类指外部类,最大的类,修饰符有public(表示该类在项目所有类中可以被导入),default(该类只能在同一个package中使用),abstract,final
2.内部类指位于类内部但不包括位于块、构造器、方法内,且有名称的类,修饰符有public,private,protected访问控制符,也可以用static,final关键字修饰,public和private比较简单,一个表示所有可以被所有类访问,一个表示只能被自身访问,protected修饰的成员类可以被同一个包中的类和子类访问。而default修饰的成员类只能被同一个包中的类访问。
3.局部内部类指位于块、构造器、方法内的有名称类,最多只能有final修饰

6.假如某个JAVA进程的JVM参数配置如下:
-Xms1G -Xmx2G -Xmn500M -XX:MaxPermSize=64M -XX:+UseConcMarkSweepGC -XX:SurvivorRatio=3,
请问eden区最终分配的大小是多少?

正确答案: C 你的答案: C (正确)
A.64M
B.500M
C.300M
D.100M

解释:
java -Xmx2G -Xms1G -Xmn500M -Xss128k
-Xmx2G:设置JVM最大可用内存为2G。
-Xms1G:设置JVM促使内存为1G。此值可以设置与-Xmx相同,以避免每次垃圾回收完成后JVM重新分配内存。
-Xmn500M:设置年轻代大小为2G。整个JVM内存大小=年轻代大小 + 年老代大小 + 持久代大小。
-XX:SurvivorRatio=3:新生代中又会划分为 Eden 区,from Survivor、to Survivor 区。
其中 Eden 和 Survivor 区的比例默认是 8:1:1,当然也支持参数调整 -XX:SurvivorRatio=3的话就是3:1:1。
故该题为500*(3/5)=300M.

7.下面程序的结果是

public class Demo {
    public static String sRet = "";
    public static void func(int i)
    {
        try
        {
            if (i%2==0)
            {
                throw new Exception();
            }
        }
        catch (Exception e)
        {
            sRet += "0";
            return;
        } 
        finally
        {
            sRet += "1";
        }
        sRet += "2";
    }
    public static void main(String[] args)
    {
        func(1);
        func(2);
        System.out.println(sRet);
    }
}

正确答案: B 你的答案: C (错误)
A.120
B.1201
C.12012
D.101

解释:

  1. 如果finally前面的代码中有return,那么先执行finally中的语句然后再执行return。
  2. 如果finally中的代码也有return,则finally中return的结果会覆盖前面代码中的return结果。

8.在Web应用程序中,( )负责将HTTP请求转换为HttpServletRequest对象

正确答案: C 你的答案: C (正确)
A.Servlet对象
B.HTTP服务器
C.Web容器
D.JSP网页

解释:
web容器是一种服务程序,在服务器一个端口就有一个提供相应服务的程序,而这个程序就是处理从客户端发出的请求,如JAVA中的Tomcat容器,ASP的IIS或PWS都是这样的容器。一个服务器可以多个容器。

9.Java网络程序设计中,下列正确的描述是()

正确答案: A D 你的答案: C D (错误)
A.Java网络编程API建立在Socket基础之上
B.Java网络接口只支持tcP以及其上层协议
C.Java网络接口只支持UDP以及其上层协议
D.Java网络接口支持IP以上的所有高层协议

解释:链接:
UDP Java的java.net包中,提供了两个类DatagramSocket和DatagramPacket来支持UDP的数据报(Datagram)通信 其中DatagramSocket用于在程序之间建立传送数据报的通信通道,DatagramPacket则用来表示一个数据报。DatagramSocket发送的每个包都需要指定地址,而DatagramPacket则是在首次创建时指定地址,以后所有数据的发生都通过此socket。 UDP的客户端编程也是4个部分:建立连接、发送数据、接受数据和关闭连接。TCP Java实现TCP数据传输涉及到的类有Socket、ServerSocket;TCP分客户端服务端,而UDP不分客户端服务端

10.关于抽象类与接口,下列说法正确的有?

正确答案: A C 你的答案: A C (正确)
优先选用接口,尽量少用抽象类
抽象类可以被声明使用,接口不可以被声明使用
抽象类和接口都不能被实例化。
以上说法都不对

解释:

  1. 一个子类只能继承一个抽象类,但能实现多个接口
  2. 抽象类可以有构造方法,接口没有构造方法
  3. 抽象类可以有普通成员变量,接口没有普通成员变量
  4. 抽象类和接口都可有静态成员变量,抽象类中静态成员变量访问类型任意,接口只能public static final(默认)
  5. 抽象类可以没有抽象方法,抽象类可以有普通方法,接口中都是抽象方法
  6. 抽象类可以有静态方法,接口不能有静态方法
  7. 抽象类中的方法可以是public、protected;接口方法只有public
Java 核心技术 卷1 Index Chapter 1: An Introduction to Java 1 Java As a Programming Platform 2 The Java “White Paper” Buzzwords 2 Java Applets and the Internet 7 A Short History of Java 9 Common Misconceptions about Java 11 Chapter 2: The Java Programming Environment 15 Installing the Java Development Kit 16 Choosing a Development Environment 21 Using the Command-Line Tools 22 Using an Integrated Development Environment 25 Running a Graphical Application 28 Building and Running Applets 31 Chapter 3: Fundamental Programming Structures in Java 35 A Simple Java Program 36 Comments 39 Data Types 40 Variables 44 Operators 46 Strings 53 Input and Output 63 Control Flow 71 Big Numbers 88 Arrays 90 Chapter 4: Objects and Classes 105 Introduction to Object-Oriented Programming 106 Using Predefined Classes 111 Defining Your Own Classes 122 Static Fields and Methods 132 Method Parameters 138 Object Construction 144 Packages 15 The Class Path 160 Documentation Comments 162 Class Design Hints 167 Chapter 5: Inheritance 171 Classes, Superclasses, and Subclasses 172 Object: The Cosmic Superclass 192 Generic Array Lists 204 Object Wrappers and Autoboxing 211 Methods with a Variable Number of Parameters 214 Enumeration Classes 215 Reflection 217 Design Hints for Inheritance 238 Chapter 6: Interfaces and Inner Classes 241 Interfaces 242 Object Cloning 249 Interfaces and Callbacks 255 Inner Classes 258 Proxies 275 Chapter 7: Graphics Programming 281 Introducing Swing 282 Creating a Frame 285 Positioning a Frame 288 Displaying Information in a Component 294 Working with 2D Shapes 299 Using Color 307 Using Special Fonts for Text 310 Displaying Images 318 Chapter 8: Event Handling 323 Basics of Event Handling 324 Actions 342 Mouse Events 349 The AWT Event Hierarchy 357 Chapter 9: User Interface Components with Swing 361 Swing and the Model-View-Controller Design Pattern 362 Introduction to Layout Management 368 Text Input 377 Choice Components 385 Menus 406 Sophisticated Layout Management 424 Dialog Boxes 452 Chapter 10: Deploying Applications and Applets 493 JAR Files 494 Java Web Start 501 Applets 516 Storage of Application Preferences 539 Chapter 11: Exceptions, Logging, Assertions, and Debugging 551 Dealing with Errors 552 Catching Exceptions 559 Tips for Using Exceptions 568 Using Assertions 571 Logging 575 Debugging Tips 591 Using a Debugger 607 Chapter 12: Generic Programming 613 Why Generic Programming? 614 Definition of a Simple Generic Class 616 Generic Methods 618 Bounds for Type Variables 619 Generic Code and the Virtual Machine 621 Restrictions and Limitations 626 Inheritance Rules for Generic Types 630 Wildcard Types 632 Reflection and Generics 640 Chapter 13: Collections 649 Collection Interfaces 650 Concrete Collections 658 The Collections Framework 689 Algorithms 700 Legacy Collections 707 Chapter 14: Multithreading 715 What Are Threads? 716 Interrupting Threads 728 Thread States 730 Thread Properties 733 Synchronization 736 Blocking Queues 764 Thread-Safe Collections 771 Callables and Futures 774 Executors 778 Synchronizers 785 Threads and Swing 794 Appendix 809 Index 813 Java 核心技术 卷2 Index Chapter 1: Streams and Files 1 Streams 2 Text Input and Output 11 Reading and Writing Binary Data 23 ZIP Archives 32 Object Streams and Serialization 39 File Management 59 New I/O 65 Regular Expressions 75 Chapter 2: XML 87 Introducing XML 88 Parsing an XML Document 93 Validating XML Documents 105 Locating Information with XPath 129 Using Namespaces 136 Streaming Parsers 138 Generating XML Documents 146 XSL Transformations 157 Chapter 3: Networking 169 Connecting to a Server 170 Implementing Servers 177 Interruptible Sockets 184 Sending E-Mail 191 Making URL Connections 196 Chapter 4: Database Programming 217 The Design of JDBC 218 The Structured Query Language 222 JDBC Configuration 227 Executing SQL Statements 232 Query Execution 242 Scrollable and Updatable Result Sets 254 Row Sets 260 Metadata 263 Transactions 273 Connection Management in Web and Enterprise Applications 278 Introduction to LDAP 279 Chapter 5: Internationalization 297 Locales 298 Number Formats 303 Date and Time 310 Collation 318 Message Formatting 324 Text Files and Character Sets 328 Resource Bundles 329 A Complete Example 333 Chapter 6: Advanced Swing 351 Lists 352 Tables 370 Trees 405 Text Components 442 Progress Indicators 479 Component Organizers 492 Chapter 7: Advanced AWT 521 The Rendering Pipeline 522 Shapes 524 Areas 540 Strokes 542 Paint 550 Coordinate Transformations 552 Clipping 557 Transparency and Composition 559 Rendering Hints 568 Readers and Writers for Images 575 Image Manipulation 585 Printing 601 The Clipboard 635 Drag and Drop 652 Platform Integration 668 Chapter 8: Javabeans Components 685 Why Beans? 686 The Bean-Writing Process 688 Using Beans to Build an Application 690 Naming Patterns for Bean Properties and Events 698 Bean Property Types 701 BeanInfo Classes 710 Property Editors 713 Customizers 723 JavaBeans Persistence 732 Chapter 9: Security 755 Class Loaders 756 Bytecode Verification 767 Security Managers and Permissions 771 User Authentication 790 Digital Signatures 805 Code Signing 822 Encryption 828 Chapter 10: Distributed Objects 841 The Roles of Client and Server 842 Remote Method Calls 845 The RMI Programming Model 846 Parameters and Return Values in Remote Methods 856 Remote Object Activation 865 Web Services and JAX-WS 871 Chapter 11: Scripting, Compiling, and Annotation Processing 883 Scripting for the Java Platform 884 The Compiler API 895 Using Annotations 905 Annotation Syntax 911 Standard Annotations 915 Source-Level Annotation Processing 919 Bytecode Engineering 926 Chapter 12: Native Methods 935 Calling a C Function from a Java Program 936 Numeric Parameters and Return Values 942 String Parameters 944 Accessing Fields 950 Encoding Signatures 954 Calling Java Methods 956 Accessing Array Elements 962 Handling Errors 966 Using the Invocation API 970 A Complete Example: Accessing the Windows Registry 975 Index 991
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风儿吹吹吹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值