Java - 鲁棒性和代码重用

标签 java code-reuse robust

我对java概念有一些疑问:

  1. Java 中的代码重用与使用 C 等其他编程语言中定义的函数类似吗?

  2. Java 本质上是健壮的还是它提供了一种编写健壮代码的方法?

谁能解释一下以上两个。我读了几本书,但没有得到清晰的了解

最佳答案

代码重用

我确实想向您指出有关此主题的一些链接。

第一个链接中有关代码重用的一些要点。

Code reuse, the most common kind of reuse, refers to the reuse of source code within sections of an application and potentially across multiple applications. At its best, code reuse is accomplished by sharing common classes or collections of functions and procedures. At its worst, code reuse is accomplished by copying and then modifying existing code. A sad reality of our industry is that code copying is often the only form of reuse practised by developers.

稳健

引自 Core Java,第一卷,基础知识。

"Java is intended for writing programs that must be reliable in a variety of ways. Java puts a lot of emphasis on early checking for possible problems, later dynamic (runtime) checking, and eliminating situations that are error-prone. . . . The single biggest difference between Java and C/C++ is that Java has a pointer model that eliminates the possibility of overwriting memory and corrupting data."

This feature is also very useful. The Java compiler detects many problems that, in other languages, would show up only at runtime. As for the second point, anyone who has spent hours chasing memory corruption caused by a pointer bug will be very happy with this feature of Java.

If you are coming from a language like Visual Basic that doesn’t explicitly use pointers, you are probably wondering why this is so important. C programmers are not so lucky. They need pointers to access strings, arrays, objects, and even files. In Visual Basic, you do not use pointers for any of these entities, nor do you need to worry about memory allocation for them. On the other hand, many data structures are difficult to implement in a pointerless language. Java gives you the best of both worlds. You do not need pointers for everyday constructs like strings and arrays. You have the power of pointers if you need it, for example, for linked lists. And you always have complete safety, because you can never access a bad pointer, make memory allocation errors, or have to protect against memory leaking away.

关于Java - 鲁棒性和代码重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8373655/

相关文章:

java - 目前流行的Java SIP库是什么?

java - 阿尔法优势.co : Historical data is unable to fetch with 5 min interval

types - 如何在 Rust 中为相似但不同的类型重用代码?

javascript - jQuery Accordion 插件(如 Facebook 或 Google)

javascript - 如何导出函数并使它们在 javascript/reactjs 中可重用

r - `glmRob()` 在给定 `newdata` 参数时不预测

java - 如何在 Swing 中分析 EDT?

java - 无法从 fragment 对象访问公共(public)方法

python - 使用 PyMC 的鲁棒非线性回归(2)