Submitted by heartin on Sat, 07/04/2020 - 21:50
Traversing arrays
Traversing an array is the process of visiting each element of an array.
Two common ways to traverse an array are:
Example array
int[] myArray = {1,2,3,4,5}
Submitted by heartin on Thu, 10/23/2014 - 10:07
The while statement
The “while loop” is an alternative to “for loop”. a “for loop” is usually used when the number of times the block is to be executed is known. A “while loop” is usually used when the number of times the block is to be executed is not known, like prompting the user whether to stop executing during every iteration.
The syntax of “while loop” is:
while (<condition>) <statements>;
Example:
Submitted by heartin on Tue, 10/29/2013 - 09:29
Access modifiers are used to specify the accessibility or access levels of a type (class, interface) and its members (methods, variables and even constructors). There are three access modifiers and four access levels in Java. The three access modifiers are are private, protected and public. Four access levels (from most restricted to least restricted) are private, default (no modifier), protected and public.
Submitted by heartin on Sat, 10/26/2013 - 13:10
Constructors are used to initialize the state of an object when it is created. Constructors are invoked while creating objects, usually after the new keyword. A child class may also invoke a super constructor using the super keyword to initialize the parent object.
Constructors are similar in syntax to methods, but without any return type and have the same name as that of the class (case sensitive).
MyClass{
MyClass(){
}
Submitted by heartin on Wed, 10/23/2013 - 08:52
The “this keyword” in Java refer to the the current object (current instance). All your instance variables may be referred as 'this.variableName' even though it is implicit in most cases.
The “this keyword” is mostly useful in below cases:
-
Refer to instance variables of a class when a local variable has precedence over it.
Pages