Found 9321 Articles for Object Oriented Programming

How to compile a java program

Akshaya Akki
Updated on 12-Sep-2023 02:07:51

32K+ Views

Compiling a Java program is very easy after JDK installation. Following are the steps −Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\.Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption: The path variable is set).The file is compiled and you can see MyFirstJavaProgram.class file generated in the same folder.

How can we edit a java program?

Alankritha Ammu
Updated on 30-Jul-2019 22:30:21

557 Views

Java programs are simple text-based programs and can be edited using any text editor like notepad etc. The filename should be same as class name.

What are the key features of Java?

Debarpito Sarkar
Updated on 05-Sep-2022 12:08:11

4K+ Views

This article will help you understand what the key features of Java Programming language are. The Key features of Java Programming Language are − Java is Easy to Understand Java’s base is similar to that of C and C++ languages and it includes many important features of these languages. It removes many drawbacks and complexities of C or C++. So if one has good understanding of either C or C++, then Java language will be very familiar and easily understandable. Java is an object oriented programming language Object Oriented Programming (OOP) is an approach to standardize the programs by creating ... Read More

What does the method toArray() do?

karthikeya Boyini
Updated on 12-Mar-2020 12:16:49

662 Views

The toArray() method of the java.util.The ArrayList class returns an array containing all of the elements in this list in proper sequence (from first to the last element). This acts as a bridge between array-based and collection-based APIs.ExampleLive Demoimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String[] args) {       ArrayList arrlist = new ArrayList(5);       arrlist.add(20);       arrlist.add(40);       arrlist.add(10);       arrlist.add(15);       arrlist.add(25);       for (Integer number : arrlist) {          System.out.println("Number = " + number);       ... Read More

How to find package explorer in Java eclipse project?

V Jyothi
Updated on 20-Feb-2020 05:19:59

20K+ Views

To view the project explorer, click on Window menu then, click on Show View and select Project Explorer.There is simpler way to open project explorer, when you are in the editor press alt + shift + w and select project explorer.

How to convert a list collection into a dictionary in Java?

Nikitha N
Updated on 30-Jul-2019 22:30:21

1K+ Views

Following is an example to convert a list collection into a dictionary in Java.Example Live Demoimport java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; public class CollectionDictionary {    public static void main(String[] args) {       ArrayList list = new ArrayList();       list.add("JavaFx");       list.add("Java");       list.add("WebGL");       list.add("OpenCV");       System.out.println(list);       Dictionary dictionary = new Hashtable();       Hashtable hashTable = new Hashtable();       hashTable.put(1, list.get(0));       hashTable.put(2, list.get(1));       hashTable.put(3, list.get(2));       hashTable.put(4, list.get(3));       System.out.println(hashTable);    } }Output[JavaFx, Java, WebGL, OpenCV] {4=OpenCV, 3=WebGL, 2=Java, 1=JavaFx}

How to copy or clone a Java ArrayList?

Abhinanda Shri
Updated on 25-Feb-2020 09:50:14

1K+ Views

The clone() method of the java.util.ArrayList class returns a shallow copy of this ArrayList instance (i.e the elements themselves are not copied). Using this method, you can copy the contents of one array list to other.Exampleimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String args[]) {       ArrayList arrlist1 = new ArrayList();       arrlist1.add(new StringBuilder("Learning-"));       ArrayList arrlist2 = (ArrayList) arrlist1.clone();       StringBuilder strbuilder = arrlist1.get(0);       strbuilder.append("list1, list2-both pointing to the same StringBuilder");       System.out.println("The 1st list prints: ");       for (int i = ... Read More

How to compare two ArrayList for equality in Java?

Srinivas Gorla
Updated on 30-Jul-2019 22:30:21

12K+ Views

You can compare two array lists using the equals() method of the ArrayList class, this method accepts a list object as a parameter, compares it with the current object, in case of the match it returns true and if not it returns false.Example Live Demoimport java.util.ArrayList; public class ComparingList {    public static void main(String[] args) {       ArrayList list1 = new ArrayList();       list1.add("JavaFx");       list1.add("Java");       list1.add("WebGL");       list1.add("OpenCV");       ArrayList list2 = new ArrayList();       list2.add("JavaFx");       list2.add("Java");       list2.add("WebGL"); ... Read More

How to use remove(obj), remove(index), and removeAll() methods in Java list collections?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

140 Views

remove(int index) − Removes the element at position index from the invoking list and returns the deleted element. The resulting list is compacted. That is, the indexes of subsequent elements are decremented by one. removeRange(int fromIndex, int toIndex) − Removes all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. removeAll(Collection c) − Removes from this list all of its elements that are contained in the specified collection (optional operation).

How to iterate over a Java list?

Abhinaya
Updated on 30-Jul-2019 22:30:21

11K+ Views

Often, you will want to cycle through the elements in a collection. For example, you might want to display each element.The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list and the modification of elements.Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator() method that returns an iterator to the start of the ... Read More

Advertisements