Saturday, 13 May 2017

JP - Super Keyword ~ foundjava

Super keyword in java

Super keyword in java is a reference variable that is used to refer parent class object. Super is an implicit keyword create by JVM and supply each and every java program for performing important role in three places.
  • At variable level
  • At method level
  • At constructor level

Need of super keyword:

Whenever the derived class is inherits the base class features, there is a possibility that base class features are similar to derived class features and JVM gets an ambiguity. In order to differentiate between base class features and derived class features must be preceded by super keyword.
Read More »

JP - This Keyword ~ foundjava

This keyword in java

this is a reference variable that refers to the current object. It is a keyword in java language represents current class object

Usage of this keyword

  • It can be used to refer current class instance variable.
  • this() can be used to invoke current class constructor.
  • It can be used to invoke current class method (implicitly)
  • It can be passed as an argument in the method call.
  • It can be passed as argument in the constructor call.
  • It can also be used to return the current class instance.
Read More »

JP - Static Keyword ~ foundjava

Static keyword in java

The static keyword is used in java mainly for memory management. It is used with variables, methods, blocks and nested class. It is a keyword that are used for share the same variable or method of a given class. This is used for a constant variable or a method that is the same for every instance of a class. The main method of a class is generally labeled static.
No object needs to be created to use static variable or call static methods, just put the class name before the static variable or method to use them. Static method can not call non-static method.
Read More »

JP - Final Keyword ~ foundjava

Final keyword in java

It is used to make a variable as a constant, Restrict method overriding, Restrict inheritance. It is used at variable level, method level and class level. In java language final keyword can be used in following way.
  • Final at variable level
  • Final at method level
  • Final at class level
final keyword in java
Read More »

JP - Array in Java ~ foundjava

Array in java

Array is a collection of similar type of data. It is fixed in size means that you can't increase the size of array at run time. It is a collection of homogeneous data elements. It stores the value on the basis of the index value.
array in java

Advantage of Array

One variable can store multiple value: The main advantage of the array is we can represent multiple value under the same name.
Code Optimization: No, need to declare a lot of variable of same type data, We can retrieve and sort data easily.
Random access: We can retrieve any data from array with the help of the index value.
Read More »

JP - Access Modifiers ~ foundjava

Access Modifiers in Java

Access modifiers are those which are applied before data members or methods of a class. These are used to where to access and where not to access the data members or methods. In Java programming these are classified into four types:
  • Private
  • Default (not a keyword)
  • Protected
  • Public
Note: Default is not a keyword (like public, private, protected are keyword)
Read More »

JP - Import Statements ~ foundjava

Import statements in Java

Import is a keyword in java language used to import the predefined properties of java API into current working java program.
import statement
Read More »

JP - Naming Conversion ~ foundjava

Naming Conversion of Java

Sun micro system was given following conversions by declaring class, variable, method etc. So that it is highly recommended to follow this conversion while writing real time code.

Why Using naming Conversion

Different Java programmers can have different styles and approaches to write program. By using standard Java naming conventions they make their code easier to read for themselves and for other programmers. Readability of Java code is important because it means less time is spent trying to figure out what the code does, and leaving more time to fix or modify it.
1. Every package name should exist a lower case latter.
Read More »

JP - Wrapper Classes ~ foundjava

Wrapper classes in java

For each and every fundamental data type there exist a pre-defined class, Such predefined class is known as wrapper class. The purpose of wrapper class is to convert numeric string data into numerical or fundamental data.

Why use wrapper classes ?

We know that in java whenever we get input form user, it is in the form of string value so here we need to convert these string values in different different datatype (numerical or fundamental data), for this conversion we use wrapper classes.
Read More »

JP - Looping statements ~ foundjava

Looping Statement in Java

Looping statement are the statements execute one or more statement repeatedly several number of times. In java programming language there are three types of loops; while, for and do-while.

Why use loop ?

When you need to execute a block of code several number of times then you need to use looping concept in Java language.

Advantage with looping statement

  • Reduce length of Code
  • Take less memory space.
  • Burden on the developer is reducing.
  • Time consuming process to execute the program is reduced.
Read More »

JP - Decision making statements ~ foundjava

Decision Making Statement in Java

Decision making statement statements is also called selection statement. That is depending on the condition block need to be executed or not which is decided by condition. If the condition is "true" statement block will be executed, if condition is "false" then statement block will not be executed. In java there are three types of decision making statement.
  • if
  • if-else
  • switch

