SCJP第二课课后笔记

如何通过SCJP考试(含真题分析和考点)          SCJP认证全称为SUN 认证Java程序员,是Java认证系列中最基础的一门认证。要通过Java的其他认证,必须先通过SCJP认证(SCEA认证除外)。即使SUN被Oracle收购了,Java技术本身是不会因为收购而受到影响,Java技术仍然是大型企业应用的首选技术。       虽然不能说,如果拥有了Java的相关认证,就能有多高多高薪水,不过很多公司企业对于拥有证书 阅读详情

题外话:

  • PSP(Personal Software Process     个人开发能力)
  • TSP(Team Software Process  团队开发能力)
  • CMM(Capability Maturity Model for Software  能力成熟度模型)之间的关系

·PSP能够指导软件工程师如何保证自己的工作质量,估计和规划自身的工作,度量和追踪个人的表现,管理自身的软件过程和产品质量。经过PSP学习和实践的正规训练,软件工程师们能够在他们参与的项目工作之中充分运用PSP,从而有助于CMM目标的实现。



·TSP结合了CMM的管理方法和PSP的工程技能,通过告诉软件工程师如何将个体过程结合进小组软件过程,并将后者与组织进而整个管理系统相联系;通过告诉管理层如何支持和授权项目小组,坚持高质量的工作,并且依据数据进行项目的管理,向组织展示如何应用CMM的原则和PSP的技能去生产高质量的产品。

 

 

 ·CMM是过程改善的第一步,它提供了评价组织的能力、识别优先改善需求和追踪改善进展的管理方式。企业只有开始CMM改善后,才能接受需要规划的事实,认识到质量的重要性,才能注重对员工经常进行培训,合理分配项目人员,并且建立起有效的项目小组。然而,它实现的成功与否与组织内部有关人员的积极参加和创造性活动密不可分。

 

抽象

  • 函数—— 一种算法,一旦写成即可用于多种情况
  • 对象—— 将一组相关的属性和行为组成一个类(两个级别 对象中包含对象的对象叫做集合对象)
  • 框架和API—— 支持复杂行为的大型对象组

 

类

类是对象的蓝图。

Java技术编程语言支持三个OOP的关键特性:封装、继承和多态。

格式如下:

<修饰符> class <类名>{

  [<属性声明>]

  [<构造器声明>]

  [<方法声明>]

}

 

 

属性

属性名一般为名词命名

格式如下

<修饰符><类型><名称>;

 

方法

格式如下

<修饰符><返回类型><名称>([参数列表]){

 <语句>

}

返回类型必须写,如果没有必须写void,如果有则必须在结尾处写return语句,return语句后任何代码都不被程序读取

 

 

信息隐藏

尽量使用private来修饰。保护数据

 

封装

  • 封装的意义
  • 隐蔽类的实现细节
  • 强迫用户使用接口访问数据
  • 使代码更易维护

构造器(俗称“构造方法”)

强调:构造器不是方法!因为它没有任何返回,甚至连void都没有,因为它并不包含返回选项。另外它不可以被继承

 

格式如下:

<修饰符><类名>([<参数表>]){

  [<语句>]

}

 

默认构造器

  • 每个类至少有一个构造器
  • 如果不便携构造器,则自动添加默认构造器:
    • 默认构造器不带参数
    • 默认构造器为空
  • 不必编写构造器就能使用new xxx()创建对象实例。

可以通过默认构造器使用new xxx()创建实例,否则,将要求为每个类提供一个构造器。

 

源文件布局

格式如下

[<包声明>]

[<导入声明>]

  <类声明>+

 

(+号代表一个或多个)

