Skip to main content

Q) What is a package?


A)

->a package is a grouping mechanism which related class files are grouped and made available to other applications or other part of the same application.

->a package creates a namespace (logical container, we can’t have 2 files with same name).
->directory also holds files like package, but difference is ‘directory’ can’t be made available to either applications where as package can do it. Directory is a name given to the os files system terminology where as package is a java terminology.
->a package provides the fallowing
1) Some level of security in the application.
2) Provides namespace (logical container) when no 2 class files have the same name.
3) Grouping of related class files and there by easy maintenance
4) Making the class files available to other applications and other part of same allocation.
Note:
no class files exists in java which doesn’t belong to a package.
->available in missing with default package. I.e. The package where the class files store in a folder only.
Packages are 2 types
1) Pre defined (built-in) package (library class files)
2) User defined package

->in built in packages library class files are grouped.
->In user defined package applications, user defined class files are grouped.
->in java, we have 2 kinds of built in packages.
1) Core packages
2) Extension packages

Jar –xf rt.jaràun zipping g
Core packages



->for every application by default package is java.long package. It is implicitly available.
->library inclusion in c is static i.e. the header files contribute to the size of the program.
->library inclusion in java is dynamic i.e. all does not contribute to size of object. Only particular one contributes.
->indicates availability of class files in a package but sub package class files are not available.
->in a java application, if we use library class without import it then we get compilation error. if that class belongs to other than long package.
->we include util package into a java application as fallows

import java.util.*;

-> ’*’ indicates that it does not represent sub package class files of util package. The above syntax does not package into current java applications process space. It makes all the class files of util package available to java application? At run time which library class files of that package we use in the applications. Those class files only be loaded into memory. This is known as “library inclusion is dynamic in java”.
->in ‘c’ whether we use the library in the program or not. Entire is contributed to size of program. Whenever in java it is not like that only particular one is contributed to size of program.
 ->if we ‘import’ out of the class does not mean violation of encapsulation. Because we are not programming any data, we are making many encapsulated units available to the application.

Comments

Popular posts from this blog

Q) Explain repeated deletion of records.

A) //RepeatedDeletion.java import java.util.Scanner; import java.sql.*; class RepeatedDeletion {        public static void main(String[] args) {               Connection con= DriverManager. getConnection ( "jdbc:odbc:prince" , "scott" , "tiger" );               PreparedStatement ps=con.PreparedStatement( "DELETE FROM ACCOUNT WHERE ACCNO=?" );               Scanner s= new Scanner(System. in );               while ( true )               {                      System. out .println( "Enter accno : " );      ...

Q) Retrieving data from database?

A)   ->to retrieve the data from database we need to submit SELECT statement from JDBC application. -> executeQuery() method of statement object is used for this purpose. This method has the fallowing ResultSet executeQuery(String sql) throws SQLException Ex: ResultSet rs = st.executeQuery(“SELECT * FROM ACCOUNT”); ->objectoriented representation of tables formate data is called ResultSet object. Ao the driver created one object i.e. ResultSet object. ->object orientation representation of a table of records returned from db is nothing but “ ResultSet ” object.  

Q) What is the purpose of JDBC?

A) -> Java application can do any task by making a method (function) call. ->java method calls are not understandable to database management system. They can understand only SQL statements. ->SQL statements can’t be directly used in a java application. Java compiler complains. ->therefore, we say that java environment and database environment are heterogeneous to each other. Purpose of JDBC: ->for any kind of java application to communicate with any kind of database (management system) in a standard manner, JDBC is used.