if-then Statement

if-then is most basic statement of Decision making statement. It tells to program to execute a certain part of code only if particular condition is true.
Read More »

JP - SOP Statements ~ foundjava

System.out.println() in Java

In java language print() and println() are the predefined non-static method of printStream class used to display value or message either in the same line or line by line respectively. PrintStream class is having fixed object reference in the System class (existing as a static properties) so that either print() or println() method can be called with following syntax..
system.out.println
Read More »

JP - CMD Arguments ~ foundjava

Command Line Arguments in Java

If any input value is passed through the command prompt at the time of running of the program is known as command line argument by default every command line argument will be treated as string value and those are stored in a string array of main() method.

Syntax for Compile and Run CMD programs

Compile By -> Javac  Mainclass.java
Run By -> Java  Mainclass value1 value2  value3 ....................
Command line arguments
Read More »

JP - Main() Method ~ foundjava

Main() Method in Java

main() method is starting execution block of a java program or any java program start their execution from main method. If any class contain main() method known as main class.
Syntax of main() method:

Syntax

public static void main(String args[])
{
.......
.......
} 
main method in java
Read More »

JP - Java Program Structure ~ foundjava

Structure of Java Program

Structure of a java program is the standard format released by Language developer to the Industry programmer.
Sun Micro System has prescribed the following structure for the java programmers for developing java application.
structure of java program
Read More »

JP - Operators in Java ~ foundjava

Operators in Java

Operator is a special symbol that tells the compiler to perform specific mathematical or logical Operation. Java supports following lists of operators.
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Ternary or Conditional Operators
Read More »

JP - Variables in Java ~ foundjava

Variable Declaration Rules in Java

Variable is an identifier which holds data or another one variable is an identifier whose value can be changed at the execution time of program. Variable is an identifier which can be used to identify input data in a program.
variable declaration in java
Read More »

JP - Datatypes in Java ~ foundjava

Data Type in Java

Datatype is a spacial keyword used to allocate sufficient memory space for the data, in other words Data type is used for representing the data in main memory (RAM) of the computer.
In general every programming language is containing three categories of data types. They are
  • Fundamental or primitive data types
  • Derived data types
  • User defined data types.
Read More »

JP - Object and Class ~ foundjava

Object and class in Java

Object is the physical as well as logical entity where as class is the only logical entity.
Class: Class is a blue print which is containing only list of variables and method and no memory is allocated for them. A class is a group of objects that has common properties.
A class in java contains:
  • Data Member
  • Method
  • Constructor
  • Block
  • Class and Interface
Read More »

JP - JVM Architecture ~ foundjava

JVM Architecture in Java

JVM (Java Virtual Machine) is a software. It is a specification that provides Runtime environment in which java bytecode can be executed.
JVM Architecture
Read More »

JP - JDK JVM JRE ~ foundjava

Difference between JDK, JVM and JRE

Jvm, Jre, Jdk these all the backbone of java language. Each components have separate works. Jdk and Jre physically exists but Jvm are abstract machine it means it not physically exists.
jvm, jdk, jre
Read More »

JP - Compile and execute ~ foundjava

Compile and Run Java Program

In the Java programming language, all source code is first written in plain text files and save with the .java extension. After compilation, .class files are generated by javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes (it is machine language of the Java Virtual Machine1 (JVM)).
Compile Java Code
The java launcher tool then runs your application with an instance of the Java Virtual Machine (JVM).
Read More »

JP - First java Program ~ foundjava

First Java Program

Requirements for java Program

For executing any java program we need given things.
  • Install the JDK any version if you don't have installed it.
  • Set path of the jdk/bin directory.
  • Create the java program
  • Compile and run the java program

Steps For compiling and executing the java program

Java is very simple programming language first we write a java program and save it with program class name.
Read More »

JP - Platform Independent ~ foundjava

How Java is Platform Independent

A programming language or technology is said to be platform independent if and only if which can run on all available operating systems with respect to its development and compilation. (Platform represents Operating System).
Java is a platform independent programming language, Because when you install jdk software on your system then automatically JVM are installed on your system. For every operating system separate JVM is available which is capable to read the .class file or byte code. When we compile your Java code then .class file is generated by javac compiler these codes are readable by JVM and every operating system have its own JVM so JVM is platform dependent but due to JVM java language is become platform independent.
Read More »

JP - Path vs Classpath ~ foundjava

