Object Oriented Programming Articles

Page 482 of 589

Where and how can I create a private constructor in Java?

Swarali Sree
Swarali Sree
Updated on 25-Feb-2020 411 Views

We can use a private contractor in a Java while creating a singleton class. The Singleton's purpose is to control object creation, limiting the number of objects to only one. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. Singletons often control access to resources, such as database connections or sockets.ExampleThe easiest implementation consists of a private constructor and a field to hold its result, and a static accessor method with a name like getInstance().The private field can be assigned from within a static initializer block ...

Read More

What does the method ensureCapacity(int, minCapacity) do in java?

Govinda Sai
Govinda Sai
Updated on 25-Feb-2020 210 Views

The ensureCapacity(int minCapacity) method of the class java.util.ArrayList increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.Exampleimport java.util.ArrayList; public class ArrayListDemo { public static void main(String args[]) { ArrayList arrlist = new ArrayList(5); arrlist.add(10); arrlist.add(50); arrlist.add(30); arrlist.ensureCapacity(15); for (Integer number : arrlist) { System.out.println("Number = " + number); } } }OutputNumber = 10 Number = 50 Number = 30

Read More

What does the method contains(obj o) do in java?

Nikitha N
Nikitha N
Updated on 25-Feb-2020 178 Views

The contains(Object) method of the java.util.ArrayList class returns true if this list contains the specified element.Exampleimport java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { ArrayList arrlist = new ArrayList

Read More

What is the Java Runtime Environment (JRE)?

Ayyan
Ayyan
Updated on 25-Feb-2020 697 Views

JRE is Java Runtime Environment and is the machine-specific implementation of JVM. It contains libraries like rt.jar, class loaders etc which are used by JVM.

Read More

Initialization, declaration and assignment terms in Java

Arushi
Arushi
Updated on 25-Feb-2020 2K+ Views

A variable provides us with named storage that our programs can manipulate. Each variable in Java has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.You must declare all variables before they can be used. Following is the basic form of a variable declaration − data type variable [ = value][, variable [ = value] ...] ;Here data type is one of Java's datatypes and variable is the name of the variable. To ...

Read More

Best book to learn Java programming for beginners

Daniol Thomas
Daniol Thomas
Updated on 25-Feb-2020 325 Views

Following books are on top from popularity and content wise and are a good resource to learn java programming from beginner to advance level.

Read More

Method overloading with autoboxing and widening in Java.

Arjun Thakur
Arjun Thakur
Updated on 25-Feb-2020 326 Views

Widening refers to passing a lower size data type like int to a higher size data type like long. Method overloading is possible in such case. Example public class Tester {     public static void main(String args[]) {         Tester tester = new Tester();         short c = 1, d = 2;         int e = 1, f = 2;         System.out.println(tester.add(c, d));         System.out.println(tester.add(e, f));     }     public int add(short a, short b) {         System.out.println("short");         return a + b;     }     public int add(int a, int b) {         System.out.println("int");         return a + b;     } } Output Short 3 Int 3

Read More

Which is the best book for Java interview preparation

Krantik Chavan
Krantik Chavan
Updated on 25-Feb-2020 219 Views

Following books are on top from popularity and content wise and are a good resource to learn java programming from beginner to advance level.

Read More

Pass by reference vs Pass by Value in java

Giri Raju
Giri Raju
Updated on 25-Feb-2020 7K+ Views

Call by Value means calling a method with a parameter as value. Through this, the argument value is passed to the parameter. While Call by Reference means calling a method with a parameter as a reference. Through this, the argument reference is passed to the parameter. In call by value, the modification done to the parameter passed does not reflect in the caller's scope while in the call by reference, the modification done to the parameter passed are persistent and changes are reflected in the caller's scope. But Java uses only call by value. It creates a copy of references ...

Read More

Passing array to method in Java

Jai Janardhan
Jai Janardhan
Updated on 25-Feb-2020 441 Views

Just as you can pass primitive type values to methods, you can also pass arrays to methods. For example, the following method displays the elements in an int array -Examplepublic static void printArray(int[] array) {    for (int i = 0; i < array.length; i++) {       System.out.print(array[i] + " ");    } }You can invoke it by passing an array. For example, the following statement invokes the print Array method to display 3, 1, 2, 6, 4, and 2 -printArray(new int[]{3, 1, 2, 6, 4, 2});

Read More
Showing 4811–4820 of 5,881 articles
« Prev 1 480 481 482 483 484 589 Next »
Advertisements