`
Odysseus_110
  • 浏览: 120420 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

SCJP notes

    博客分类:
  • J2SE
阅读更多

The default constructor has the same access as its class

 

 

which gets the name of the parent directory file “file.txt”?

String name = (new File(“file.txt”)).getParent();

 

 

which of these are valid JavaBeans method signatures?

A  public void removeWibbleListener(BurbleListener w)

B  public void addElement(Element e)

C  public boolean getActive()

D  public boolean isActive()

E   int getFooNumber()

F   public long size()

The correct options are C and D.With regards to the JavaBeans naming conventions:

E is incorrect because getter and setter methods must be public

B is incorrect because an add… or remove… method must end in ….Listener

A is incorrect because a removeWibbleListener method must take a WibbleListener as its argument

 

 

which methods can be declared at the position indicated and not cause a compile-time error?

A  protected void drawSting()

B  void drawSting();

C  public abstract void drawSting();

D   public static void drawSting();

E  strictfp void drawSting();

The correct options are B and C

Interface method declarations are implicitly public and abstract,and these modifiers can be omitted.Interface methods cannot be static(ruling out D),nor can they be marked strictfp(ruling out E) ,final or native.Marking A protected conflicts with the restriction that interface methods must be public.

 

 

Fill in the table to indicate which Exception and Error classes are typically thrown programmatically and which by the JVM.

 

Exception/Error class                                   Typically thrown…?

ArrayIndexOutOfBoundsException                 By the JVM

ClassCastException                                         By the JVM

IllegalArgumentException                                 Programatically

IllegalStateException                                        Programatically

NullPointerException                                      By the JVM

NumberFormatException                                 Programatically

AssertionError                                                Programatically

ExceptionInInitalizerError                                By the JVM

StackOverflowError                                        By the JVM

NoClassDefFoundError                                  By the JVM

 

 

How many lines don't compile ?

byte a = 127 + 1 ;

byte b = ( byte ) 25768 ;

char c = 127 ;

c+= 12345 ;

Answer: line 1 does not compile

127 is the max value of a byte. Casting makes everything ok. Remember += does an automatic cast.

 

 

class test {
 public static void main ( String [] args ) {
      final Integer x4 = 8; 
      final int x = 10; 
      switch ( x ) { 
                 case x4: 
                     System.out.println("4");
                     break; 
                 case x: 
                     System.out.println("x");
                     break; 
      } 
}
}
 

 

 

compile error

Final objects are not allowed in a case statement. A final object's value can be changed whereas a final variables value cannot be changed.

 

 

 

 

 

an interface may extend multiple interfaces

 

 

an ArithmeticException is  a checked exception.

Answer:false

ArithmeticException are considered programmer problems ,and are Not checked by the compiler.A divide-by-zero error,for example,should be checked for by your own code.

 

 

 

Public class Demo{ 
public static void main(String[] args){ 
for(int i =0;i < 3;i++){
           label1:
               switch(i){ 
                       case 0: 
                           System.out.println(“34”);
                       case 1: 
                           System.out,println(“23”); 
                           break; 
                       case 2: 
                           System.out.println(“12”);
                       case 3: 
                           System.out.println(“01”); 
                           break label1; 
                       default: 
                           System.out.println(“40”); 
               } 
} 
} 
}
 

 

 

A The code is correct and it compiles.

 

label1: can lay before switch?

you can put label before any statement or block of code.
but you cannot call break labelX if you are not in its scope.
you are trying to call break label1 in switch case 3 but it is out of scope.
look this code about scopes:

 

 label1:
System.out.println("in label1");//here scope of this label is
                                //this one statement so you can't
                                //break
 
label2:{  //here starts scope of label2
   System.out.println("label 2 started");
   break label2;  // here you can use break in scope of this label
   System.out.println("label 2 ended");  //but it wont compile because compiler
                                         //knows this statement is unreachable
}   //here ends scope of label2
 
break label2; // you cant do this here because you are out of scope
 
for(int i = 0; i < 5; i++){
   // bla bla bla
   break label2; // you cant do this here because you are out of scope
 

 

 

which of these are legal escape sequences?

A \n

B \f

C \m

D \n

E \e

F \r

G \t

ABDFG

 

Remember the sentence:”Big farms need red tractors

only “b” “f” “n” “r” and “t” are legal,no other characters!

 

 

 

Which of the following statements are not true?

java.lang.Character does not extend java.lang.Number

java.lang.Void can't be extended but it can only be instantiated

java.lang.Integer can't be extended

java.lang.Character does not have a constructor that takes a String

java.lang.Byte does not extend java.lang.Number

 

B and E are correct. Only these two statements are NOT true. The class java.lang.Void is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void. This class is final and has a private constructor. Hence, it can neither be extended nor can it be instantiated.

The class java.lang.Byte does indeed extend java.lang.Number.

The class java.lang.Character does not extend java.lang.Number, and has only one constructor that takes a char value.

All wrapper classes are final, and hence they can not be extended.

 

 

It is perfectly legal in Java to create arrays of size zero.

 

 

 

 

在定义一个 native method 时,并不提供实现体(有些像定义一个 java interface ),因为其实现体是由非 java 语言在外面实现的。,下面给了一个示例:    
    public class IHaveNatives
    {
      native public void Native1( int x ) ;
      native static public long Native2() ;
      native synchronized private float Native3( Object o ) ;
      native void Native4( int[] ary ) throws Exception ;
    }

标识符 native 可以与所有其它的 java 标识符连用,但是 abstract 除外。这是合理的,因为 native 暗示这些方法是有实现体的,只不过这些实现体是非 java 的,但是 abstract 却显然的指明这些方法无实现体。

 

 

 

What will happen when you attempt to compile and run the following code?

 

class MyClass 
{
  	static String myName = "SCJP";
  
	MyClass getMyClass() 
  	{     
     		System.out.println(myName);
     		return null;     
  	}

  	public static void main(String[ ] args) 
  	{
    		System.out.println( new MyClass().getMyClass().myName );
  	}
}
 

 

 

 

Answer: Prints SCJP twice

C is the correct choice. The above method will not give any compilation error as at compile time, compiler sees the return type of getMyClass method as MyClass and calling myName on MyClass is valid at compile time.

 

Also it doesn't give any runtime error which is not very obvious. Please note that a null reference may be used to access a class (static) variable without causing an exception . The static variable is called on the class itself and not on the object. Had the myName variable non-static, the above code at run time would give NullPointerException.

 

 

 

 

 

 

  • scjpnote.rar (283 KB)
  • 描述: scjp学习笔记
  • 下载次数: 8
1
0
分享到:
评论

相关推荐

    BB_s Notes4 SCJP1.4

    BB_s Notes4 SCJP1.4 是一份针对SCJP(SUN Certified Programmer for Java 1.4)认证考试的重点复习资料。这份笔记涵盖了Java语言的关键概念,包括基本数据类型、运算特性、字符串特点、类与方法修饰符、多态、覆盖...

    SCJP 6 notes

    SCJP 6(Sun Certified Programmer for Java Platform)是针对Java程序员的专业认证,旨在评估考生对Java SE 6平台的理解和编程能力。以下是基于给定文件信息的重要知识点详解: ### 浮点数与整数默认类型及转换 ...

    scjp-6-notes-jonathangiles

    根据给定文件的信息,我们可以提炼出一系列关于Java 6 SCJP考试的重要知识点,这些知识点涵盖了基本数据类型处理、面向对象编程、接口实现、匿名内部类、静态方法、异常处理、对象相等性与哈希码、初始化块、垃圾...

    SCJP考试资料整理

    首先,"notes for scjp(1.4).doc"可能是一个关于Java 1.4版本的笔记,这涵盖了Java语言的基础,包括语法、数据类型、流程控制、异常处理、类和对象、包、接口等。Java 1.4是较早的版本,但基础概念对于理解后来的...

    SCJP考题_学习笔记

    2. **学习笔记**: "scjp_amay's notes for 1.4.doc"可能是一位名叫Amay的学习者针对Java 1.4版本的SCJP考试整理的笔记,这个版本可能包含对当时Java语言特性的详细解析,例如原始类型、字符串常量池、异常处理机制等...

    SUN SCJP 认证笔记

    文档如"amay's2.doc"、"JavaCertificationStudyNotes.doc"、"amay's notes for 1.4.doc"和"mynote"都提供了不同角度的学习材料,有助于考生从不同层面理解和巩固知识。 在备考过程中,考生不仅要熟记理论知识,还要...

    一个网友考scjp后上传的资料

    这份由网友提供的"notes for 1.4.doc"文档,很可能是关于SCJP 1.4版本的备考笔记,该版本对应的是Java SE 1.4,尽管现在已经有些过时,但其中的基础知识对于理解Java编程依然非常有价值。 【Java基础】文档可能会...

    sun jave certified book

    SCJP认证的sun官方课程资料-student guide with instruction notes.

    notes for 1.4.doc

    ### SCJP 学习笔记 for 1.4 #### 八进制与十六进制表示法 - **八进制数表示**: - Java 中,八进制数以数字 `0` 开头(不是字母 `o`)。例如,八进制数 `010` 实际上表示的是十进制数 `8`。 - **示例**:`System...

    Java Certificate Notes

    13. **其他网站** - 不断增加的各种关于 SCJP(Sun Certified Java Programmer)认证的相关网站。 #### 三、考试目标概览 根据文档中的描述,Java 认证考试的目标主要涵盖了以下几个方面: 1. **声明与访问控制** ...

    各类面试题

    2. "amay's notes for 1.4.doc":这看起来像是一个人(Amay)对某个版本或主题1.4的笔记,可能是对面试题目的解析或准备指南,可能是针对特定技术领域,如软件开发的某个版本或标准。 3. "scjp.txt":SCJP是“Sun ...

    程序员考试刷题-ocp-java8-notes:关于OCPJava8认证的一些注意事项

    SCJP 6 --&gt; OCP 8 & SCJP 7 --&gt; OCP 8 的升级也存在 Java牧场 书 OCP:Oracle Certified Professional Java SE 8 Programmer II 学习指南:考试 1Z0-809 执照 MIT - Licence Copyright (c) 20

Global site tag (gtag.js) - Google Analytics