Difference between path and classpath in Java

Path

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer. In Java to run any program we use java tool and for compile Java code use javac tool. All these tools are available in bin folder so we set path upto bin folder.

classpath

classpath variable is set for providing path of all Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.
Read More »

JP - Environment Setup ~ foundjava

How to Set Path and Classpath in Java

Path Variable

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath Variable

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Video Tutorial

Read More »

JP - Features of Java ~ foundjava

Features of Java

Features of a language are nothing but the set of services or facilities provided by the language vendors to the industry programmers. Some important features of java are;
features of java
Read More »

JP - Basic Points ~ foundjava

Basic Points of Java

Java is a platform independent, more powerful, secure, high performance, multithreaded programming language. Here we discuss some points related to Java.

Define byte

Byte code is the set of optimized instructions generated during compilation phase and it is more powerful than ordinary pointer code.

Define JRE

The Java Runtime Environment (JRE) is part of the Java Development Kit (JDK). It contains a set of libraries and tools for developing Java application. The Java Runtime Environment provides the minimum requirements for executing a Java application.
Read More »

JP - Overview of Java ~ foundjava

Overview of Java

Java is one of the programming language or technology used for developing web applications. Java language developed at SUN Micro Systems in the year 1995 under the guidance of James Gosling and there team. Originally SUN Micro Systems is one of the Academic university (Standford University Network)
Whatever the software developed in the year 1990, SUN Micro Systems has released on the name of oak, which is original name of java (scientifically oak is one of the tree name). The OAK has taken 18 months to develop.
The oak is unable to fulfill all requirements of the industry. So James Gosling again reviews this oak and released with the name of java in the year 1995. Scientifically java is one of the coffee seed name.
Read More »

JP - History of Java ~ foundjava

History of Java

Java language developed by company Sun Microsystems and the creator is Jamesh Gosling.
James Gosling

Story behind development of Java

Sun Microsystems Started by a group of the students who are studing in Standard University. These people found the problem in their room with electronic consumable remote. That means one electronic consumable control doesn't work on another electronics consumable. These people want to develop a common remote control which is controlling all the electronic consumables so they contact James Gosling and requested for the projects. Sun Microsystems started by a group of students out of them one person also Indian whose name Vinode Khosla.
Read More »

JP - Java Home ~ foundjava

Java Tutorial

It is one of the programming language or technology used for developing web applications. Using this technology you can develop distributed application. A Java language developed at SUN Micro Systems in the year 1995 under the guidance of James Gosling and their team. In other word It is a programming language suitable for the development of web applications. It is also used for developing desktop and mobile application.
Read More »

Basics of Java ~ foundjava

Basic Points of Java

Java is a platform independent, more powerful, secure, high performance, multithreaded programming language. Here we discuss some points related to Java.

Define byte

Byte code is the set of optimized instructions generated during compilation phase and it is more powerful than ordinary pointer code.

Define JRE

The Java Runtime Environment (JRE) is part of the Java Development Kit (JDK). It contains a set of libraries and tools for developing Java application. The Java Runtime Environment provides the minimum requirements for executing a Java application.
Read More »

Connecting to Oracle using Thin Driver ~ foundjava

Connecting to Oracle Database using Thin Driver

To connect a Java application with Oracle database using Thin Driver. You need to follow the following steps
  1. Load Driver Class: The Driver Class for oracle database is oracle.jdbc.driver.OracleDriver and Class.forName("oracle.jdbc.driver.OracleDriver") method is used to load the driver class for Oracle database.
  2. Create Connection: For creating a connection you will need a Connection URL. The Connection URL for Oracle is
    connecting to oracle
Read More »

Connecting to Access using Type-1 Driver ~ foundjava

Connecting to Access Database using Type-1 Driver

To connect a Java application with Access database using JDBC-ODBC Bridge(type-1) Driver. You need to follow the following steps

Create DSN Name

  1. Go to control panel
    Connecting to access
Read More »

Steps to Connect to Database ~ foundjava

Steps to connect a Java Application to Database

The following 5 steps are the basic steps involve in connecting a Java application with Database using JDBC.
  1. Register the Driver
  2. Create a Connection
  3. Create SQL Statement
  4. Execute SQL Statement
  5. Closing the connection
steps to connect to database
Read More »

SQL Package ~ foundjava

JDBC 4.0 API

JDBC 4.0 API is mainly divided into two package
  1. java.sql
  2. javax.sql

