Programming Articles

Page 2545 of 2545

What is the difference between Java references and pointers in other languages?

Ali
Ali
Updated on 30-Jul-2019 424 Views

Reference datatypes in java are those which contains reference/address of dynamically created objects. These are not predefined like primitive data types. Following are the reference types in Java. class types − This reference type points to an object of a class. array types − This reference type points to an array. interface types − This reference type points to an object of a class which implements an interface. Once we create a variable of these types (i.e. when we create an array or object, class or interface). These variables only store the address of these values. Default ...

Read More

Why are classes sometimes declared final in Java?

Sreemaha
Sreemaha
Updated on 30-Jul-2019 677 Views

If a class is declared final, you cannot inherit it. If you try it gives you a compile-time error as − Example final class Super { private int data = 30; } public class Sub extends Sub { public static void main(String args[]){ } } Output Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Sub.main(Sub.java:7)

Read More

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 25441–25445 of 25,445 articles
« Prev 1 2541 2542 2543 2544 2545 Next »
Advertisements