The javax.json.JsonArray interface can represent an immutable JSON array and provides an unmodifiable list view of the values in the array. A JsonArray object can be created by reading JSON data from an input source and also using a static method createArrayBuilder() of javax.json.Json class. We need to import the javax.json package (download javax.json-api.jar file) in order to execute it.Syntaxpublic static JsonArrayBuilder createArrayBuilder()Exampleimport java.io.*; import javax.json.*; import javax.json.JsonObjectBuilder; public class JsonArrayTest { public static void main(String[] args) { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("Name", "Raja Ramesh"); builder.add("Designation", "Java Developer"); builder.add("Company", "TutorialsPoint"); ... Read More
The world is now embracing connectivity and communication like never before through the application of various mobility based devices. Mobile computing devices such as mobile phones, palmtops etc. have become a part of our daily routine as they are convenient and effective to use.Mobile IP (Internet Protocol) serves the needs of the burgeoning population of mobile computer users who wish to connect to the Internet and maintain communications as they move from place to place.Mobile IP (or MIP) is an Internet Engineering Task Force (IETF) standard communications protocol that is designed to allow mobile device users to move from one network ... Read More
The Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON format. We can deserialize a Java object from a Reader stream using the deserialize() method of JSONDeserializer class, it uses an instance of Reader class as JSON input.Syntaxpublic T deserialize(Reader input)Exampleimport java.io.*; import flexjson.JSONDeserializer; public class JSONDeserializeReaderTest { public static void main(String[] args) { JSONDeserializer deserializer = new JSONDeserializer(); String jsonStr = "{" + "\"firstName\": \"Adithya\", " + ... Read More
Looking to explore the world of online programming? then, there is good news to all of you!! Currently, there are few online programming websites which offer free services. Tutorialspoint is one such provider. Few years back, Tutorialspoint.com started compiler online service and based on the excellent response, the company has enhanced the service which is renamed as “Coding Ground”. It is a one stop solution for aspiring programmers and IT professionals to start coding in their relevant software without any installation requirement.The biggest technology innovators like Google, Microsoft or Amazon were built due to the consistent effort of programmers as ... Read More
A JSONObject is an unordered collection of a name and value pairs. A few important methods of JSONArray are accumulate(), put(), opt(), append(), write() and etc. The accumulate() method accumulates the values under a key and this method similar to the put() method except if there is an existing object stored under a key then a JSONArray can be stored under a key to hold all of the accumulated values. If there is an existing JSONArray then a new value can be added.Syntaxpublic JSONObject accumulate(java.lang.String key, java.lang.Object value) throws JSONExceptionExampleimport org.json.*; public class JSONAccumulateMethodTest { public static void main(String[] args) throws JSONException { ... Read More
A JSONObject can parse the text from String to produce a Map kind of an object. An Enum can be used to define a collection of constants, when we need a predefined list of values which do not represent some kind of numeric or textual data then we can use an enum. We can convert a JSON object to an enum using the readValue() method of ObjectMapper class.In the below example, we can convert/deserialize a JSON object to Java enum using the Jackson library.Exampleimport com.fasterxml.jackson.databind.*; public class JSONToEnumTest { public static void main(String arg[]) throws Exception { ObjectMapper mapper ... Read More
The Jackson @JsonInclude annotation can be used to exclude the properties or fields of a class under certain conditions and it can be defined using the JsonInclude.Include enum. The JsonInclude.Include enum contains few constants like "ALWAYS", "NON_DEFAULT", "NON_EMPTY" and "NON_NULL" to determine whether to exclude the property(field) or not.Syntaxpublic static enum JsonInclude.Include extends EnumExampleimport com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import java.io.*; public class JsonIncludeTest { public static void main(String args[]) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Employee emp = new Employee(); String jsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(emp); System.out.println(jsonString); } } // Employee class ... Read More
This example demonstrate about How to resize Image in Android App.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.sample ; import android.app.Activity ; import android.content.Intent ; import android.graphics.Bitmap ; import android.net.Uri ; import android.provider.MediaStore ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.ImageView ; import java.io.IOException ; ... Read More
The main difference between require and library is that require was designed to use inside functions and library is used to load packages. If a package is not available then library throws an error on the other hand require gives a warning message.Using library> library(xyz) Error in library(xyz) : there is no package called ‘xyz’Using requirerequire(xyz) Loading required package: xyz Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘xyz’Here we can see that the library shows an error and require gives a warning message, since warnings are mostly avoided ... Read More
The error “could not find function” occurs due to the following reasons −Function name is incorrect. Always remember that function names are case sensitive in R.The package that contains the function was not installed. We have to install packages in R once before using any function contained by them. It can be done as install.packages("package_name")The package was not loaded before using the function. To use the function that is contained in a package we need to load the package and it can be done as library("package_name").Version of R is older where the function you are using does not exist.If you ... Read More