Java Tutorials

231. Using read() to read one character at a time from console input

By: Jagan : 2007-09-08

Description: Each time that read() is called, it reads a character from the input stream and returns it as an integer value. It returns –1 when the end of the stream is encountered.


232. readLine() to read strings from console input

By: Kamini : 2007-09-08

Description: To read a string from the keyboard, use the version of readLine() that is a member of the BufferedReader class. Its general form is shown here:


233. Method Overriding in Java

By: Henry : 2007-09-08

Description: In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass. The version of the method defined by the superclass will be hidden.


234. Basics of Inheritance in Java

By: Baski : 2007-09-08

Description: To inherit a class, you simply incorporate the definition of one class into another by using the extends keyword. To see how, let's begin with a short example. The following program creates a superclass called A and a subclass called B. Notice how the keyword extends is used to create a subclass of A.


235. static keyword in Java

By: Abinaya : 2007-09-08

Description: There will be times when you will want to define a class member that will be used independently of any object of that class. Normally a class member must be accessed only in conjunction with an object of its class. However, it is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration with the keyword static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object. You can declare both methods and variables to be static. The most common example of a static member is main(). main() is declared as static


236. Method Overloading (function overloading) in Java

By: Abinaya : 2007-09-08

Description: In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways that Java implements polymorphism.


237. Garbage Collection in Java

By: Ivan Lim : 2007-09-08

Description: Since objects are dynamically allocated by using the new operator, you might be wondering how such objects are destroyed and their memory released for later reallocation. In some languages, such as C++, dynamically allocated objects must be manually released by use of a delete operator. Java takes a different approach; it handles deallocation for you automatically. The technique that accomplishes this is called garbage collection. It works like this: when no references to an object exist, that object is assumed to be no longer needed, and the memory occupied by the object can be reclaimed. There is no explicit need to destroy objects as in C++. Garbage collection only occurs sporadically (if at all) during the execution of your program. It will not occur simply because one or more objects exist that are no longer used. Furthermore, different Java run-time implementations will take varying approaches to garbage collection, but for the most part, you should not have to think about it while writing your programs.


238. this keyword in Java

By: Jagan : 2007-09-08

Description: Sometimes a method will need to refer to the object that invoked it. To allow this, Java defines the this keyword. this can be used inside any method to refer to the current object. That is, this is always a reference to the object on which the method was invoked. You can use this anywhere a reference to an object of the current class' type is permitted.


239. Use of - new - in Java

By: Henry : 2007-09-08

Description: The new operator dynamically allocates memory for an object. It has this general form:


240. right shift operator, >>, in Java

By: Emiley J : 2007-09-07

Description: The right shift operator, >>, shifts all of the bits in a value to the right a specified number of times. Its general form is shown here: