<< Chapter < Page | Chapter >> Page > |
This book will explain how to use the following classes:
An investigation into the use of the other classes and interfaces will be left as "an exercise for the student" .
I encourage you to copy the code from Listing 1 . Execute the code and confirm that you get the same results as those shown in Figure 1 . Experiment with the code, making changes, and observing the results of your changes. Make certain that youcan explain why your changes behave as they do.
Listing 1 provides the source code for the program named Code.java .
/********************************************************************
Copyright 2016, R.G.BaldwinEstablishes the position of each of the json-simple classes in the
class hierarchy by getting and displaying the superclass of eachclass.
Produces the following output:ItemList: class java.lang.Object
JSONArray: class java.util.ArrayListJSONObject: class java.util.HashMap
JSONParser: class java.lang.ObjectJSONValue: class java.lang.Object
ParseException: class java.lang.ExceptionYytoken: class java.lang.Object
Tested with Java 8, Windows 7, and json-simple-1.1.1.jar********************************************************************/
import org.json.simple.JSONObject;import org.json.simple.JSONArray;
import org.json.simple.JSONValue;import org.json.simple.ItemList;
import org.json.simple.JSONAware;import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;import org.json.simple.parser.Yytoken;
class Code{public static void main(String[] args){System.out.println("ItemList: " +
new ItemList().getClass().getSuperclass());System.out.println("JSONArray: " +
new JSONArray().getClass().getSuperclass());System.out.println("JSONObject: " +
new JSONObject().getClass().getSuperclass());System.out.println("JSONParser: " +
new JSONParser().getClass().getSuperclass());System.out.println("JSONValue: " +
new JSONValue().getClass().getSuperclass());System.out.println("ParseException: " +
new ParseException(ParseException.ERROR_UNEXPECTED_CHAR).getClass().getSuperclass());
System.out.println("Yytoken: " +new Yytoken(Yytoken.TYPE_COLON,":").
getClass().getSuperclass());}//end main
}//end class code
This section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
-end-
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?