Category Archive for: A Closer Look at Methods and Classes

Exploring the String class

Exploring the String class Although the String class will be examined in depth in Part II of this book, a short exploration of it is warranted now, because we will be using strings in some of the example programs shown toward the end of Part I. String is probably the most commonly used class in Java’s class…

Read More →

Introducing Nested And Inner Classes

Introducing Nested And Inner Classes It is possible to define a class within another class; such classes are known as nested lasses. The Scope of a nested class is bounded by the scope of its enclosing class. Thus, if class Bis defined within class A, then Bis known to A, but not outside of A. A blindside.…

Read More →

Introducing final

Introducing final A variable can be declared as final. Doing so prevents its contents from being. modified. This means that you must initialize a final variable when it is declared. (In this usage, final is similar to canst in C/C++.) For example•Subsequent parts of your program can now use FILE_OPEN, etc., as if they were constants; without fear…

Read More →

Understanding Static

Understanding Static Although methods will usually provide access to the data defined by a class, this does not always have to be the case. It is perfectly proper to allow an instance variable to be public when there is good reason to do so, For example, most of the simple classes in this book were created with little…

Read More →

Introducing Access Control

Introducing Access Control As you know, encapsulation links data with the code that manipulates it. However encapsulation provides another important attribute:  access control. Through ‘ encapsulation, you can control what parts of a program can access ,the members of a class. By controlling access, you can prevent misuse. For example, allowing access to data only through a well-defined set…

Read More →

Recursion

Recursion Java support recourse Recursion is the process of defining something in terms of itself. As it relates to Java programming. recursion is the attribute that allows a method to call itself. A method that calls itself is said to be recursive. The classic example of recursion is the computation of the factorial of a number. The factorial…

Read More →

A Closer Look at Argument Passing

A Closer Look at Argument Passing In general, there arc two ways that a computer language can pass an argument to a subroutine. The first way is call-by-value. This method copies the value of an argument ,into ‘the formal parameter of the subroutine. Therefore, changes made to the parameter of the subroutine have no effect on the argument used…

Read More →

Overloading Constructors

Overloading Constructors In addition to overloading normal methods, you can also overload constructor  methods. In fact, for most real-world classes thought create, overloaded constructors will be the norm, not the exception. To undercut stand why, let’s return Lo the Box class’ developed in the preceding chapter. Following is the latest version As you can see, the Box() constructor requires…

Read More →

A Closer Look at Methods and Classes

A Closer Look at Methods and Classes This chapter continues the-discussion of methods and classes begun in the ?receding chapter. It examines several topics relating to methods, including. overloading, parameter passing, and recursion. The chapter, then returns to the class, discussing-access control, the use of the keyword static, and one of Java’s most important built-in classes: String, Overloading Methods…

Read More →

Back to Top