Sei sulla pagina 1di 11

Q1. Ans.

What are the basic features of JAVA technology. Simple Small language [ large libraries ] Small interpreter (40 k), but large runtime libraries( 175 k).

Object Oriented Supports encapsulation, polymorphism. inheritance, abstraction, and

Distributed Libraries for network programming Remote Method Invocation

Secure Difficult to break Java security mechanisms. Java Bytecode verification. Signed Applets.

Architecture neutral Java Bytecodes are interpreted by the JVM. Primitive data type sizes and their arithmetic behavior are specified by the language. Libraries define portable interfaces. Threads are easy to create and use ( perhaps easier than any other programming language). Finding Runtime Type Information is easy. Portable

Multithreaded

Dynamic Q2. What is Java Virtual Machine and its role in Java Programming environment. A Java virtual machine's main job is to load class files and execute the byte codes they contain. Only those class files from the Java API that are actually needed by a running program are loaded into the virtual machine. The byte codes are executed in an execution engine, which is one part of the VM.

Q3.

What is class, property and methods. Explain with Example. CLASSES AND OBJECTS A class is a template used to create multiple objects with similar features. A class embodies all features of a particular object. Classes are used to instantiate objects and objects are directly used in programs.

PROPERTIES AND METHODS Properties are the individual that differentiate one class of objects from another. They determine an objects appearance, state, and other qualities as specified by that class. Pen Class Object Color or the pen Red; Size of the pen Blue; Type of the Pen Pen1 Object, Pen2 Pen1.color = Pen2.color =

Basic syntax of a Java class: <modifier> class <name> { <attribute_declaration>* <constructor_declaration>* <method_declaration>* }

Example: public class Vehicle { private double maxLoad; public void setMaxLoad(double value) { maxLoad = value; }

} Q4. Explain Constructor and Default Constuctor. Basic syntax of a constructor: <modifier> <class_name> (<parameter>*) { <statement>* } Examples: public class Thing { private int x; public Thing() { x = 47; } public Thing(int new_x) { x = new_x; } } Default Constructor There is always at least one constructor in every class If the writer does not supply any constructors, the compiler generates a default constructor automatically. The default constructor takes no arguments Enables you to create object instances with new Xxx() without having to write a constructor Q5. Ans. Group data objects of the same type. Declare arrays of primitive or class types. char s[]; Point p[]; or or char [] s; Point [] p; What is an Array.

Create space for reference.

An array is an object, not memory reserved for primitive types. Use the new keyword to create an array object.

s = new char[20];

p = new Point[100]; p[0] = new Point(); p[1] = new Point(); . . . Initialize an array element Create an array with initial values

String names[] = new String[3]; names [0] = Jack; names [1] = Jill; names [2] = Tom; MyClass array[] = {new MyClass(), new MyClass() }; Q6. Define Interfaces with Example. Allow to fully abstract a classes interfaces from their implementations. Pure abstract classes with no implementation of any method. Only methods and constant declarations are allowed within an interface. Classes implement interfaces, but can have only one superclass. Once defined, any number of classes can implement an interface. {

Syntax access interface name .. return-type method-nameN(argument list); type final-varname1 = value; type final-varname2 = value; type final-varnameN = value; } Explanation access is either public or not used, the default access has package scope. methods are essentially abstract methods. return-type method-name1(argument list);

Variables are public, final and static and can not be changed by the implementing classes. All methods and variables are implicitly public even if the interface itself is not declared as public.

Example interface Area { final static float pi=3.14F; float compute(float x,float y); } class Rectangle implements Area { public float compute(float x,float y) { return (x*y); } } class Circle implements Area { public float compute(float x,float y) { return(pi*x*x); } } class InterfaceTest { public static void main(String args[]) { Rectangle rect = new Rectangle(); Circle cir = new Circle(); System.out.println("Area of Rectangle :"+rect.compute(10,20)); System.out.println("Area of Circle :"+ cir.compute(10,0)); } } Q7. Write a program to input value from user using scanner class.

Q8.

import java.util.Scanner; public class Appp { public static void main(String []args) { Scanner scan1 = new Scanner(System.in); System.out.println("Enter a String"); String str1 = scan1.nextLine(); System.out.println("Enter a int value"); int i = scan1.nextInt(); System.out.println("Enter a Double Value"); double value = scan1.nextDouble(); } }

Explain Exception handling. User input errors This is some incorrect data entered by the user

Code errors A method may not perform correctly.

Device error The hardware may have some problems which need to be reported to the user. For example, printer may be off, printer out of paper or it has failed during the execution itself

Physical limitation Program runs out of available memory or Hard disk is full. try catch

- use the try statement with the code that might throw an exception. - use the catch statement to specify the exception to catch and the code to execute if the specified exception is thrown. finally - used to define a block of code that we always want to execute, regardless of whether an exception was caught or not. throw - typically used for throwing user-defined exceptions.

throws

- lists the types of exceptions a method can throw, so that the callers of the method can guard themselves against the exception. Q9. What is MVC Architecture. Explain with Example.

Independent elements: Model View how the component looks onscreen state data for each component different data for different models

Controller dictates how the component reacts to events

Q10. Write a Program for following output.

Q11. Write a Program for following output.

Q12. Write a Program for following output.

Q13. Write a Program for following output.

Q14. Write a Program for following output.

Q15. Write a Program for following output.

Q16. Write a Program for following output.

Q17. Write a Program for following output.

Q18. Write a Program for following output.

Potrebbero piacerti anche