Friday, 31 August 2012

Google Tips & Tricks

Here I am giving few google tips & tricks. Few are funny and few are useful for developers.

1. zerg rush:
Just go to google.com and type "zerg rush" in google search and press enter. Now you have to protect your page from enemies. Try this it is so funny.


2. do a barrel roll:
In google search just type "do a barrel roll" and press enter.


3. gravity:
In google search type "gravity" and press "I'm Feeling Lucky" button.


4. Web History:
If you are logged in through gmail account and browsing on the web, then you can retrieve all your history. Google maintains your search history for you. In the right upper corner there is one button called option. Click this button and go to web history. Here it will ask you for login, after login it will give you all your history.


5. See visited pages by you:
Write keyword in search bar for which you want to see visited pages. Now in the left side panel at the bottom you will see "The web" option in that click "More search tools". In that you will find option of "Visited pages". Click that option and you will get visited pages.


6. Create open source project with google:
Go to "More" option present at top of your google page. In that click "Even more". Here at the bottom of page you will find option of "Code". Click this option and you will all information about creating open source projects.

I will try to add more.

Thursday, 30 August 2012

G-mail Tips & Tricks


In this post I am giving few Gmail tips and tricks. These tips and tricks can be used by general user of g-mail  for maintaining his/her emails properly and customizing layout properly. It may be used by developers as well. So here is first trick for developers,


1. If you want to test application which dose not allow to send or receive emails from same email address then you can use following trick, If your email address is abc@gmail.com and you are sending emails to abc+1@gmail.com, abc+2@gmail.com and so on then all emails will be forwarded to abc@gmail.com only. Instead of +1, +2 you can use +a, +b... and so on.

2.  Click settings button which is present at right upper corner. Then drop down menu will be displayed, in that menu again select "Settings". In that select "Labs" tab. Here are all crazy stuffs of g-mail. Here I am giving few of them,
1. SMS in chat:
It will allow you to send text messages (SMS) in chat.
2. Extra Emoji:
Here you will get extra smilly icons to use.
3. Unread message icon:
  It will show your unread messages at top just near to page title.
4. Google calender:
Very useful for saving important events with phone sync facility.
        5. Voice player:
                It will allow you to play voice mails.
In this way there are many facilities are provided in this "Labs" tab. You can check out all of them. Every feature is interesting.

3. Under the same "Settings" menu you have "Themes" option using which you can change theme of your email account. Try out these themes.

4. If you are switching from one account to another account then g-mail provides you facility to redirect all your mails to new account. You will find this option under settings in "Accounts and import". In this tab find out option "Import mail and contacts". In learn more section of this option you will get detailed information.

5. If you want to forward email coming from specific account then under "Settings" menu in "Forwarding and POP/IMAP" tab you will find that option. Under learn more section details are given.

6. You can create filter with different options for specific email addresses. For this under "Settings" menu select "Filter" tab. In that at the bottom there is option "Create a new filter". On click of this option you will get one form. fill up that form and move forward and filter will be created. Here you can do following things with mail from specific account.
     a. Directly add to archive by skipping inbox.
     b. Mark as read.
     c. Star it.
     d. You can apply specific label.
     e. You can directly forward it to specific email address.
     f. Even you can directly delete that email.
     g. And few more...

These are few interesting tips and tricks I will try to add more......Enjoy it.

Wednesday, 29 August 2012

Writing Plugins For Phonegap In Android


Note: Here it is assumed that you have properly running Phone gap project.
Writing plugins is very easy for android in phonegap. Here are simple four steps to write plugins.


1.  Create TestingPlugin.java class in src folder of your eclipse project.
Replace that file with following code,
Code:
package src.com.testing; 
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
public class TestingPlugin extends Plugin { 
      @Override
      public PluginResult execute(String action, JSONArray data, String callbackId) {
            try {
                  return new PluginResult(PluginResult.Status.OK, "Process successful");
            } catch(Exception e) {
                  return new PluginResult(PluginResult.Status.ERROR, "Process fail");
            }
      }

} 
Remember one thing that, method from plugin class can return PluginResult only.


