Skip to main content

Posts

JSON parsing in JAVA

JSON parsing in JAVA package jsonsample; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class JsonSample { public static void main(String[] args) { String str = "{'status': 'ok','found': true," + "'header': {'queried_sn': 'T0650GW872832', 'mfpro_env': 'deere_staging', 'elapsed_seconds': 2.314,'timestamp': '2012-06-14 07:12:18'}," + "'machine': { 'mfpro_machine': {'updated_at': '2012-05-22T10:23:54-04:00','matches': 3,'hours': 6809,'id': 1140530,'features': " + "[{'key': 'pat','label': 'Power-Angle-Tilt','feature_key': 'cons_blades'}]}," + "'make': {'name': 'John Deere','id': 100,'pi': null}," + ...

Dynamically adding content in Dropdown in Javascript

<html> <head> <script type="text/javascript"> function addOption(dropdown,text,value ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; dropdown.options.add(optn); } </script> </head> <select id="year" name="year" style="width: 70px" ></select> <script type="text/javascript"> var date = new Date(); var startYear = '2000' ; var currentYear = date.getFullYear(); do   {    addOption(document.getElementById("year"), currentYear, currentYear);    currentYear--;   } while (currentYear >= startYear); </script> </BODY> </html> *************Output*************

C# List Examples

C# List Examples 1. Adding values ~~~ Program that adds elements to List (C#) ~~~ using System.Collections.Generic; class Program {       static void Main()       {             List list = new List();             list.Add(2);             list.Add(3);             list.Add(5);             list.Add(7);       } } *********************************************************************************** 2. Adding objects. Using Add method ~~~ Program that uses Add method (C#) ~~~ using System.Collections.Generic; class Program {       static void Main()    ...

How to Stop Thread in Java

  Methods for Stopping a Thread     private volatile Thread thrd; public void stop() { thrd = null; } public void run() { Thread thisThread = Thread.currentThread(); while (thrd == thisThread) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } }   The volatile keyword is used to ensure prompt communication between threads.    A field may be declared as volatile , in which case a thread must reconcile its working copy of the field with the master copy every time it accesses the variable. Moreover, operations on the master copies of one or more volatile variables on behalf of a thread are performed by the main memory in exactly the order that the thread requested.”

Basic Java Interview Questions

1. Why java does not support multiple inheritance ? Answer :- To say why java doesn't support inheritance directly like c++ should be the diamond problem faced by c++,(Diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override it), and B and C have overridden this method differently, then via which class does it inherit: B, or C?) 2. JVM crash is an Error or Exception.? Answer:- JVM crash is an Error as a normal developer as we cannot handle it, but its exception for JVM developer as they can fix it. 3. Print “Hello World!” Without Main Method in Java? Answer:- public class Testing {    static    {        System.out.println("Hello World");    }    public static void main(String[] args)    {    } } ...

Toggle Event in Javascript

Toggle Event in Javascript This functions describes how the link toggles from On state to Off state. <script type="text/javascript"> function toggle_visibility(event) {              event = event || window.event;              var target = event.target || event.srcElement;        var id = target.id;        if(id == 'on')        {         document.getElementById("on").style.display = 'none';         document.getElementById("off").style.display = 'block';        }        else if(id == 'off')        {         document.getElementById("on").s...

Collections in Java

Collections in Java Introduction to Collections Framework The Collections Framework provides a well defined set of interfaces and classes for storing and manipulating the groups of data into a single unit. Introduction to Collections Framework Collections Framework: The Collections Framework provides a well-designed set of interfaces and classes for storing and manipulating the groups of data into a single unit. The collections framework is a unified architecture which is used to represent and manipulate collections. The framework allows the collections to get manipulated independently, additionally it reduces the programming efforts and increases performance. It includes implementation of interfaces and algorithms. Basically it is a unified architecture that consists the following collections: Interfaces: These are the abstract data types that represent collections. With the help of interfaces we manipulate collections independently. A hierarchy is generally formed ...