Programming Articles

Page 2544 of 2544

What are tokens in Java?

Johar Ali
Johar Ali
Updated on 30-Jul-2019 2K+ Views

Java tokens are smallest elements of a program which are identified by the compiler. Tokens in java include identifiers, keywords, literals, operators and, separators.

Read More

How to convert Java Array/Collection to JSON array?

Sravani S
Sravani S
Updated on 30-Jul-2019 8K+ Views

Google provides a library named org.json.JSONArray and, following is the maven dependency to add library to your project. com.googlecode.json-simple json-simple 1.1 The JSONArray class of the org.json package provides put() method. Using this method, you can populate the JSONArray object with the contents of the elements.Exampleimport org.json.JSONArray; public class ArrayToJson { public static void main(String args[]) { String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"}; JSONArray jsArray = new JSONArray(); ...

Read More

Do local variables in Java have default values?

Ali
Ali
Updated on 30-Jul-2019 1K+ Views

No, local variables do not have default values. Once we create a local variable we must initialize it before using it. Since the local variables in Java are stored in stack in JVM there is a chance of getting the previous value as default value. Therefore, In Java default values for local variables are not allowed. Example public class Sample { public static void main(String args[] ){ int data; System.out.println(data); } } Error C:\Sample>javac Sample.java Sample.java:4: error: variable data might not have been initialized System.out.println(data); ^ 1 error

Read More
Showing 25431–25433 of 25,433 articles
« Prev 1 2540 2541 2542 2543 2544 Next »
Advertisements