2. Now in your www folder create one html file and use following code,
Code:
<!DOCTYPE HTML>
<html>
<head>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="stylesheets/jquery.mobile-1.1.0.min.css" />
      <script src="scripts/jquery-1.7.1.min.js"></script>
      <script src="scripts/TestingPlugin.js"></script>
      <script src="scripts/jquery.mobile-1.1.0.min.js"></script>
      <script type="text/javascript" charset="utf-8" src="scripts/cordova-2.0.0.js"></script>
      <script type="text/javascript">
      function onBodyLoad()
      {          
            document.addEventListener("deviceready", onDeviceReady, false);
      }
      function onDeviceReady() {
            navigator.notification.alert("Testing")
      }
    function callNativePlugin( returnSuccess ) {
        TestingPlugin.callNativeFunction( success, fail, returnSuccess );
    }
    function success (result) {
       alert("SUCCESS: \r\n"+result );
    }
    function fail (error) {
       alert("ERROR: \r\n"+error );
    }
    </script>
    </head>
      <body onload="onBodyLoad()">
            <h1>Testing</h1> 
            <button onclick="callNativePlugin('Your_parameters');">Invoke plugin</button>
      </body>
</html>

Here include all necessary scripts carefully. Important script is highlighted here. It is necessary for calling plugin function.


3. Now in "www -> scripts" folder create TestingPlugin.js file and use following code.
Code:
var TestingPlugin = {
    callNativeFunction: function (success, fail, resultType) {
      return cordova.exec(success, fail, "src.com.testingplugin.TestingPlugin", "nativeAction", [resultType]);
    }
};



4.  Now open "res -> xml -> plugins.xml" file and past following line of code under <plugins></plugins> tag,
Code:
<plugin name=”src.com.testingplugin.TestingPlugin” value=” src.com.testingplugin.TestingPlugin”/>


5. And here you are ready to go. Here for every facility you have to write one class. 

Enjoy plugins....

JSON Format

1. JSON stands for "Java Script Object Notation".

2. We generally use JSON for information exchange between two entities. Entity's may be two methods, two computers connected in network, mobile and server etc. In any case you can use JSON format for information exchange.

3. Sometimes we can use JSON for storing information. We may store information in file with low space and processing power. Generally we use JSON and XML databases with low power processing devices like mobiles, where there are many limitations.

4. JSON is running with many characteristics as given below,
     a. JSON is platform independent.
     b. JSON is language independent.
     c. JSON is light weight.
     d. Much like XML but less complicated.

5. JSON parser's are available in nearly each language. Here I am giving sample JSON format,
Ex.

{
"Major1" : "Record1",
"Major2" : [{"Minor1" : "Record2"},
   {"Minor2" : "Record3"}
  ]
}
This means under key "Major1" we have value "Record1", under key "Major2" we have another key value pairs which are {"Minor1" : "Record2"} and {"Minor2" : "Record3"}.
In short this JSON format always works in key value pair.

6. If you want to validate your JSON, then there are number of online JSON validators are available.
Just google it with search string "Online JSON validators".

7. Here is simple code for JSON extraction in java,
public String getElement(jsonString, key) {
     JSONObject jo=new JSONObject(jsonString);

     return jo.get(key).toString();
}
Now you can call this getElement function to get value of specific key.

8. Here is simple code in java script,
var JSONObject = {"name" : "This is name"};
Now if you want value of name then use,
JSONObject.name;
That's it.

9. In this way you can construct string at the side from where you want to send data and at receiving end simply extract data using JSON extraction facility provided by language.

Tuesday, 28 August 2012

SQL Clauses

SQL stands for "Structured Query Language". SQL supports four major tags INSERT, UPDATE, DELETE and WHERE. Here I am explaining some rare tags.

1. TOP:
Top clause is use to get some top records from result of our query. We can retrieve top records in numbers or in percentage.

Ex. If we fire query like, 
“SELECT * FROM user” 
then it will return you all records from user table. In this case if you want to retrieve first 10 records or 25% records of all users then you can use this TOP clause.

Ex. SELECT TOP 10 * FROM user
      SELECT TOP 25 PERCENT FROM user
    

2. Alias:
Alias (AS) is used to give shortcut name to long table names. We can use this alias in from clause.

Ex. If you are running with table names as userSalaryTableOfXyz then writing this name every time will be tedious task for coder. In this case alias can be used as given below,
SELECT u.name from userSalaryTableOfXyz AS u where id<3


3. UNION:
Union is used to combine results of two SELECT clauses. But necessary things in union is that, for both SELECT’s number of columns, data types and order must be same. You can union as given below.

Ex. SELECT name from user where id=1
      UNION
      SELECT name from user where id=2
