
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

5K+ Views
Once you write a Java program you need to compile it using the javac command, this shows you the compile time errors occurred (if any).Once you resolve them and compile your program success fully, an executable file with the same name as your class name is generated in your current folder, with the .class extension.Then you need to execute it using the java command as −java class_nameWhile executing, when JVM does not find a .class file with the specified name then a run time error occurs saying “Could not found or load main class” error as −D:\sample>java Example Error: Could ... Read More

20K+ Views
The given task is to overwrite a line in a .txt file with new content. Assume we have a .txt file with the following content - Line 1: Hello World Line 2: This is a test file. Line 3: This line will be overwritten. Line 4: Goodbye! We want to overwrite line 3 with "This line has been changed". Following will be the resultant content - line 1: Hello World line 2: This is a test file. line 3: This line has been changed. line 4: Goodbye! Overwriting a Line in a ".txt" File There are no direct methods ... Read More

622 Views
The split() method of the String class. splits the current string around matches of the given regular expression. The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string.The replaceAll() method of the String class accepts two strings representing a regular expression and a replacement String and replaces the matched values with given String.To replace all the characters in of a file with '#' except a particular word (one way) −Read the contents of a file to a String.Create ... Read More

15K+ Views
The java.text package provides a class named SimpleDateFormat which is used to format and parse dates in required manner (local).One of the constructors of this class accepts a String value representing the desired date format and constructors SimpleDateFormat object.The format() method of this class accepts a java.util.Date object and returns a date/time string in the format represented by the current object.Therefore, to parse a date String to another date format −Get the input date string.Convert it into java.util.Date object.Instantiate the SimpleDateFormat class by passing the desired (new) format as string to its constructor.Invoke the format() method by passing the above ... Read More

2K+ Views
Using regular expressionYou can find whether a particular String value contains ASCII characters using the following regular expression −\A\p{ASCII}*\zThe matches() method of the String class accepts a regular expression and verifies whether the current string matches the given expression if so, it returns true, else it returns false.Therefore, Invoke the matches() method on the input/required string by passing the above specified regular expression as a parameter.Example Live Demoimport java.util.Scanner; public class OnlyASCII { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string value: "); String input ... Read More

5K+ Views
You can initialize the array variable which is declared inside the class just like any other value, either using constructor or, using the setter method.ExampleIn the following Java example, we are declaring an instance variable of array type and initializing it from the constructor. Live Demopublic class Student { String name; int age; String subs[]; Student(String name, int age, String subs[]){ this.name = name; this.age = age; this.subs = subs; } public void display() { System.out.println("Name: "+this.name); System.out.println("Age :"+this.age); System.out.print("Subjects: "); for(int i = 0; i < subs.length; i++) { ... Read More

949 Views
ArrayList to ArrayList Instead of the typed parameter in generics (T) you can also use “?”, representing an unknown type. These are known as wild cards you can use a wild card as − Type of parameter or, a Field or, a Local field. Using wild cards, you can convert ArrayList to ArrayList as − ArrayList stringList = (ArrayList)(ArrayList)(list); Example import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; public class ArrayListExample { public static void main(String args[]) { //Instantiating an ArrayList object ... Read More

9K+ Views
Jackson is a Java-based library, and it can be useful for converting Java objects to JSON and JSON to Java objects. A Jackson API is faster than other API, needs less memory, and is good for large objects. We can convert a JSON array to a list using the ObjectMapper class. It has a useful method, readValue(), which takes a JSON string and converts it to the object class specified in the second argument. Before proceeding further, first of all, we need to import the Jackson library into our project. To do this, you can add the following dependency to ... Read More

1K+ Views
The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can serialize a list of objects using the serialize() method of JSONSerializer class. This method can perform a shallow serialization of the target instance. We need to pass a list of objects of List type as an argument to the serialize() method.Syntaxpublic String serialize(Object target)Exampleimport flexjson.JSONSerializer; import java.util.*; public class JsonSerializeListTest { public static void main(String[] args) { JSONSerializer serializer = new JSONSerializer().prettyPrint(true); // pretty print JSON Student s1 = new Student("Raja", "Ramesh", 28, "Hyderabad"); Student s2 = new Student("Suresh", "Kumar", 30, "Chennai"); ... Read More

7K+ Views
JSON is a format for storing and exchanging data. It is easily readable and also easy to parse. Creating JSON Using Java JsonGenerator In Java, we can create a JSON object using the JsonGenerator class. JsonGenerator is class in the javax.json.stream package that is used to create JSON data. It provides methods to write JSON objects, arrays, and values. To use the JsonGenerator class, we need to add the javax.json library to our project. If you are using Maven, add this to your pom.xml file: javax.json javax.json-api 1.1.4 If you are not using Maven, you can download ... Read More