java.sql package

This package include classes and interface to perform almost all JDBC operation such as creating and executing SQL Queries.

Important classes and interface of java.sql package

Read More »

JDBC ~ foundjava

Introduction to JDBC

Java Database Connectivity(JDBC) is an Application Programming Interface(API) used to connect Java application with Database. JDBC is used to interact with various type of Database such as Oracle, MS Access, My SQL and SQL Server. JDBC can also be defined as the platform-independent interface between a relational database and Java programming. It allows java program to execute SQL statement and retrieve result from database.
architecture of JDBC
Read More »

Thursday, 4 May 2017

RMI ~ foundjava

Remote method invocation(RMI) allow a java object to invoke method on an object running on another machine. RMI provide remote communication between java program. RMI is used for building distributed application.

Concept of RMI application

A RMI application can be divided into two part,Client program and Server program. A Server program creates some remote object, make their references available for the client to invoke method on it. A Client program make request for remote objects on server and invoke method on them. Stub and Skeleton are two important object used for communication with remote object.

Stub and Skeleton

Stub act as a gateway for Client program. It resides on Client side and communicate with Skeleton object. It establish the connection between remote object and transmit request to it.
Read More »

Reflection classes ~ foundjava

java.lang.Class class

Class is a final class in java.lang package which extends Object class. Instance of this class represents classes and interfaces in a running Java application. It is used to analyze and change dynamic behaviour of a class at runtime.

Some Important Methods of java.lang.Class class

This class defines several methods using which we can get information about methodsconstructorsmodifiers and members of a class at runtime.

forName()

This method takes fully qualified name of classes or interface as its argument and returns instance of the class assocaited with it. Syntax
Read More »

Introduction to Reflection ~ foundjava

Reflection API

Reflection means ability of a software to analyze itself. In Java, Reflection API provides facility to analyze and change runtime behaviour of a Class, at runtime.
For example, using reflection at the runtime you can determine what method, field, constructor or modifers a class supports.

What is reflect package ?

java.lang.reflect package encapsulates several important interfaces and classes. These classes and interface define methods which are used for reflection.
Read More »

Swing Component ~ foundjava

Swing Framework contains a large set of components which provide rich functionalities and allow high level of customization. All these components are lightweight components. They all are derived from JComponent class. It supports the pluggable look and feel.

JButton

JButton class provides functionality of a button. JButton class has three constuctors,
JButton(Icon ic)

JButton(String str)

JButton(String str, Icon ic)
It allows a button to be created using icon, a string or both. JButton supports ActionEvent. When a button is pressed an ActionEvent is generated.
Read More »

Swing ~ foundjava

Swing Framework contains a set of classes that provides more powerful and flexible GUI components than those of AWTSwing provides the look and feel of modern Java GUI. Swing library is an official Java GUI tool kit released by Sun Microsystems. It is used to create graphical user interface with Java.

Main Features of Swing Toolkit

  1. Platform Independent
  2. Customizable
  3. Extensible
  4. Configurable
  5. Lightweight
Read More »

AWT ~ foundjava

AWT contains large number of classes and methods that allows you to create and manage windows GUI application. AWT is the foundation upon which Swing is made. It is used for GUI programming in Java. But now a days it is merely used because most GUI java programs are implemented using Swing because of its rich implementation of GUI controls and light-weighted nature.

AWT Hierarchy

heirarchy of component class

Read More »

Event Handling ~ foundjava

Any program that uses GUI (graphical user interface) such as Java application written for windows, is event driven. Event describes the change of state of any object. Example : Pressing a button, Entering a character in Textbox.

Components of Event Handling

Event handling has three main components,
  • Events : An event is a change of state of an object.
  • Events Source : Event source is an object that generates an event.
  • Listeners : A listener is an object that listens to the event. A listener gets notified when an event occurs.
Read More »

Event Handling ~ foundjav

Any program that uses GUI (graphical user interface) such as Java application written for windows, is event driven. Event describes the change of state of any object. Example : Pressing a button, Entering a character in Textbox.

Components of Event Handling

Event handling has three main components,
  • Events : An event is a change of state of an object.
  • Events Source : Event source is an object that generates an event.
  • Listeners : A listener is an object that listens to the event. A listener gets notified when an event occurs.
Read More »

Applet ~ foundjava