It will give you distinct results from both SELECT clauses. If you want to get all records then simply replace UNION by UNION ALL


4. Wildcard charlist:
Charlist is use when you want match specific alphabets at specific position. Let’s see an example so that idea will be clear.

Ex. SELECT name FROM user WHERE name LIKE ‘[xyz]%’
It will give you names starting with x or y or z.
Also you can try,
SELECT name FROM user WHERE name LIKE ‘[!xyz]%’
It will give you all name not starting with x or y or z.


5. INDEX:
Indexes are manly use for fast searching or getting fast results from query.  You can apply indexing on particular column of table. But there is disadvantage of indexing. If you are applying indexing the search will be fast but updates will be slower, because when you update table records the indexes are also needs to be updated.
Syntax for creating index is,

Ex. CREATE INDEX xyz on tableAbc (column_name).



Saturday, 25 August 2012

OOP's Objective Questions & Answers

1. Which of the following is not the member of class?
   a) Static function
   b) Friend function
   c) Constant function
   d) Virtual function
Ans. Friend function.

2. Which of the following is an abstract data type?
   a) int
   b) double
   c) String
   d) Class
Ans. Class

3. Which of the following correctly describes overloading of functions?
   a) Virtual polymorphism
   b) Transient polymorphism
   c) Ad-hoc polymorphism
   d) Pseudo polymorphism
Ans. Ad-hoc polymorphism.

4. Which of the following approach is adapted by c++?
   a) Top-down
   b) Bottom-up
   c) Right-left
   d) Left-right
Ans. Bottom-up.

5) Dispatch mechanism is implemented using ...
   a) Inheritance
   b) Polymorphism
   c) Dynamic method dispatch
   d) Abstraction
Ans. Polymorphism.

6) Which of the following statements regarding inline functions are correct ?
   a) It speeds up the execution
   b) It slows down the execution
   c) It increases the code size
   d) Both A & C
Ans. Both A & C.

7. What is size of object of empty class?
   a) 0 byte
   b) 1 byte
   c) 4 bytes
   d) 8 bytes
Ans. 1 byte.

8. Deadly Diamond of Death problem occurs because of ...
   a) Multiple inheritance
   b) Multilevel inheritance
   c) Hybrid inheritance
   b) None
Ans. Hybrid inheritance.

9. When we create object, reference of object is stored on ...
   a) Heap
   b) Stack
   c) MainMemory
   d) None
Ans. Stack

10. Can we have static and constant function in class?
   a) Yes
   b) No
Ans. No

Wednesday, 22 August 2012

System.out.print() - Java

In core java System.out.print() is mainly used to print something on screen. Here is little deep analysis of this statement.
System is very useful class in java. It is present from JDK 1.0.
Ex. System.out.print("Hello..."); //It will simply print [Hello...] on screen.

1. System class shows three fields in, out, err. All three fields are streams.

2. System class is public and final by nature.

3. Out of three err and out are of type PrintStream and in is of type InputStream.

4. All three streams are public, static and final by nature. public means can be accessed anywhere, static means we can use these streams without object of System class and final means we can't override these streams.

5.  PrintStream is a class in java.io package which is public by nature.

6. PrintStream class shows [public void print method()].

7. InputStream is a class present in java.io package which is public and abstract by nature.

8. InputStream shows methods like read().

9. out and err are streams which displays output to standard output device means monitor. But we can redirect output to some other device.

10. in is a stream which supplies input data from standard input device i.e. keyboard. But we can use some other device as well.

11.  So finally we are using print and println methods of PrintStream class through System.

Tuesday, 21 August 2012

printf tricks - C Programming

Here I am trying to put some variations of printf statement in C language. These are not all, so lets share the other variations that you know. Here I am assuming that we have little knowledge of C language.
Here I am starting with printf function.

1. printf():
printf function is mainly used to display something on screen in formatted manner.

Ex. 1
printf function executes its parameters from right to left. Here is example,
int a = 10, b = 20;
printf("%d      %d", (a+b), b+=5);
It will display [35      25].

Ex. 2
char a = 'a';
printf("%c      %c      %c", a, a++, a++);
It will output [c      b      a].

Ex. 3
Printf function displays some default values initially.
int a = 10, b = 20, c = 30;
printf("%d      %d      %d");
It will display [30      20      10]. Here also it executes parameters from right.

Ex. 4
If you want to print hex equivalent of integer then use following way,
int a = 12;
printf("%x", a);

