MY mENU


Thursday, 9 February 2012

static variables in Interface


Interfaces have static keyword implicitly but only for variables e.g.
interface Abc
{
int a = 5;
}

then you can call this variable in static way like Abc.a and the variables in interface are implicitly final also. You can't change the value of variable declared in interface.

The methods declared in interface are not static. They are implicitly abstract and the sub-class must implement all the methods of Interface or the sub-class should also be abstract class if it is not implement the methods of Interface.


To access the instance variable, we have to create the instance of a class. Only then we can access the instance members of a class.

But in the case of interface, we can't create the instance of an Interface. Interface don't have any constructors to create the instance. But we can only declare variable of Interface type. So we can't access the instance variable if we can declare a non-static (instance) variable in interface.

That's why the variables in Interface are implicitly static variables.

But the question can arise in your mind that we can't able to create the instance of an Abstract class also. But we can declare the instance variable in an Abstract class.

The reason behind it is that we also not able to create the instance of an Abstract class directly, but an Abstract class can have constructor and this constructor will be called when we create the object of the sub-class. So Abstract class can have instance variables and we can call them using the object of sub-class.


JDBC Drivers in Java


JDBC Drivers are divided into 4 types or levels.

The different types of JDBC Drivers are :

Type 1 - JDBC-ODBC Bridge driver (Bridge)
Driver Class : sun.jdbc.odbc.JdbcOdbcDriver
URL : jdbc:odbc:myDSN

Type 2 - Native-API/partly Java driver (Native/OCI)
Driver Class : oracle.jdbc.driver.OracleDriver
URL : jdbc:oracle:oci:@orans

Type 4 - All Java/Native-protocol driver (Pure Java/Thin)
Driver Class : oracle.jdbc.driver.OracleDriver
URL : jdbc:oracle:thin:@localhost:1521:xe

Type 3 - All Java/Net-protocol driver (Middleware)

R.java File in Android

The directory gen in an Android project contains generated values. R.java is a generated class which contains references to resources of the res folder in the project. These resources are defined in the res directory and can be values, menus, layouts, icons or pictures or animations. For example a resource can be an image or an XML file which defines strings.

If you create a new resource, the corresponding reference is automatically created in R.java. The references are static int values, the Android system provides methods to access the corresponding resource.

For example to access a String with the reference id R.string.yourString use the method getString(R.string.yourString));. R.java is automatically maintained, manual changes are not necessary.

While the directory res contains structured values which are known to the Android platform the directory assets can be used to store any kind of data. In Java you can access this data via the AssetsManager and the method getAssets().