Applet in Java

  • Applets are small Java applications that can be accessed on an Internet server, transported over Internet, and can be automatically installed and run as apart of a web document. Any applet in Java is a class that extends the java.applet.Applet class.
  • An Applet class does not have any main() method.
  • It is viewed using JVM. The JVM can use either a plug-in of the Web browser or a separate runtime environment to run an applet application.
  • JVM creates an instance of the applet class and invokes init() method to initialize an Applet.
Read More »

Legacy Classes ~ foundjava

Legacy Classes

Early version of java did not include the Collection framework. It only defined several classes and interface that provide method for storing objects. When Collection framework were added in J2SE 1.2, the original classes were reengineered to support the collection interface. These classes are also known as Legacy classes. All legacy claases and interface were redesign by JDK 5 to support Generics.
The following are the legacy classes defined by java.util package
  1. Dictionary
  2. HashTable
  3. Properties
  4. Stack
  5. Vector
There is only one legacy interface called Enumeration
NOTE: All the legacy classes are syncronized
Read More »

Comparator Interface ~ foundjava

In Java, Comparator interface is used to order the object in your own way. It gives you ability to decide how element are stored within sorted collection and map.
Comparator Interface defines compare() method. This method compare two object and return 0 if two object are equal. It returns a positive value if object1 is greater than object2. Otherwise a negative value is return. The method can throw a ClassCastException if the type of object are not compatible for comparison.

Example

Student class
class Student
int roll;
  String name;
  Student(int r,String n)
  {
      roll = r;
      name = n;
  }
  public String toString()
  {
      return roll+" "+name;
  }
Read More »

Map Interface ~ foundjava

A Map stores data in key and value association. Both key and values are objects. The key must be unique but the values can be duplicate. Although Maps are a part of Collection Framework, they can not actually be called as collections because of some properties that they posses. However we can obtain a collection-view of maps.
InterfaceDescription
MapMaps unique key to value.
Map.EntryDescribe an element in key and value pair in a map. This is an inner class of map.
NavigableMapExtends SortedMap to handle the retrienal of entries based on closest match searches
SortedMapExtends Map so that key are maintained in an ascending order.
Read More »

Iterator and ListIterator ~ foundjava

Accessing a Collection

To access, modify or remove any element from any collection we need to first find the element, for which we have to cycle throught the elements of the collection. There are three possible ways to cycle through the elements of any collection.
  1. Using Iterator interface
  2. Using ListIterator interface
  3. Using for-each loop

Accessing elements using Iterator

Iterator Interface is used to traverse a list in forward direction, enabling you to remove or modify the elements of the collection. Each collection classes provide iterator() method to return an iterator.
Read More »

Collection Classes ~ foundjava

The Collection classes

Java provides a set of Collection classes that implements Collection interface. Some of these classes provide full implementations that can be used as it is and other abstract classes provides skeletal implementations that can be used as starting points for creating concrete collections.

ArrayList class

  1. ArrayList class extends AbstractList class and implements the List interface.
  2. ArrayList supports dynamic array that can grow as needed. ArrayList has three constructors.
    ArrayList()
    
    ArrayList( Collection C )
    
    ArrayList( int capacity )
    
  3. ArrayLists are created with an initial size, when this size is exceeded, it gets enlarged automatically.
  4. It can contain Duplicate elements and maintains the insertion order.
  5. ArrayLists are not synchronized.
Read More »

Collection Interfaces ~ foundjava

Interfaces of Collection Framework

The collection framework has a lot of Interfaces, setting the fundamental nature of various collection classes. Lets study the most important Interfaces in the collection framework.

The Collection Interface

  1. It is at the top of collection heirarchy and must be implemented by any class that defines a collection. Its general declaration is,
    interface Collection < E >
    
  2. Following are some of the commonly used methods in this interface.
Read More »

Introduction to Collection ~ foundjava

Collection Framework

Collection framework was not part of original Java release. Collections was added to J2SE 1.2. Prior to Java 2, Java provided adhoc classes such as Dictionary, Vector, Stack and Properties to store and manipulate groups of objects. Collection framework provides many important classes and interfaces to collect and organize group of alike objects.

Important Interfaces of Collection API

InterfaceDescription
CollectionEnables you to work with groups of object; it is at the top of collection hierarchy
DequeExtends queue to handle double ended queue.
ListExtends collection to handle sequences list of object.
QueueExtends collection to handle special kind of list in which element are removed only from the head.
SetExtends collection to handle sets, which must contain unique element.
SortedSetExtends sets to handle sorted set.
Read More »