Ex. 5
int a = 14;
printf("%4x", a); //It will print hex equivalent of integer but in right justified manner.
printf("%04x"); //It will display int in hex format with right justification with leading places filled with 0's.
printf("%*d", a); //It will leave blanks before number equivalent to that number.

Ex. 6
Printing substring.
char c[5] = {'a', 'b', 'c', 'd', '\0'};
printf("%.*s", 2, c);
It will print [ab] as output.

Ex. 7
int a = 0;
printf("%.0d", a); //It will print only non zero numbers. In this case output will be blank.

If you have more variations then you can share here.

Monday, 20 August 2012

HTML5 Awsome Quiz Questions & Answers - 3

1. What is application cache in HTML5.
AnsHTML5 shows new concept application cache, with this the web application will be cached, and will be accessible without an internet connection.

Application cache shows following advantages,
Offline browsing - You can browse offline(Pages those are cached).
Speed - It can load cached pages more faster.
Reduced server load - the browser will only download updated/changed resources from the server.

For this application cache manifest file shows three sections, cache manifest, network, fallback.

2. State new media elements in HTML5.
Ans. a) Audio   b) Video   c) track   d) embed   e) source

3. Data list is used with...
a) Input elements   b) Output elements   c) List elements   d) None
Ans. Input elements.
This data list is used with input elements to show pre-defined elements to user for that input element.

4. In <bdi>, dbi stands for....
a) Bi-directional Isolation   b) Bi-directional Indexing   c) Bi-detection Indexing   d) None
AnsBi-directional Indexing.

5. Which of the following browsers supports bdi tag of HTML5
a) IE   b) Opera   c) Safari   d) Firefox
Ans. Firefox.

6. bdi tag supports event attributes.
a) True   b) False
Ans. True

7. details tag is supported by...
a) Firefox   b) Safari   c) Maxthon   d) None
Ans. None. It is supported by only chrome.

8. Which of the following browser dose not support wbr tag?
a) IE   b) Firefox   c) Maxthon   d) Opera
Ans. IE

9. There are _ type(s) of storage HTML5 supports.
a) 1   b) 2   c) 3   d) 4
Ans. 2

10. New attributes for form are..
a) list   b) pattern   c) nonvalidate   d) required
Ansnonvalidate   

Notification - Android

Here I am presenting simple example of notification in android. In android notification is shown in status bar at the top of screen. For this purpose we don't need to set any permission. Here is code for notification in android,

Notify.java

package com.android;


import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Notify extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button notificationButton = (Button)findViewById(R.id.notificationButton);
        notificationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Timer timer = new Timer();
                timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        notification("Title","Message");
                    }
                },0);
            }
        });
    }

    // Notification Function
    private void notification(String notificationTitle, String notificationMessage) {
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.icon, "A New Message!", System.currentTimeMillis());
        Intent notificationIntent = new Intent(this, Notify.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(Notify.this, notificationTitle, notificationMessage, pendingIntent);
        notificationManager.notify(10001, notification);
    }
}

and here is main.xml file,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
   
     <TextView android:text="Notification Example"
     android:id="@+id/TextView01"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>
   
     <Button
     android:id="@+id/notificationButton"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="Notify"/>
</LinearLayout>

That's all you have to for notification.

Sunday, 19 August 2012

Full Screen Activity And Orientation Lock - Android

In android locking screen orientation is just one line stuff.
In the same way if you want to make your activity full screen then it is easy. Making activity full screen means we are hiding status bar.
Here is code for both stuffs,

Main.java

package com.android.fullscreenactivity;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        //Here you can make activity fullscreen.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        //Here you can lock orientation.
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
       
        setContentView(R.layout.main);
    }
}

There is no need of setting any permissions in manifest for this.

Text To Image Conversion - Android

In android text to image conversion is very easy. We may need to convert text to image at run time to make it more fancy or to draw it on specific component. For this purpose you have to use canvas, paint and bitmap. Here is code to convert text to image,

Main.java file

package com.android.texttoimage;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class Main extends Activity implements OnClickListener {
    ImageView iv;
    Button btn;
    EditText tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        iv=(ImageView)findViewById(R.id.iv);
        tv=(EditText)findViewById(R.id.tv);
       
        btn=(Button)findViewById(R.id.btn);
        btn.setOnClickListener(this);
    }

    public void onClick(View v) {
        Bitmap b = Bitmap.createBitmap(200,200,
                Bitmap.Config.ARGB_8888);
        Canvas cv=new Canvas(b);
        Paint paint=new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(1);
        paint.setColor(Color.MAGENTA);
        paint.setTextSize(30);
        cv.drawText(tv.getText().toString(), 75, 75, paint);
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setTextSize(30);
        cv.drawText(tv.getText().toString(), 75, 110, paint);
        iv.setImageBitmap(b);
    }
}