Ps:包的命名规则:编程者所在组织的域名倒写加其他规范,如com.sun.java.ProKun

       包必须写在import之前,一般写在源文件最顶部

       包不可以使用诸如package com.*之类的带*的名称

       包名小写,无数字

       每个源文件只有一个包声明

 

       import java.net.*;此句话只引入当前包下所有文件,并不包含它们的子包。即访问不到java.net.URL.*;

       import用.*和.具体包名运行速度完全相同,无任何差异,对程序性能没有影响这点和C/C++的#include语句完全不同,初学者最好使用后者方法,可帮助记忆

 

 

术语摘要:

  • 类 ——  Java编程语言中定义新的对象类型的一种方法,类可以被视为一张蓝图——它是您要描述的对象的模型。
  • 对象 —— 类的实例。对象就是每次使用new 来实例化一个类得到的东西。对象也被称为实例。
  • 属性 —— 对象的数据元素。属性存储一个对象的信息。属性也被称为数据成员、实例变量或数据字段。
  • 方法 —— 一个对象的功能元素。方法也被称作函数或过程。
  • 构造器 —— 用于初始化(或建立)一个新对象的“类似方法”的构造。构造器名与类名相同。
  • 程序包 —— 是类、子程序包或者两者的集合。

Java API文档

  • 一套超文本标记语言(HTML)文件,是描述提供的API的文档
  • 一个包含了到多有类信息超链接的包
  • 一个类的文档。包括了类的层次结构、对象的描述、成员变量列表、构造器列表,等等。

 另外,为什么写程序要写成:

public static void main(String[] args){

 

}

 

而不是

public static void main(String[] args)

{

 

}

 

前者会让编程人员在屏幕上看到更多行的代码,提高编程效率。

 

 

====================================================================

本章练习题:

 

SL275: Module1: Getting Started

Exercise #1: Explore Java Errors

(Level 1)

Objective

In this exercise you will solve compilation and runtime errors by fixing an example Java technology program.

Directions

 

  1. Compile the Test1.java file.
    Why did it fail?
    Fix it and recompile and run this program.

     

  2. Compile the Test2.java file.
    Why did it fail?
    How would you fix this situation?

     

  3. Compile and run the Test3 class.
    Why did it fail?
    Fix it and recompile and run this program.

     

  4. Compile and run the Test4 class.
    Why did it fail?
    Fix it and recompile and run this program.

     

文件名:Test1.java

内容:

==================================================

public class Test1 {
  public static void main(String[] args) {
    System.out.println("What's wrong with this program?");
  }
}
public class TestAnother1 {
  public static void main(String[] args) {
    System.out.println("What's wrong with this program?");
  }
}

==================================================

 

 

 

文件名:Test2.java

内容:

==================================================

public class Testing2 {
  public static void main(String[] args) {
    System.out.println("What's wrong with this program?");
  }
}
==================================================

 

 

 

 

文件名:Test3.java

内容:

==================================================

public class Test3 {
  public static void main(String args) {
    System.out.println("What's wrong with this program?");
  }
}
==================================================

 

 

 

 

 

 

文件名:Test4.java

内容:

==================================================

public class Test4 {
  public void main(String[] args) {
    System.out.println("What's wrong with this program?");
  }
}
==================================================

 

 

 

 

我的解答:

Test1:一个类文件只能有一个public的class,并且一个程序只有一个main方法。所以显然是错误在这里,应改成

public class Test1 {
  public static void main(String[] args) {
    System.out.println("This is Right!");
  }
}

 

 

 

Test2:类名和文件名不同。应改成

public class Test2 {
  public static void main(String[] args) {
    System.out.println("This is Right!");
  }
}

 

 

 

Test3:字符数组没写。应改成

public class Test3 {
  public static void main(String[] args) {
    System.out.println("This is Right!");
  }
}

 

 

 

Test4:main方法不是静态的。应改成

 public class Test4 {
  public static void main(String[] args) {
    System.out.println("This is Right!");
  }
}

 

 

 

练习2

SL275: Module2: Object-Oriented Programming

Exercise #2: Explore Encapsulation

(Level 2)

Objective

In this exercise you will explore the purpose of proper object encapsulation. You will create a class in three steps demonstrating the use of information hiding.

