排序
Valid Parentheses | LeetCode | Java
Valid Parentheses | LeetCode | Java,class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<>(); for(char ch : s.toCharArray()){ if(stack...
The this Reference
The this Reference,The keyword this refers to the object itself. It can also be used inside a constructor to invoke another constructor of the same class. The this keyword is the n...
The Scope of Variables
The Scope of Variables,The scope of instance and static variables is the entire class, regardless of where the variables are declared. Local variables are declared and used inside ...
Immutable Objects and Classes
Immutable Objects and Classes,You can define immutable classes to create immutable objects. The contents of immutable objects cannot be changed. Normally, you create an object and ...
Array of Objects
Array of Objects,An array can hold objects as well as primitive type values. Single-Dimensional Arrays, described how to create arrays of primitive type elements. You can also crea...
Passing Objects to Methods
Passing Objects to Methods,Passing an object to a method is to pass the reference of the object. You can pass objects to methods. Like passing an array, passing an object is actual...
Data Field Encapsulation
Data Field Encapsulation,Making data fields private protects data and makes the class easy to maintain. The data fields radius and numberOfObjects in the CircleWithStaticMembers cl...
Visibility Modifiers
Visibility Modifiers,Visibility modifiers can be used to specify the visibility of a class and its members. You can use the public visibility modifier for classes, methods, and dat...
Static Variables, Constants, and Methods
Static Variables, Constants, and Methods,A static variable is shared by all objects of the class. A static method cannot access instance members of the class. The data field radius...
Using Classes from the Java Library
Using Classes from the Java Library,The Java API contains a rich set of classes for developing Java programs. This section gives some examples of the classes in the Java library. T...
Accessing Objects via Reference Variables
Accessing Objects via Reference Variables,An object’s data and methods can be accessed through the dot (.) operator via the object’s reference variable. Newly created objects are...
Constructing Objects Using Constructors
Constructing Objects Using Constructors,A constructor is invoked to create an object using the new operator. Constructors are a special kind of method. They have three peculiaritie...