And here is main.xml,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:id="@+id/tv"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:id="@+id/btn"/>
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/iv"
        android:src="@drawable/icon"/>
</LinearLayout>

There is no need of permissions for this stuff. In this case you can use different sizes, strokes, fonts and colors. 

One of the application where I used this stuff is page curl effect. Where I was drawing text on each page.

Saturday, 18 August 2012

HTML5 Awsomw Quiz Questions & Answers - 2

1. The "contenteditable" attribute is used to...
   a) Update content dynamically from server.
   b) Allow the user to edit only text contained  within the element.
   c) Allow the user to edit any text and markup contained within the element.
   d) Allow the user to edit only images contained within the elements.
Ans. C

2.
Which of the following is not the event of Video Tag in HTML 5 ?
   a) readyToPlay   b) play   c) emptied   d) abort
   Ans . readyToPlay

3. Which of the JavaScript objects are not accessible by web workers ?
   a) event   b) variables   c) document object   d) None. 
Ans. document object

4. Canvas in HTML 5.0 is a 
   a) List element   b) Element   c) Styling attribute   d) None.
   Ans . Element

5. In html5 SSE stands for...
   a) Server side event   b) Server sent event   c) Source server event.
Ans. Server sent event

6. Which tag of HTML5 is not supported by any browser?
   a) track   b) figcaption   c) bid   d) embed
Ans. track

7. Is it compulsory to write <html> tag in html file?
   a) Yes   b) No
Ans. No

8. Is it compulsory to write <body> tag in html file?
   a) Yes   b) No
Ans. No

9. Which of the elements are supported in mobile platform in HTML5?
   a) 3D canvas   b) micro data   c) Filereader   d) None
Ans. None

10. Which method is used to stop web worker?
   a) worker.stop()   b) w.terminate()   c) w.stop()   d) worker.terminate()

Friday, 17 August 2012

HTML5 Awsome Quiz Questions & Answers - 1

1. Which current browser supports most of features of HTML5? And which browser supports less features?
Ans. Chrome supports most of features of HTML5 and IE9 supports less features.
Here is ranking of browsers with respect to support(score) from higher to lower,
    a) Chrome21 - 437          b) Maxthon 3.4.1 - 422
    c) Opera 12.0 - 385         d) Safari 6.0 - 376
    e) Firefox 14 - 345            f)  IE9 - 138.

2. Which of these technologies/API's are officially a part of HTML5?
   a) Web SQL   b) Microdata   c) SVG   d) Silerlite.
  Ans . Microdata.
HTML5 shows number of API's as given below,
    a)  Application cache API   b) Data transfer API   c) Command API   d) Constraints validation API.
    e) History API.   f) Mediacontroller API   g) Text track API.
These are few API's not all. There are still other API's that HTML5 supports.

3. Which of these element is not supported under HTML5?
   a) blockquote   b) table   c) cite   d) center.
Ans. center.
Other elements not supported in HTML5 are as given below,
    a) acronym   b) applet   c) basefont   d) big   e) dir   
    f) font   g) frame   h) frameset   i) noframes   j) strike   k) tt.

4. What is use of datalist tag? And which browsers dose not support datalist tag?
Ans. <datalist> tag is used to provide auto complete feature on input elements. User will see drop down list as he/she will input data.As we see drop down list when we type search keyword in google.
IE and safari dose not support this feature.

5. Which of these is not valid HTML5 section element?
   a) header   b) aside   c) nav   d) body.
Ans . body.

6. Dose HTML5 require reference to DTD? Why?
Ans. HTML5 need no support of DTD(Document Type Definition), because it is not based on SGML(Standard Generalized Markup Language).

7. Which of these is not valid input type in HTML5?
   a) telephone   b) week   c) datetime-local   d) color.
Ans . telephone.
All new input types in HTML5 are given below,
    a) color   b) date   c) datetime   d) datetime-local   e)  email   f) month   g) number
    h) range   i) search   j)  tel   k)  time   l)  url   m) week.

