Вы находитесь на странице: 1из 10

JAVA Basics Who Developed Java?

Java Was Developed by James Gosling at Sun Microsystems, Sun Microsystems is a Software development company best known for workstations. Java was originally called Oak, and it is designed for use in Embedded Consumer Electronic applications in 1991.It was redesigned for developing Internet application and renamed as JAVA In 1995 2. What are the features of Java? Platform Independence The Write-Once-Run-Anywhere ideal has not been achieved (tuning for different platforms usually required), but closer than with other languages. Object Oriented Object oriented throughout - no coding outside of class definitions, including main (). Compiler/Interpreter Combo Code is compiled to bytecodes that are interpreted by a Java virtual machines (JVM) . This provides portability to any machine for which a virtual machine has been written. The two steps of compilation and interpretation allow for extensive code checking and improved security. Robust Exception handling built-in, strong type checking (that is, all data must be declared an explicit type), local variables must be initialized. Several dangerous features of C & C++ eliminated: No memory pointers No preprocessor Array index limit checking Automatic Memory Management Automatic garbage collection - memory management handled by JVM. Security No memory pointers Programs runs inside the virtual machine sandbox. Array index limit checking bytecode verifier - checks classes after loading Good Performance Interpretation of bytecodes slowed performance in early versions, but advanced virtual machines with adaptive and just-in-time compilation and other techniques now typically provide performance up to 50% to 100% the speed of C++ programs. Threading Lightweight processes, called threads, can easily be spun off to perform multiprocessing. Can take advantage of multiprocessors where available Great for multimedia displays.

What is Object-Oriented programming? In Object-Oriented Programming construction is done by constructing objects.

We use objects interact with each other to send and receive messages Mainly OOPS Concepts are 1. Data Abstraction &Encapsulation 2. Inheritance 3. Polymorphism. What is Object? Objects are the basic run-time entities in an object oriented system. When program is executed, objects interact with each other by sending &receiving messages What is Class? A class is a collection of objects of similar type. Once a class is defined any number of objects can be created which belong to that class. What is Abstraction? Abstraction refers essential features without including the back ground details. What is Encapsulation? Encapsulation is the wrapping of data and methods in to single unit is called as Encapsulation For security purpose we are using this Encapsulation. What is Inheritance? Inheritance is the process where the objects of one class can acquire the properties of another class Inheritance provides the REUSABILITY. What is Polymorphism? Polymorphism means the ability to take more than one form. An operation may exhibit different behavior in different times

What is Data Abstraction? Abstraction refers essential feature without including background details or explanations. What is an abstract method? An abstract method is a method that does not have a body .i.e. it misses the code that it can execute, i.e. an abstract method does not provide an implementation It is declare with abstract keyword. What is an interface? An interface is a class containing a group of constants and method declarations that do not provide implementation. Briefly an interface allows us to specify what a class must do, but not how to do In interface methods must be abstract and public Public and abstract keywords may be omitted in the code but java treats all methods of the interface as public and abstract implicitly Java supports multiple inheritances through interface only Can we instantiate an interface? You cant instantiate an interface directly, but you can instantiate a class that implements an interface. Can we create an object for an interface?

Yes, it is always necessary to create an object implementation for an interface. Interfaces cannot be instantiated in their own right, so you must write a class that implements the interface and fulfill all the methods defined in it. What modifiers are allowed for methods in an Interface? Only public and abstract modifiers are allowed for methods in interfaces. Can there be any abstract method without abstract class? No,if there is any abstract method in a class,that class must be abstract. Can you use abstract and final both with a method? No,because abstract method needs to be overridden wehereas you can't overried final method.

What is exception handling? The error generated at runtime are called exceptions, those errors handled by programmer or jvm called exception handling Examples of Exceptions? . IO Exception . Interrupted Exceptions . Runtime Exceptions . File not found Exceptions . IndexOutOfBound Exception. . Arithmatic Exception . Negative Array Size Exception. What is super class of Exception? Throwable. Types of Exception? 1. Checked Exception 2.UnChecked Exception What is Checked Exception? All the subclasses of throwable class except runtime exception are called as checked Exception ,and programmer has to check himself .E.g:IOException,SQLException,etc. What is Unchecked Exception? All the subclass of runtime exception are called unchecked exception, JVM Check these and terminate those errors.E.g: IOException,SQLException,etc. When will we get Exception ? An exception can occur for many different reasons, including the following: A user has entered invalid data. A file that needs to be opened cannot be found. A network connection has been lost in the middle of communications, or the JVM has run out of memory. Explain Java error handling mechanism?

