Email :
[email protected] IGNOU Friend
Course Code : CS- 74 Course Title : Introduction to Internet Programming (Java, ActiveX) Assignment Number : BCA (6)-74/Assignment/2011 Maximum Marks : 100 Last Date of submission : 30th April, 2011 (For January Session) 30th October, 2011 (For July Session) This assignment is having five questions. Answer all the questions. Question 1: Differentiate between the following terms along with appropriate examples (20 Marks) Applet and application Applet •Programs that are downloaded from the Web and executed inside of a browser •Cannot read or write to local file system •Cannot communicate with any server other than the one that the applet was downloaded from •Cannot run any program on user's system •Cannot load programs native to the local platform Application •Stand alone Java programs that do not require a Web browser to run •They are more general purpose programs •They do not have security restrictions that applets have •They are typically executed using the command line JVM (java)
Inheritance and interface
Inheritance •Extending base class’s members into drive class •Extending class and abstract class into drive class •Support only single inheritance by using extend keyword •Inherited class would create there instance
If you have any query just email us at www.ignoufriend.blogspot.com Email :
[email protected]
Email :
[email protected] IGNOU Friend
•Abstract class is act like partial interface Interface •Organizing drive class by base class member declaration •Drive class must have definition function which are declared in base class •You can implement multiple interfaces into a single drive class by using implements keyword •Interfaces does not create any instance •Interface doesn’t consist any definition of members (iii) Private and Protected Private •The type or member can be accessed only by code in the same class •Private variables, are variables that are visible only to the class to which they belong. •Private variable can’t inherited into sub class •Private variable can be access within class by using this keyword Private variable are tightly encapsulated with class’s object Protected •The type or member can be accessed only by code in the same class, or in a class that is derived from that class. Page | 2
If you have any query just email us at www.ignoufriend.blogspot.com Email :
[email protected]
Email :
[email protected] IGNOU Friend
•Protected variables, are variables that are visible only to the class to which they belong, and any subclasses. •Protected variables can be inherited in to sub class as private as well as protected •Protect variable can be access within class by using this keyword and super keyword in sub class •Protected variable are loosely encapsulated with class’s object This and Super
This •this keyword use to access class level members •this refers to the current class
•private variables cannot be accessed in a inherited class by using "this" • by using this same class constructor can class another constructor of the same class Super •super keyword use to access super class members as well as constructor •super refers directly to its immediate above super class •by using "super" we can easily access the private variables in its super class •by using super we can call super class constructor, but I’ll present at first line of drive class constructor Question 2: Answer the following questions (20 Marks) What is mean by Serialization? Also differentiate between Transient and Volatile keywords.
Serialization is the process of translating a state of an object into a stream of bytes. The process of reconstructing an object from a stream of bytes that represent its serialized state is called de-serialization. Serialization is mostly used when the state of objects have to be written to persistent storage for later retrieval or for transfer over a network. TRANSIENT identifies a variable not to be written out when an instance is serialized (It can'nt be copied to remove system) VOLATILE
If you have any query just email us at www.ignoufriend.blogspot.com Email :
[email protected]
Email :
[email protected] IGNOU Friend
indicates that the field is used by synchronized threads and that the compiler should not attempt to perform optimizations with it. When more than one thread share a (volatile) data it is checked every time. Every thread keeps the latest value of volatile variable (ii) Why Java is called platform independent? Is C++ also Platform independent? Justify your answer? Page | 3
If you have any query just email us at www.ignoufriend.blogspot.com Email :
[email protected]
Email :
[email protected] IGNOU Friend
Platform independent means the execution of the program is not restricted by the type of os environment provided...thereby make it possible to process the program at any type of environement available. Java is a platform independent language becoz of the bytecode magic of java. In java when we execute the source code...it generates the .class file comprising the bytecodes. Bytecodes are easily interpreted by JVM which is available with every type of OS we install. Whereas C and C++ are complied languages which makes them platform dependent. The source code written in C / C++ gets transformed into an object code which is machine and OS dependent. That's the reason why C and C++ languages are termed as Platform Dependent. (iii) When do we declare a member of class static ?Explain with the help of a suitable example A static member can be accessed without creating an instance of the class. If you try to use a nonstatic method and variable defined in this class then the compiler will say that non-static variable or method cannot be referenced from a static context. Static method can call only other static methods and static variables defined in the class. The concept of static method will get more clear after this program. First of all create a classHowToAccessStaticMethod. Now define two variables in it, one is instance variable and other is class variable. Make one static method named staticMethod() and second named asnonStaticMethod(). Now try to call both the method without constructing a object of the class. You will find that only static method can be called this way. The code of the program is given below: public class HowToAccessStaticMethod{ int i; static int j; public static void staticMethod(){ System.out.println("you can access a static method this way"); } public void nonStaticMethod(){ i=100; j=1000; System.out.println("Don't try to access a non static method"); } public static void main(String[] args) { //i=100; j=1000; //nonStaticMethod(); staticMethod(); } }
If you have any query just email us at www.ignoufriend.blogspot.com Email :
[email protected]