8. Which of the following is not media element?
   a) readyToPlay   b) embed   c) track   d) video
Ans. readyToPlay

9. Can we have two body tags in same HTML5 file?
   a) Yes   b) No   c) May be   d) Sometimes
Ans. Yes

10. Can we embed one <html> tag in body of another one in same file?
   a) Yes   b) No   c) May be   d) Sometimes
Ans. Yes

More... http://tech-world-brij.blogspot.in/2012/08/html5-awsomw-quiz-questions-answers-2.html.

Thursday, 16 August 2012

Repository Architectural Style

Repository architectural style is data centered style, which allows user interaction for data processing. This style shows two main entities. First one is central data structure which represents the current state of system and second one is independent entity which operates on central data structure. Second entity called clients have full control over logic flow. Means clients can read data from central data structure and write data to central data structure. Different clients may have different interfaces and privileges on central data structure.

Central repository may be our normal database or any kind of data store. Central repository is also known as blackboard and clients are called as knowledge sources. Knowledge source is independent entity of application. These knowledge sources communicate with each other through blackboard only. Here is diagram representing whole structure,




Here each knowledge source will change the data at blackboard which will lead to solution. Each knowledge source will be triggered by the current state of blackboard.

This type of style is mainly used in the applications where complex signaling system is required. We can also use such a style in applications involving shared data access and loosely coupled agents.

In java we can use threading and synchronized block to implement this style.

Java "Class" class

This class is mainly used to inspect specific class in java. It will help you to know about classes, methods, interfaces ect. about class. This class is present at java.lang.Class present from JDK 1.0.


Here I am giving simple example of it because main intention is to know about class. After that you can explore that class. I am giving explanation in code itself so read comments carefully.


import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Main {
public static void main(String[] args) {
try {
// Checking whether method returns void ro not.
System.out.print("\nReturn type of method\n");
Class c1 = Test1.class.getMethod("testing1",null).getReturnType();
System.out.println(c1 == Void.TYPE);
/* Obtaining all methods of class.
* It will return you all methods of java class including methods
* it is obtaining from its super class. For example Methods from 
* object class. But here it will give you private methods. 
* For private methods you hava to use getDeclaredMethods()*/
System.out.print("\n\nAll methods");
Method[] m = Test1.class.getMethods();
for(int i=0; i < m.length; i++) {
System.out.print("\nMethod : " + m[i].toString());
}
/* Obtaining declared methods of class.
* It will return you all methods declared in specific class
* including private methods. It will not return superclass methods.*/
System.out.print("\n\nDeclared methods");
Method[] m2 = Test1.class.getDeclaredMethods();
for(int i=0; i < m2.length; i++) {
System.out.print("\nDeclared Methods : " + m2[i].toString());
}
/* Here you will get all declared constructors
* including private ones.
*/
System.out.print("\n\nAll constructors");
Constructor[] c2 = Test1.class.getDeclaredConstructors();
for(int i=0; i < c2.length; i++) {
System.out.print("\nConstructors : " + c2[i].toString());
}
/* Here you will get all declared constructors
* excluding private ones.
*/
System.out.print("\n\nPublic constructors");
Constructor[] c3 = Test1.class.getConstructors();
for(int i=0; i < c3.length; i++) {
System.out.print("\nConstructors : " + c3[i].toString());
}
/* It will return you all public member classes of specific class
* including member classes of super class.
* It will not return any private class.
*/
System.out.print("\n\nAll public Classes");
Class[] cls = Test1.class.getClasses();
for(int i=0; i < cls.length; i++) {
System.out.print("\nClasses : " + cls[i].toString());
}
/* It will return you all declared member classes including 
* private member classes.
*/
/*
* In the same way you can analyze interfaces.
*/
System.out.print("\n\nAll declared Classes");
Class[] cls1 = Test1.class.getDeclaredClasses();
for(int i=0; i < cls1.length; i++) {
System.out.print("\nClasses : " + cls1[i].toString());
}
} catch (Exception e) {
System.out.print("\nError : " + e);
}
}
}

class Test2 {
public Test2() {
}
public void superClassMethod() {
}
public class innerTest2 {
}
private class innerPrivateTest2 {
}
}

class Test1 extends Test2{
public Test1() {
}
private Test1(String str) {
}
public void testing1(){
}
public String testing2() {
return null;
}
private void testing3() {
}
public class innerTest1 {
}
private class innerPrivateTest1 {
}
}