i. ii.

What is a thread? Thread is single sequential flow of control within a program. A thread itself is not a program; a thread cant run its own rather it runs with in a program. How many ways we can create a thread? By extending the thread class By implementing the runnableInterface What is thread scheduler? Allocation of microprocessor time for all the threads is controlled by thread scheduler. Explain the life cycle of thread?

1. Born state 2.Runnable State 3.blocked State 4.Dead State

Born State:-when a thread created i.e. (Thread t1=new Thread ();)here thread is created but is not active and also it is not eligible for microprocessor time. Runnable State:-when a thread is created, it is inactive and to make it active ,we will start(); method on it (t1.start();). Blocked State:-A running thread can be made temporarily inactive for a short period by inactive and ot eligible for microprocessor time . Dead State:-When the threads run () method execution is over, at last it dies automatically and the thread object is garbage collected. A dead thread cannot be restarted again. By calling stop() method we will bring a thread in to Dead State . What is thread priority? The order of execution of multiple threads on a CPU,it depends on the scheduling of thread scheduler. Every thread has a priority in the range of Java i.e. Thread.MIN_PRIORITY (constant 1) Thread.MAX_ PRIORITY (constant 10) Thread.NORM_PRIORITY (constant 5) What is suspend () and resume () methods? Suspend () method is used to temporarily stop the execution (making inactive) of the thread Resume () method is which can restart a suspended thread (and making active again) What is Thread Synchronization? Synchronization is done in order to protect a segment of code from being accessed by more than a single Thread at any particular instance of time. In Java, synchronization is achieved with the use of synchronized keyword. Synchronization can be applied to methods as well as to a block of code. What is Deadlock? In a multithreaded program if we dont synchronize multiple threads properly ,a deadlock situation may arise and if a situation comes ,the program simply hangs. Deadlock comes between Synchronized threads only.

What is serialization and deserialization? Serialization is the process of writing the state of an object to a byte stream.Deserialization is the process of restoring these objects. What is the purpose of the Runtime class? The purpose of the Runtime class is to provide access to the Java runtime system. What will a read() function do?. A method in Input Stream.It reads a single byte or an array of bytes.Returns no of bytes read or -1 if EOF(End of file)is reached. What is the purpose of the System class? The purpose of the System class is to provide access to system resources. What is the purpose of the File class? The File class is used to create objects that provide access to the files and directories of

a local file system. What is the Properties class? The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used. How many methods in the Externalizable interface? There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal(). What an I/O filter? An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another. What class allows you to read objects directly from a stream? The ObjectInputStream class supports the reading of objects from input streams.

1. 2. 3. 4. 5. 6. 7.

1. 2. 3. 4. 5.

What is String ? A string is an array of characters and in java a string is an object (derived from string class) That can be assigned with a group of characters. Enclosed in double quotes. 5imp methods in String Class? indexOf(Char Ch) charAt(int index) SubString(int num) valueOf(); toUpperCase(),toLowerCase() and trim() length() equals() What is String Buffer class and explain methods? String is mutable. I.e when a new value is assigned to string buffer,in the same location the value is changed. Imp methods of StringBuffer Capacity() and length() charAt() and SetCharAt() Append() Insert() and Delete() Reverse() Discuss the reverse () method of StringBuffer? With reverse () method we can reverse the characters in a string buffer.it must be noted that reverse () is not available in StringClass. Difference between string and stringBuffer? String class and String Buffer class are both from Java.lang package. String is immutable where as String buffers are mutable

When a string is created a memory allocations is assigned when reassigned the string is allocated a new memory location and one is garbage collected, that is for every reassignment a new location is created This immutable nature is a big overhead to operating system. To overcome this, java designers introduced StringBuffer.Incase of StringBuffer, if a value is changed the location is not changed and in the location is not changed in the old location only the value changed.

