Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Friday, 7 November 2014

JAVA BASIC INTERVIEW QUESTIONS


  • What is a pointer and pointers are used in  Java or not?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.



  • What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.


  • What are local variables?

Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.


  • What is an abstract class?
We can’t create the instance of an abstract class, because abstract classes are incomplete.Abstract modifier doesn’t supported by interface, Values type and static types.We can declare class as abstract by using abstract keyword in beggining of the class definition.

Abstract class provides similar definition of base class which can be shared by multiple derived classes.Abstract class may define abstract methods by using the abstract keyword before the method definition.Abstract methods have no implementation, only they can be implemented in the derived class.


  • what did you understand by Polymorphism?

When one task is performed by different ways i.e. known as polymorphism. For example: to convense the customer differently, to draw something e.g. shape or rectangle etc.In java, we use method overloading and method overriding to achieve polymorphism.
}


  • what is Inheritance?

When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.

Thursday, 6 November 2014

COMMENTS IN JAVA

COMMENTS IN JAVA


  • Like c,c++ we use comments to know the process of program or operation performed in program  , In JAVA we also use comments to describe the performed operation.
  • Comments are description about the features of program.
  • When we write comment in our program , we can understand what is program doing as well as it help others to easily to follow our code.

The biggest advantage of the comments is that readability & understanding of the program increases.

TYPES OF COMMENTS

In JAVA there are three types of comments

  1. Single Line
  2. Multi Line
  3. Java Documentation


SINGLE LINE COMMENTS

These comments are for marking a single line as a comment. These comments are start with a double slash symbol (//)
E.g. //THIS IS MY FIRST CLASS.

DOUBLE LINE COMMENTS

These comments are used for representing several lines as a comment .these comments start with  /* and end with  */.
E.g. /* THIS IS MY FIRST ROW.
THIS IS SECOND ROW.
THIS IS THIRD ROW. /*


JAVA DOCUMENTATION COMMENTS

These comments are used to provide description for every feature in a Java Program . these are start with /** and end with */.
By the use of this .html file is created which is also called as API(Application Programming Interface)  document.
E.g. /** DESCRIPTION ABOUT CLASS*/
CLASS CODE
/**DESCRIPTION ABOUT METHOD*/

METHOD CODE

JAVA|INTERVIEW QUESTIONES

API DOCUMENT IN JAVA

  • API stands for Application Programming Interface.
  • An API document is a .html file that contains description of all the features of a software, a product , a technology .
  • API document is helpful for user to understand how to use the software or technology.   


DIFFERENCE BETWEEN #include  AND import STATEMENT

  • #include directive makes the compiler go to the c/c++ standard library and copy the code from the header files into the program . due to this, the size of program increases thus wasting of memory as well as processing time increases.
  • Import statement makes  the JVM  to go the java standard library , execute the code their ,and substitute the result in the program . in java no code is copied .so waste of memory as well as processing time decreases.

          So we can say that import Mechanism is efficient compare to the  #include . 

Monday, 18 August 2014

SIMPLE PROGRAM OF JAVA

To create a simple java program, We need to create a class that contains main method.
Let's understand the requirement first.

REQUIREMENT FOR SIMPLE PROGRAM 


For executing any java program, you need to

LETS BEGIN TO WRITE THE JAVA PROGRAM

STEP 1

To write the simple program, open notepad by start menu -> All Programs -> Accessories -> notepad Then write the simple program.




save this file as Simple.java

To compile:javac Simple.java
To execute:java Simple

STEP 2 

As displayed in the above diagram, write the simple program of java in notepad and saved it as Simple.java. To compile and run this program, you need to open command prompt by start menu -> All Programs -> Accessories -> command prompt.   

                                                    


 

To compile and run the above program, go to your current directory first; my current directory is c:\rohit(it is my folder name you write according to yours). Write here:
To compile:javac Simple.java
To execute:java Simple

















TIME TO UNDERSTAND THE PROGRAM......

Let's understand  what is the meaning of class, public, static, void, main,String[],System.out.println().
  • class keyword is used to declare a class in java.
  • public keyword is an access modifier which represents visibility, it means it is visible to all.
  • static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory.
  • void is the return type of the method, it means it doesn't return any value.
  • main represents startup of the program.
  • String[] args is used for command line argument. We will learn it later.
  • System.out.println() is used print statement. We will learn about the internal working of System.out.println statement later.

                                                                                                                                                     NEXT

JAVA : INTRODUCTION

WHAT IS JAVA.......?

Java is a programming language and a platform.

Platform Any hardware or software environment in which a program runs, known as a platform. Since Java has its own Runtime Environment (JRE) and API, it is called platform.

TYPES OF JAVA APPLICATION

Basically their are 4 types application:
  1. Standalone Application
  2. Web Application
  3. Enterprise Application
  4. Mobile Application

JAVA VERSION IN MARKET....

  1. JDK Alpha and Beta (1995)
  2. JDK 1.0 (23rd Jan, 1996)
  3. JDK 1.1 (19th Feb, 1997)
  4. J2SE 1.2 (8th Dec, 1998)
  5. J2SE 1.3 (8th May, 2000)
  6. J2SE 1.4 (6th Feb, 2002)
  7. J2SE 5.0 (30th Sep, 2004)
  8. Java SE 6 (11th Dec, 2006)
  9. Java SE 7 (28th July, 2011)

FEATURES OF JAVA....


There is given many features of java. They are also known as java buzzwords.
  1. Simple
  2. Object-Oriented
  3. Platform independent
  4. Secured
  5. Robust
  6. Architecture neutral
  7. Portable
  8. Dynamic
  9. Interpreted
  10. High Performance
  11. Multithreaded
  12. Distributed
We discuses these all features later. 



                                                                                                                                         NEXT