对于以下代码,表达式的值为true的是 String str1="java"; String str2="java"; String str3=new String("java"); StringBuffer str4=new StringBuffer("java");
A.str1==str2
B.str1==str4
C.str1==str3
D.str3==str4
第1题:
有如下applet代码:
import java.applet.*;
import java.awt.*;
public class MyApplet extends Applet
{
AA s;
public void int()
{
s = new AA("Hello!", "I love JAVA.");
}
public void paint(Graphics g)
{
g.drawString(s.toString(), 30, 50);
}
}
class AA
{
String s1;
String s2;
AA(String str1, String str2)
{
s1 = str1;
s2 - str2;
}
public String toString()
{
return s1 + s2;
}
}
运行后,窗口上将会出现什么,选择一个正确答案______。
A.Hello!
B.I love JAVA.
C.Hello! I love JAVA.
D.什么都没有
第2题:
在Java中,字符串由java.lang.String和( )定义。
A.java.lang.StringChar
B.java.lang.StringBuffer
C.java.io.StringChar
D.java.io.StringBuffer
第3题:
A.When using versions of Java technology earlier than 5.0.
B.When sharing a StringBuffer among multiple threads.
C.When using the java.io class StringBufferInputStream.
D.When you plan to reuse the StringBuffer to build more than one string.
第4题:
下列关于字符串的叙述错误的是( )。
A.创建String类的字符串对象后,字符串所代表的内容根据情况可改变
B.字符串可以使用java.lang.String和java.lang.StringBuffer来定义
C.StringBuffer用来处理长度可变的字符串
D.在Java语言中,字符串是作为对象来处理的
第5题:
阅读以下说明和Java代码,回答问题
[说明]
在某些系统中,存在非常复杂的对象,可以采用循序渐进的方式进行组合将小对象组合,成复杂的对象。
以下实例展示了Builder(生成器)模式。该实例用来建立“文件”,文件内容包括:一个标题、一串字符以及一些有项目符号的项目。Builder类规定组成文件的方法,Director类利用这个方法产生一份具体的文件。图6-1显示了各个类间的关系。
以下是Java语言实现,能够正确编译通过。
[Java代码]
//Builder. java文件
public (1) class Builder {
public abstract void makeTitle(String title);
public abstract void makeString(String str);
public abstract void makeItems(String[] items);
public abstract Object getResult();
}
//Director. java文件
public class Director{
private (2) builder;
public Director(Builder builder){
this. builder = builder;
}
public Object construct(){
builder.makeTitle("Greeting");
builder.makeString("从早上到白天结束");
builder.makeItems(new String[]{"早安", "午安",});
builder.makeString("到了晚上");
builder.makeItems(new String[]("晚安", "好梦",});
return builder.getResult();
}
}
//TextBuilder.java文件
public class TextBuilder (3) Builder{
private StringBuffer buffer = new StringBuffer();
public void makeTitle(String title){
buffer.append("『" + title + "』"\n\n");
}
public void makeString(String str){
buffer.append('■' + str + "\n\n ");
}
public void makeItems(String[] items){
for(int i = 0; i< (4) ; i++){
buffer.append('·' + items[i] + "\n");
}
buffer.append("\n");
}
public Object getResult(){
return buffer.toString();
}
}
//Main.java文件
public class Main {
public static void main(String[] args) {
Director director = new Director(new TextBuilder());
String result = (String)director. (5) ;
System.out.println(result);
第6题:
public class EqTest{() Public static void main(String args[]) EqTest e=new EqTest(); } EqTest(){ String s=”Java”; String s2=”java”; //在这儿放置测试代码 {Systrm.out.println(“相等”); Else{System.out.println(“不相等”)} } } 在上面的java代码的注释行位置,放置()测试代码能输出“相等”结果
第7题:
//point X public class foo ( public static void main (String[]args) throws Exception { printWriter out = new PrintWriter (new java.io.outputStreamWriter (System.out), true; out.printIn(“Hello”); } ) Which statement at PointX on line 1 allows this code to compile and run?()
第8题:
使用String s1=new String("Java");String s2=new String("Java")创建两个字符串时,s1,s2使用不同的内存空间
第9题:
//point X public class foo { public static void main (String[]args) throws Exception { java.io.printWriter out = new java.io.PrintWriter { new java.io.outputStreamWriter (System.out), true; out.printIn(“Hello”); } } } Which statement at PointX on line 1 allows this code to compile and run?()
第10题:
if(s==s2)
if(s.equals(s2))
if(s.equalsIgnoreCase(s2))
if(s.noCaseMatch(s2))
第11题:
第12题:
对
错
第13题:
设有以下语句: char str1[]="string",str2[8],*str3,*str4=="string; 则______不是对库函数的正确调用。
A.strcpy(str1,"HELLO1");
B.strcpy(str2,"HELLO2");
C.strcpy(str3,"HELLO3");
D.strcpy(str4,"HELLO4")
第14题:
Youneedtocreateaservletfilterthatstoresallrequestheaderstoadatabaseforallrequeststothewebapplication’shomepage"/index.jsp".WhichHttpServletRequestmethodallowsyoutoretrievealloftherequestheaders?()
A.String[]getHeaderNames()
B.String[]getRequestHeaders()
C.java.util.IteratorgetHeaderNames()
D.java.util.IteratorgetRequestHeaders()
E.java.util.EnumerationgetHeaderNames()
第15题:
下面代码的运行结果是( )。 public class ConcatTest { public static void main (String[ ] args) { String str1 = "abc"; String str2 = "ABC"; String str3 = str1. coneat(str2); System. out. println(str3); } }
A.abc
B.ABC
C.abcABC
D.ABCabc
第16题:
下面哪些代码在Java语言中是合法的? ( )
A.string A="abcdefg"; A-="cde";
B.string A="abcdefg"; A+="cde";
C.Integer J=new Integer(27); J-=7;
D.Integer J=new Integer(27); J--;
第17题:
设有以下语句: char str1[]= “string”,str2[8],*str3,*str4= “ string”; 则不能对库函数strcpy(复制字符串)的正确调用的是()
第18题:
Whichtwo scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object?()
第19题:
Public class test ( Public static void stringReplace (String text) ( Text = text.replace (‘j’ , ‘i’); ) public static void bufferReplace (StringBuffer text) ( text = text.append (“C”) ) public static void main (String args[]} ( String textString = new String (“java”); StringBuffer text BufferString = new StringBuffer (“java”); stringReplace (textString); BufferReplace (textBuffer); System.out.printLn (textString + textBuffer); ) ) What is the output?()
第20题:
public class Test { public static void main (String[]args) { String foo = args[1]; String bar = args[2]; String baz = args[3]; System.out.printIn(“baz = ” + baz); } } And the output: Baz = 2 Which command line invocation will produce the output?()
第21题:
When using versions of Java technology earlier than 5.0.
When sharing a StringBuffer among multiple threads.
When using the java.io class StringBufferInputStream.
When you plan to reuse the StringBuffer to build more than one string.
第22题:
Import java.io.*;
Include java.io.*;
Import java.io.PrintWriter;
Include java.io.PrintWriter;
No statement is needed.
第23题:
The program prints “lava”
The program prints “java”
An error at line 7 causes compilation to fail.
Compilation succeeds but the program throws an exception.
第24题:
strcpy(str3, "HELLO!");
strcpy(str2, "HELLO!");
strcpy(str1, "HELLO!");
strcpy(str4, "HELLO!");