Directions

Version 1: No Information Hiding
UML Diagram of Version #1 of the Vehicle Class

In this version of the Vehicle class, you will leave the attributes public so that the test program TestVehicle1 will have direct access to them.

  1. Change your working directory to mod02/exercise2/version1.

     

  2. Create a class Vehicle that implements the above UML diagram.

     

    1. Include two public attributes: load "the current weight of the vehicle's cargo" and maxLoad "the vehicle's maximum cargo weight limit".
    2. Include one public constructor to set the maxLoad attribute.
    3. Include two public access methods: getLoad to retrieve the load attribute and getMaxLoad to retrieve the maxLoad attribute.

    Note that all of the data are assumed to be in kilograms.

     

  3. Read the TestVehicle.java code. Notice that the program gets into trouble when the last box is added to the vehicle's load because the code does not check if adding this box will exceed the maxLoad.

     

  4. Compile the Vehicle and TestVehicle classes.

     

  5. Run the TestVehicle class. The output generated should be:
    Creating a vehicle with a 10,000kg maximum load.
    Add box #1 (500kg)
    Add box #2 (250kg)
    Add box #3 (5000kg)
    Add box #4 (4000kg)
    Add box #5 (300kg)
    Vehicle load is 10050.0 kg
    

     

 

Version 2: Basic Information Hiding
UML Diagram of Version #2 of the Vehicle Class

To solve the problem from the first version, you will hide the internal class data (load and maxLoad) and provide a method, addBox, to perform the proper checking that the vehicle is not being overloaded.

  1. Change your working directory to mod02/exercise2/version2.

     

  2. Create a class Vehicle that implements the above UML diagram.

    You may wish to copy the Vehicle.java file you created in version #1.

     

    1. Modify the load and maxLoad attributes to be private.
    2. Add the addBox method. This method takes a single argument, which is the weight of the box in kilograms. The method must verify that adding the box will not violate the maximum load. If a violation occurs the box is rejected by returning the value of false; otherwise the weight of the box is added to the vehicle load and the method returns true.

      Hint: you will need to use an "if" statement. Here is the basic form of the conditional form:

      if ( <boolean_expression> ) {
        <statement>*
      } else {
        <statement>*
      }
      

       

    Note that all of the data are assumed to be in kilograms.

     

  3. Read the TestVehicle.java code. Notice that the code can not modify the load attribute directly, but now must use the addBox method. This method returns a true or false value which is printed to the screen.

     

  4. Compile the Vehicle and TestVehicle classes.

     

  5. Run the TestVehicle class. The output generated should be:
    Creating a vehicle with a 10,000kg maximum load.
    Add box #1 (500kg) : true
    Add box #2 (250kg) : true
    Add box #3 (5000kg) : true
    Add box #4 (4000kg) : true
    Add box #5 (300kg) : false
    Vehicle load is 9750.0 kg
    

     

 

Version 3: Change Internal Representation of Weight to Newtons
UML Diagram of Version #3 of the Vehicle Class

Now suppose that you were going to write some calculations that determine the wear on the vehicle's engine and frame. These calculations are easier if the weight of the load is measured in newtons.

  1. Change your working directory to mod02/exercise2/version3.

     

  2. Create a class Vehicle that implements the above UML diagram.

    You may wish to copy the Vehicle.java file you created in version #2.

     

    1. Modify the constructor, getLoad, getMaxLoad, and addBox methods to use a conversion from kilograms (the parameter weight measurement) to newtons (the instance variable measurement). You might want to use the following private methods:
        private double kiloToNewts(double weight) {
          return (weight * 9.8);
        }
        private double newtsToKilo(double weight) {
          return (weight / 9.8);
        }
      

    Note that now the internal data of the vehicle objects is in newtons and the external data (passed between methods) is still in kilograms.

     

  3. Read the TestVehicle.java code. Notice that it is identical to the test code in version #2.

     

  4. Compile the Vehicle and TestVehicle classes.

     

  5. Run the TestVehicle class. The output generated should be:
    Creating a vehicle with a 10,000kg maximum load.
    Add box #1 (500kg) : true
    Add box #2 (250kg) : true
    Add box #3 (5000kg) : true
    Add box #4 (4000kg) : true
    Add box #5 (300kg) : false
    Vehicle load is 9750.0 kg
    

     

