Saturday, 15 October 2016

JAVA Class

A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviours. Java class objects exhibit the properties and behaviours defined by its class. A class can contain fields and methods to describe the behaviour of an object. A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviours. Java class objects exhibit the properties and behaviours defined by its class. A class can contain fields and methods to describe the behaviour of an object.



class Sample {
public static void main(String[] args) {

   System.out.println(“I am from Class Main Method”);
  
   }

}


_________________________________________________________________________________

Define class and object. Explain them with an example using java
Class and object - Class: A class is a program construct which encapsulates data and operations on data. In object oriented programming, the class can be viewed as a blue print of an object.

What is a method? Provide several signatures of the methods
What is a method? - A java method is a set of statements to perform a task. A method is placed in a class...

Difference between instance variable and a class variable
Difference between instance variable and a class variable - An instance variable is a variable which has one copy per object / instance. That means every object will have one copy of it...

Explain how to create instance of a class by giving an example
How to create instance of a class - Java supports 3 ways of creating instances...

Define an abstract class. Explain its purpose
Define an abstract class - A class with one of more abstract methods is called an Abstract class...

What is the difference between an Abstract class and Interface?
Abstract class and Interface - An abstract class can have both abstract and concrete methods whereas an interface can have only method signatures...

What is singleton class? Where is it used?
What is singleton class? - A class is defined as singleton class, if and only if it can create only one object...

What is a native method?
What is a native method? - A native method is a method which is implemented in a non-java language that is targeted for a single machine type...

Difference between a public and a non-public class
Difference between a public and a non-public class - A class with access specifier ‘public’ can be accessed across the packages...

What is the purpose of the Runtime class?
Purpose of the Runtime class - The java runtime system can be accessed by the Runtime class...

What is the difference between a static and a non-static inner class?
Static and a non-static inner class - Like static methods and static members are defined in a class, a class can also be static...

Difference between the String and StringBuffer classes
Difference between the String and StringBuffer classes - String class is immutable. The characters of string objects can not be changed / modified...

What is the Dictionary class?
What is the Dictionary class? - The Dictionary class is an abstract class. The class maps keys to values...

What is the ResourceBundle class?
What is the ResourceBundle class? - A ResourceBundle is a group of related sub classes which are sharing the same base name...

What is the Vector class?
What is the Vector class? - The capability of implementing a growable array of object is provided by the class Vector...

What is the SimpleTimeZone class?
What is the SimpleTimeZone class? - SimpleTimeZone is a concrete subclass of TimeZone class...

What is the purpose of the System class?
Purpose of the System class - System class is provided with useful fields (static members) that are pertaining to the environment...

How are this() and super() used with constructors?
How are this() and super() used with constructors? - this() constructor is invoked within a method of a class, if the execution of the constructor is to be done before the functionality of that method...

JAVA OOPS Concepts

Java is an Object-Oriented Language. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts −
Polymorphism
Inheritance
Encapsulation
Abstraction
Classes
Objects

Objects in Java

Let us now look deep into what are objects. If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc. All these objects have a state and a behavior.
If we consider a dog, then its state is - name, breed, color, and the behavior is - barking, wagging the tail, running.
Software objects also have a state and a behavior. A software object's state is stored in fields and behavior is shown via methods.
So in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods.
Inheritance
Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.


Polymorphism
Polymorphism is the ability of an object to take on many forms. 

 Encapsulation
Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.

Abstraction
Abstraction is process of hiding the implementation details and showing only the functionality.

Classes

A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviours. Java class objects exhibit the properties and behaviours defined by its class. A class can contain fields and methods to describe the behaviour of an object.

Friday, 14 October 2016

Introduction and Popularity of Java


Java is a simple and yet powerful object oriented programming language and it is in many respects similar to C++. Java originated at Sun Microsystems, Inc. in 1991. It was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. It was developed to provide a platform-independent programming language.

Why So Popular
However, Java differs from other programming languages in a couple of significant ways. The following sections describe the most important differences.
OPEN SOURCE: Being a open source java Becomes so popular

PLATFORM INDEPENDENCE

One of the main reasons Java is so popular is its platform independence, which means that Java programs can be run on many different types of computers.

OBJECT ORIENTED

Object Oriented Programming is a method of implementation in which programs are organized as cooperative collection of objects, 

JAVA IS DISTRIBUTED

With extensive set of routines to handle TCP/IP protocols like HTTP and FTP java can open and access the objects across net via URLs.

JAVA IS MULTITHREADED

One of the powerful aspects of the Java language is that it allows multiple threads of execution to run concurrently within the same program A single Java program can have many different threads executing independently and continuously. Multiple Java applets can run on the browser at the same time sharing the CPU time.

JAVA IS SECURE

Java was designed to allow secure execution of code across network. To make Java secure many of the features of C and C++ were eliminated. Java does not use Pointers. Java programs cannot access arbitrary addresses in memory.

GARBAGE COLLECTION

Automatic garbage collection is another great feature of Java with which it prevents inadvertent corruption of memory. Similar to C++, Java has a new operator to allocate memory on the heap for a new object. But it does not use delete operator to free the memory as it is done in C++ to free the memory if the object is no longer needed. It is done automatically with garbage collector.