What is Database? Database is the collection of related data and the relationships supporting the data. What is DBMS? Database management system (DBMS) is software that is used to access data in the database The primary objective of a DBMS is to provide convenient environment to retrieve and store database information. What is SQL? Structured Query Language (SQL) is used to communicate with the DBMS to deal with database data IBM developed by this language in 1970s Sub Languages of SQL? 1. Data Definition Language (DDL): It is used to create, alter and drop tables 2. Data Manipulation language (DML): It is used to Insert, Update and delete data 3. Data Query Language (DQL): It is used to retrieve data from the database table using select . Check the syntax of A. Creating table B. Inserting data into table C. Deleting data from table D. Retrieving data from table What is JDBC? JDBC is a trademark name from Sun Micro System .JDBC is an API using this API we can develop java applications that can communicate with database Standard steps to connect to the database? a. Loading Driver b. Preparing the connection string c. Requesting for the connection d. After performing database operations closing the connection. How many drivers in JDBC? 1. JDBC-ODBC bridge driver (Bridge Driver) 2. Native API/partly java Driver(Native Driver) 3. All Java/Net-Protocol Driver (Middle ware Driver) 4. Java/native protocol Driver(pure or thin Driver) What are the major things when we connect database from Database? 1. Driver Manager 2. Connection 3.Statement What is Batch Updates? Sending multiple update statements to the database together as a unit

What is CGI? In the early days of internet, websites have only static pages. I.e. web pages were only informative but not interactive. Introduction of CGI programme in the context of a dynamic website. What packages are in java for developing Servlet? 1. Javax.servlet 2. javax.servlet.http Life cycle of Servlet? 1. init (Servlet Config) 2. Service (Servlet Request, Servlet Response) 3. Destroy () What is generic Servlet? It is an abstract class this class implement Servlet Interface. If defined init (ServletConfig) and Destroy () methods of the Servlet interface. Third life cycle method service () is not defined in the Generic Servlet class. What is HttpServlet? This is an abstract class .it is a subclass of GenericServlet always define their Servlet class by extending this class. What is Request Dispatcher? It is an interface .Servlet container writes a subclass for this interface. Servlet engine provides this sub class object when we call get Request Dispatcher () on the request (or) context object .this interface has 2methods.\ 1. Forward (). 2. Include() What is Cookie? A Cookie is a simple place of information stored on the client, on behalf of the server. This information is returned to the server with every request, in addition to the requested document, It checks the URL against the URL range of all available cookies. If a match found the cookie is is also returned with the request this helps the server overcome the stateless nature of the Http Protocol. What is stateless protocol? A web Client opens a connection with the Http Server and Requests some resource. The server responds with the requested resource and closes the connection with client. After closing the connection, the http Sever does not remember any information about the client. The server considers the next request form the same client as a fresh request with no relation to the previous request .this called stateless protocol. What is Session? Session tracking is the ability of the web container to recoginze a client uniquely in a series of interactions and also able to associate each request with a particular client . HttpSession s=request.getSession();

1. 2. 3. 1.

1. 2.

What is JPS? JSP is another web technology from sun micro Systems besides Servlets. Jsp is used to generate dynamic webpages on the server side .Jps is nothing but comination of Java &html. What is disadvantage of Sevelet when compare to JSP? Servlet are poor in presenting the response to the client. Life cycle of JSP? 1. Page Translation 2. Page compilation 3. Generated Sevrlet Class loading. 4. Servlet Instantiation phase. 5. Calling JSP Init() known as initialization phase. 6. Calling JSP Service () 7. Calling JSP Destroy () How many tags are in JSP? 1. Scripting Elements 2. Directives 3. Actions. What is Scripting Elements? The basic functionality of scripting elements is to allow jsp authors to embed java code directly in to the Jsp.We can classify scripting elements as following 1. Declaration 2. Expression 3. Scriptlet. What is JSP Directives? Directives are used to provide pages with information a6t translation time .when the JSP page is converted to a Servlet. Include Directive Taglib Directive Page Directive What are implicit objects in JSP? Request 2.Response 3.Session 4.Config 5.Application 6.page 7.Exception 8.Page Context What is JSP Actions? An Action is a request time instruction given to the Jsp Engine. Actions are high level JSP elements that create ,modify,or use other objects Actions are coded strictly according to the XML Syntax. Standard Actions Custom Actions

Вам также может понравиться