You should see no change in the output of the program. This demonstrates that the (private) internal changes to the version #3 Vehicle class did not change the code of the client class TestVehicle.

 

 

 

 

我的解答

第一题:

public class Vehicle{
 public double load;
 public double maxLoad;
 public Vehicle(double max_load){
  maxLoad=10000.0;
 }
 public double getLoad(){
  return load;
 }
 public double getMaxLoad(){
  return maxLoad;
 }
}

 

 

第二题

public class Vehicle{
 private double load;
 private double maxLoad;
 public Vehicle(double max_load){
  maxLoad=10000.0;
 }
 public double getLoad(){
  return load;
 }
 public double getMaxLoad(){
  return maxLoad;
 }
 public boolean addBox(double weight){
  load+=weight;
  if(load<=maxLoad){
   return true;
  }
  else{
   load-=-weight;
   return false;
  }
 }

}

 

 

第三题

public class Vehicle{
 private double load;
 private double maxLoad;
 public Vehicle(double max_Load){
  maxLoad=10000.0;
 }
 public double getLoad(){
  return load;
 }
 public double getMaxLoad(){
  return maxLoad;
 }
 public boolean addBox(double weight){
  load+=weight;
  if(load<=maxLoad){
   return true;
  }
  else{
   load-=weight;
   return false;
  }
 }
 private double newtsToKio(double weight){
  return (weight*9.8);
 }
 private double kiloToNewts(double weight){
  return (weight/9.8);
 }
}

SCJP刷题学习笔记(Part fifteen) QUESTION 141 Given: What is the result? A. Hi Interface-2 B. A compilation error occurs. C. Hi Interface-1 D. Hi MyClass Correct Answer: D Section: (none) Explanation Explanation... 阅读详情

相关推荐

SCJP刷题学习笔记(Part six)

