
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

6K+ Views
JSON is a lightweight data interchange format. It is mostly used in web applications for sending and receiving data. To know more about JSON, refer JSON. A JSON array is a collection of JSON objects. It is similar to a list in Java. CSV is the format for storing tabular data in plain text. It is a comma-separated value. It is used for data exchange between applications. Let's see how CSV format looks like: JSON array The following is an example of the JSON array: [ { "Name": "Ansh", ... Read More

4K+ Views
JSON is a data interchange format that is easy to read and write. It is lightweight and gets parsed easily. It is commonly used in web applications for sending and receiving data. To know more about JSON, refer to JSON. Pretty print is a type of formatting that formats data in a more easily readable way by adding indentation and line breaks. It is useful for debugging and logging purposes. Enabling pretty print Using Gson Library Gson is a JSON library for Java, which was created by Google. By using Gson, we can generate JSON and convert JSON to Java objects. ... Read More

357 Views
The StringTokenizer class allows an application to break a string into tokens. Following are the methods −Sr.NoMethod & Description1int countTokens()This method calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.2boolean hasMoreElements()This method returns the same value as the hasMoreTokens method.3boolean hasMoreTokens()This method tests if there are more tokens available from this tokenizer's string.4Object nextElement()This method returns the same value as the nextToken method, except that its declared return value is Object rather than String.5String nextToken()This method returns the next token from this string tokenizer.6String nextToken(String delim)This method returns the next token in this ... Read More

2K+ Views
To traverse through a HashMap, use Iterator. The HashMap class uses a hashtable to implement the Map interface. This allows the execution time of basic operations, such as get( ) and put( ), to remain constant even for large sets.Following is the code to traverse through a HashMap −Exampleimport java.util.*; public class Main { public static void main(String args[]) { HashMap hashMap = new HashMap(); hashMap.put("John", new Integer(10000)); hashMap.put("Tim", new Integer(25000)); hashMap.put("Adam", new Integer(15000)); hashMap.put("Katie", new Integer(30000)); hashMap.put("Jacob", new Integer(45000)); ... Read More

7K+ Views
The new operator is used in Java to create new objects. It can also be used to create an array object.Let us first see the steps when creating an object from a class −Declaration − A variable declaration with a variable name with an object type.Instantiation − The 'new' keyword is used to create the object.Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.Now, let us see an example −Examplepublic class Puppy { public Puppy(String name) { // This constructor has one parameter, name. ... Read More

1K+ Views
Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class. Nested classes are divided into two types −Non-static nested classes (Inner Classes) − These are the non-static members of a class.Static nested classes − These are the static members of a class.Following are the types of Nested classes in Java −Non-static nested classes (Inner Classes)Inner classes are a security mechanism in Java. We know a class cannot be associated with the access modifier private, but if we have the class as a ... Read More

219 Views
The compareUnsigned() method compares two integer objects numerically considering the values as unsigned.The return value if 0 if both values are equal; -1 if the val1is less than val2. The return value is 1, if the val1 is more than val2.At first, set two Integer objects −int val1 = 50; int val2 = -10;Now, compare them considering the values as unsigned −System.out.println(Integer.compareUnsigned(val1, val2));Following is an example to implement the compareUnsigned() method in Java −Examplepublic class Main { public static void main(String[] args) { int val1 = 50; int val2 = -10; ... Read More

8K+ Views
The java.lang.Integer.compareTo() method compares two Integer objects numerically. This method returns the value 0 if this Integer is equal to the argument Integer, a value less than 0 if this Integer is numerically less than the argument Integer and a value greater than 0 if this Integer is numerically greater than the argument Integer.At first, set two Integer objects −Integer obj1 = new Integer("100"); Integer obj2 = new Integer("200");Now, compare those object −int res = obj1.compareTo(obj2);Following is an example to implement the compareTo() method in Java −Examplepublic class Main { public static void main(String[] args) { Integer obj1 ... Read More

2K+ Views
Integer compare() Method The compare() method in the Integer class is a part of the Java interface and is used to compare two integers. It provides a way to compare two Integer objects or primitive int values and determine their relative ordering. This method is particularly useful when sorting or working with collections that involve integer values. Syntax public static int compare(int x, int y);Where − x: The first integer to be compared. y: The second integer to be compared. Return Value The compare() method returns an integer value that ... Read More

217 Views
The byteValue() method returns the value of this Integer as a byte.Following is an example to implement the byteValue() method in Java −Examplepublic class Main { public static void main(String[] args) { Integer val = new Integer(10); byte res = val.byteValue(); System.out.println("Value = " + res); } }OutputValue = 10Let us see another example −Exampleimport java.util.*; public class Main { public static void main(String[] args) { Byte b = new Byte("10"); byte res = b.byteValue(); System.out.println("Byte = " + b ); System.out.println("Primitive byte = "+ res); } }OutputByte = 80 Primitive byte = 80