QUESTION 51 Given: final class Folder { //line n1 //line n2 public void open () { System.out.print(“Open”); } } public class Test { public static void main (String [] args) throws Ex...

GOGOGO! 676

SCJP习题

SCJP试题集及解析 1. Which of the following range of short is correct? A. -27 -- 27-1 B. 0 – 216-1 C. -215 – 215-1 D. -231 – 231-1 翻译:下面哪些是short型的取值范围。 答案::C 解析:短整型的数据类型的长度是16 bits,有符号。另外...

itcast123的专栏 521

SL-275中文版教材

SCJP必读教材,中文翻译版本。SUN培训教程。

CAD AddAttribute 方法 AddBox 方法

CAD AddAttribute 方法 AddBox 方法

weixin_43931979的博客 462

sl275官方教程

sl275官方教程,Sun Certified Java Programming Language

SL275课程答案

北京交大,Java课程sl275习题答案,包含mod03到mod16,

面向对象程序设计JAVA学习记录(2)

最近的AVA程序设计学习记录,一些思路注解和代码

JJ-Li的博客 783

ArcGIS+PLUS+InVEST三件套:从零搞定生态系统服务模拟预测(附完整数据包)

本文详细介绍了如何整合ArcGIS、PLUS模型和InVEST模型,构建一套完整的生态系统服务模拟预测工作流。内容涵盖从统一数据预处理、PLUS模型多情景模拟,到InVEST模型量化评估的全过程,并提供了关键脚本和避坑指南,旨在帮助研究者和从业者高效解决土地利用变化与生态系统服务评估结合的实际难题。

weixin_42522857的博客 139

SCJP认证

 即Sun Certified Java Programmer。SCJP 主要测验对 Java 程序设计的观念和能力, 内容偏重于Java的语法及JDK的内容。一、SCJP有什么好处通过 Sun 任何一门专业认证后,你将会收到 Sun Microsystems 总公司寄发的资格证书及徽章,并有权将通过 Sun 认证的标记印在个人名片上,代表个人技术能力的肯定。并不需要特别的背景才可以报考二、SCJ

认证专栏 2267

强化学习 之 Actor Critic

简介 Actor Critic是一种结合体算法: (1)Actor 的前生是 Policy Gradients,这能让它毫不费力地在连续动作中选取合适的动作,而 Q-learning 做这件事会瘫痪; (2)Critic 的前生是 Q-learning 或者其他的 以值为基础的学习法,能进行单步更新,而传统的 Policy Gradients 则是回合更新,这降低了学习效率。 算法思想 Actor...

Test_tju的博客 812

【数字IC设计】Centos 7桌面版 安装Synopsys EDA Tools

简称DC,是Synopsys公司用于做电路综合的核心工具,可以将HDL描述的电路转换为基于工艺库的门级网表。

qiumingT的博客 9807

SCJP刷题学习笔记(Part twelve)

QUESTION 111 Given: and the command: java Product 0 What is the result? A. An AssertionError is thrown. B. A compilation error occurs at line n1. C. New Price: 0.0 D. A NumberFormatEx...

GOGOGO! 836

open-web UI 实用指南

open-web UI 类似于chatgpt的界面,可以私有化模型本地部署,也可以用商业模型.本文只是用开源模型. 它以实现多模态AI聊天 , AI 翻译 , 语音转文本, 文本转语音, 文生图,代码助手,可谓利器。

szmars的博客 3万+

参加SCJP认证时学习的笔记

把SCJP认证的参考书看了2遍,但迟迟未考,因为没有钱。。。今年终于狠下心花了700元在网上买了张转让的考试券(原价1400,SUN其实挺黑的),5月份报名考了90多分,也算了却了一桩心事。下面是我当时的学习笔记,都是一些很基础的知识。一.语言基础1.JAVA语言标识符:开头以字母,"_","$"开头,后跟字母,"_","$",数字。2.System.gc()  或者Runtime.getRu

pwy_19831104的专栏 672

RAW、RGB、YUV图像格式的采样与存储原理详解

本文详细解析了RAW、RGB和YUV三种核心图像格式的采样与存储原理。RAW是传感器原始数据,信息完整但需后期处理;RGB直接对应显示,直观但数据量大;YUV通过亮色分离与色度下采样,在保证观感的前提下大幅提升传输与存储效率,是视频编码与流媒体的主流格式。理解其差异是图像处理与视频开发的基础。

e4f5g6h7的博客 516

MAX31865三线PT100测温实战:配置、接线与代码全解析

本文详细解析MAX31865三线PT100测温的配置、接线与代码实现。通过实战经验分享,介绍如何利用MAX31865芯片实现高精度温度测量,重点讲解三线制接法的自动误差补偿功能,并提供完整的寄存器配置、SPI通信和温度转换算法,帮助开发者快速解决工业测温中的常见问题。

ss78901的博客 758

怎样拿下SUN公司的SCJP认证?

SCJP本来易拿下,可我第一次却恰恰为59%,郁闷啊!1250RMB的银子啊!你们可不要蹈偶的覆辙啊!想过SCJP的哥们,可以进去看看我的体会。。。。。。。SUN的SCJP资格证书,想说拿你却并不难!为什么我的命咋这么苦啊!!!???SUN JAVA程序员认证证书。现在终于把他给拿下了!中间还是费了一点周折,考了2次才PASS!第一次59%,1月6日FAIL了,差一道题就PASS,可能是偶运气

pensincun的专栏 4932

YOLO26魔改神技:YOLO26引入SimAM(无参注意力):不增加网络参数的3D能量函数提点黑科技

文章摘要 2026年YOLO26模型发布引发边缘计算革命,但特定场景精度不足问题催生注意力机制改进需求。本文聚焦无参数注意力机制SimAM,基于神经科学理论通过3D能量函数直接计算神经元权重,实现零参数量提升模型性能。文章深度解析YOLO26四大创新架构,对比SimAM与传统注意力机制差异,并探讨其在YOLO26中的集成方案。研究显示,SimAM在不增加模型体积前提下显著提升mAP指标,特别适合边缘端部署。全文涵盖架构设计、代码实现、竞品对比、部署方案等维度,为轻量化视觉模型优化提供系统解决方案。

ZDQ58818的博客 274

SCJP考试认证复习笔记系列之三

      SCJP考试认证复习笔记系列之三 java中的boolean类型不能和int类型进行转换的,不要认为true为1、false为0 局部变量在使用前一定要先初始化 class中如果含有抽象方法那么必须要声明为抽象类,如果没有抽象方法也可以声明为抽象类,接口中的方法都不能在接口中实现。 length是数组的一个变量而不是方法,通常我们计算Collection的时候要用size()方法 B

mingjava的专栏 2135

Windows 下 OpenClaw(小龙虾) 安装全记录:从零到一的保姆级图文教程(持续更新中)

本文主要介绍了Windows 下 OpenClaw 安装全记录:从零到一的保姆级图文教程,希望能对学习使用OpenClaw 的同学们有所帮助。 文章目录 1. 背景 2. 实战教程 2.1 步骤一 安装Node.js 2.2 步骤二:安装并配置OpenClaw 2.3 步骤三:配置模型 2.4 步骤四:对话 3. 后续使用步骤

weixin_43178406的博客 16万+

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

关于 SCJP 1.4 考试

 SCJP 1.4 考试是 Sun Microsystems 推出的系列 Java 认证考试中的第一个,对于众多程序员来说,它是成为优秀 Java 开发人员的第一步。 该考试测试 Java 的基础知识并需要对该语言的语法和语义有深入理解。  1.参加培训或自学Java经典课程。如果有C语言和面向对象的基础,只需自学SL275课程以及JDK1.4API,否则应该参加相应的培训班进行学习。

!Java 6122

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

SCJP刷题学习笔记(Part seven)

QUESTION 61 Given: public interface Moveable<Integer> { public default void walk (Integer distance) {System.out.println (“Walking”);) public void run(Integer distance); } Which stat...

GOGOGO! 1156

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

scjp报考流程

一、考试信息   1、考试科目SCJP   2、考试编号:310-025   3、考试题型:单选题、多选题、填空题   4、及格分数:61%   5、考试时间:120分钟   6、考试费用:人民币1250元   二、报考步骤   1、向Sun培训部购买准考证(Certification Voucher)   考试中心的相关资料请浏览以下网址:http://www

Ogelsvy的专栏 5855

[转载]SCJP 1.4 认证的初级教程

SCJP 1.4 认证的初级教程最近,Sun 已针对 J2SE 1.4 更新了 Sun Certified Java Programmer(SCJP)考试,这意味着您需要克服一些新困难才能通过认证。在这个 SCJP 认证的初级...

congji3817的博客 248

SCJP刷题学习笔记(Part sixteen)

QUESTION 151 Which two statements are true about the Fork/Join Framework? (Choose two.) A. The RecursiveTask subclass is used when a task does not need to return a result. B. The Fork/Join frame...

GOGOGO! 676

SCJP证书

SCJP的证书,大概大半年前考的。那时寒假,女朋友跟我分手了。心冷彻骨,把眼一闭,埋进书堆里就把这个证考了。 

hzxdark的专栏 2038
上一篇: SCJP第一课课后笔记
下一篇: SCJP第三课课后笔记
ProKun
博客等级 码龄18年 6粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值