Are You Feeling any difficulity while writing Core-Java Programs. Send those to me Here.

Introduction to JAVA

Introduction to JAVA

Unit Structure

1.0 Introduction
1.1 Basic concepts of OOPs
1.2 Java History
1.3 Java Feature
1.4 Comparison in Java and C++
1.5 Java Virtual Machine
1.6 Java Environment
1.7 Program
1.8 Summary

1.1 Introduction:

Java is a high-level, third generation programming language, like C, FORTRAN, Smalltalk, Perl, and many others. You can use Java to write computer applications that play games, store data or do any of the thousands of other things computer software can do. Compared to other programming languages, Java is most similar to C. However although Java shares much of C's syntax, it is not C. Knowing how to program in C or, better yet, C++, will certainly help you to learn Java more quickly, but you don't need to know C to learn Java. A Java compiler won't compile C code, and most large C programs need to be changed substantially before they can become Java programs. What's most special about Java in relation to other programming languages is that it lets you write special programs called applets that can be downloaded from the Internet and played safely within a web browser. Java language is called as an Object-Oriented Programming language and before begining for Java, we have to learn the concept of OOPs(Object-Oriented Programming).

1.2 Basic Concept of OOP(Object-Oriented Programming):

There are some basic concepts of object oriented programming as follows:
1. Object
2. Class
3. Data abstraction
4. Data encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic binding


1. Object

Objects are important runtime entities in object oriented method. They may characterize a location, a bank account, and a table of data or any entry that the program must handle.
For example:
Object: STUDENT
DATA
Name
Address
Marks
METHODS
Total()
Average()
Fig.1.1 Representation of an object ―STUDENT‖
Each object holds data and code to operate the data. Object can interact without having to identify the details of each other‘s data or code. It is sufficient to identify the type of message received and the type of reply returned by the objects.
Another example of object is CAR
Object: CAR
DATA
Colour
Cost
METHODS
LockIt()
DriveIt()
Fig.1.2 Representation of object ―CAR‖
Fig.1.1and Fig.1.2 shows actual representation of object.

2. Classes

A class is a set of objects with similar properties (attributes), common behaviour (operations), and common link to other objects. The complete set of data and code of an object can be made a user defined data type with the help of class.
The objects are variable of type class. A class is a collection of objects of similar type. Classes are user defined data types and work like the build in type of the programming language. Once the class has been defined, we can make any number of objects belonging to that class. Each object is related with the data of type class with which they are formed.
As we learned that, the classification of objects into various classes is based on its properties (States) and behaviour (methods). Classes are used to distinguish are type of object from another. The important thing about the class is to identify the properties and procedures and applicability to its instances.

In above example, we will create an objects MH-01 1234 belonging to the class car. The objects develop their distinctiveness from the difference in their attribute value and relationships to other objects.

3. Data Abstraction

Data abstraction refers to the act of representing important description without including the background details or explanations.
Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, cost and functions operate on these attributes. They summarize all the important properties of the objects that are to be created.
Classes use the concepts of data abstraction and it is called as Abstract Data Type (ADT).

4. Data Encapsulation

Data Encapsulation means wrapping of data and functions into a single unit (i.e. class). It is most useful feature of class. The data is not easy to get to the outside world and only those functions which are enclosed in the class can access it.
These functions provide the boundary between Object‘s data and program. This insulation of data from direct access by the program is called as Data hiding.
For example:


Data, process/Functions
Information in-->> -->>Information out
Fig1.5: Encapsulation

5. Inheritance

Inheritance is the process by which objects of one class can get the properties of objects of another class. Inheritance means one class of objects inherits the data and behaviours from another class. Inheritance maintains the hierarchical classification in which a class inherits from its parents.
Inheritance provides the important feature of OOP that is reusability. That means we can include additional characteristics to an existing class without modification. This is possible deriving a new class from existing one.
In other words, it is property of object-oriented systems that allow objects to be built from other objects. Inheritance allows openly taking help of the commonality of objects when constructing new classes. Inheritance is a relationship between classes where one class is the parent class of another (derived) class. The derived class holds the properties and behaviour of base class in addition to the properties and behaviour of derived class.

In Fig.1.5, the Santro is a part of the class Hyundai which is again part of the class car and car is the part of the class vehicle. That means vehicle class is the parent class.

6. Polymorphism

(Poly means ―many‖ and morph means ―form‖). Polymorphism means the ability to take more than one form. Polymorphism plays a main role in allocate objects having different internal structures to share the same external interface. This means that a general class of operations may be accessed in the same manner even though specific activities associated with each operation may differ. Polymorphism is broadly used in implementing inheritance.
It means objects that can take on or assume many different forms. Polymorphism means that the same operations may behave differently on different classes. Booch defines polymorphism as the relationship of objects many different classes by some common super class. Polymorphism allows us to write generic, reusable code more easily, because we can specify general instructions and delegate the implementation detail to the objects involved.
For Example:
In a pay roll system, manager, office staff and production worker objects all will respond to the compute payroll message, but the real operations performed are object particular.


7. Dynamic Binding

Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code related with a given procedure call is not known until the time of the call at run time.
Dynamic binding is associated polymorphism and inheritance.

1.3 Java History:

Java is a general-purpose, object-oriented programming language developed by Sun Microsystems of USA in 1991.Originally called Oak by James Gosling (one of the inventor of the language). Java was invented for the development of software for cunsumer electronic devices like TVs, tosters, etc. The main aim had to make java simple, portable and reliable.
Java Authors: James , Arthur Van , and others
Rectangle Object
Draw (Rectangle)
Square Object
Draw (Square)
Circle Object
Draw (Circle)
Following table shows the year and beginning of Java.
Year--Progress
1990--Sun decided to developed software that could be used for electronic devices. And the project called as Green Project head by James Gosling.
1991--Announcement of a new language named ―Oak‖
1992--The team verified the application of their new language to manage a list of home appliances using a hand held device.
1993--The World Wide Web appeared on the Internet and transformed the text-based interface to a graphical rich environment.
1994--The team developed a new Web browsed called ―Hot Java‖ to locate and run Applets.
1995--Oak was renamed to Java, as it did not survive ―legal‖ registration. Many companies such as Netscape and Microsoft announced their support for Java.
1996--Java language is now famous for Internet programming as well as a general purpose OO language.
1997--Sun releases Java Development Kit(JDK 1.1)
1998--Sun releases Software Development Kit (SDK 1.2)
1999--Sun releases Java 2 platform Standard Edition (J2SE) and Enterprise Edition(J2EE).
2000--J2SE with SDK 1.3 was released.
2002--J2SE with SDK 1.4 was released.
2004--J2SE with JDK 5.0 was released.

1.4 JAVA Features:

As we know that the Java is an object oriented programming language developed by Sun Microsystems of USA in 1991. Java is first programming language which is not attached with any particular hardware or operating system. Program developed in Java can be executed anywhere and on any system.
Features of Java are as follows:
1. Compiled and Interpreted
2. Platform Independent and portable
3. Object- oriented
4. Robust and secure
5. Distributed
6. Familiar, simple and small
7. Multithreaded and Interactive
8. High performance
9. Dynamic and Extensible

1. Compiled and Interpreted

Basically a computer language is either compiled or interpreted. Java comes together both these approach thus making Java a two-stage system.
Java compiler translates Java code to Bytecode instructions and Java Interpreter generate machine code that can be directly executed by machine that is running the Java program.

2. Platform Independent and portable

Java supports the feature portability. Java programs can be easily moved from one computer system to another and anywhere. Changes and upgrades in operating systems, processors and system resources will not force any alteration in Java programs. This is reason why Java has become a trendy language for programming on Internet which interconnects different kind of systems worldwide. Java certifies portability in two ways.
First way is, Java compiler generates the bytecode and that can be executed on any machine. Second way is, size of primitive data types are machine independent.

3. Object- oriented

Java is truly object-oriented language. In Java, almost everything is an Object. All program code and data exist in objects and classes. Java comes with an extensive set of classes; organize in packages that can be used in program by Inheritance. The object model in Java is trouble-free and easy to enlarge.

4. Robust and secure

Java is a most strong language which provides many securities to make certain reliable code. It is design as garbage –collected language, which helps the programmers virtually from all memory management problems. Java also includes the concept of exception handling, which detain serious errors and reduces all kind of threat of crashing the system.
Security is an important feature of Java and this is the strong reason that programmer use this language for programming on Internet.
The absence of pointers in Java ensures that programs cannot get right of entry to memory location without proper approval.

5. Distributed

Java is called as Distributed language for construct applications on networks which can contribute both data and programs. Java applications can open and access remote objects on Internet easily. That means multiple programmers at multiple remote locations to work together on single task.

6. Simple and small

Java is very small and simple language. Java does not use pointer and header files, goto statements, etc. It eliminates operator overloading and multiple inheritance.

7. Multithreaded and Interactive

Multithreaded means managing multiple tasks simultaneously. Java maintains multithreaded programs. That means we need not wait for the application to complete one task before starting next task. This feature is helpful for graphic applications.

8. High performance

Java performance is very extraordinary for an interpreted language, majorly due to the use of intermediate bytecode. Java architecture is also designed to reduce overheads during runtime. The incorporation of multithreading improves the execution speed of program.

9. Dynamic and Extensible

Java is also dynamic language. Java is capable of dynamically linking in new class, libraries, methods and objects. Java can also establish the type of class through the query building it possible to either dynamically link or abort the program, depending on the reply.
Java program is support functions written in other language such as C and C++, known as native methods.

1.5 Comparison in Java and C++




1.6 Java Virtual machine:

As we know that all programming language compilers convert the source code to machine code.Same job done by Java Compiler to run a Java program, but the difference is that Java compiler convert the source code into Intermediate code is called as bytecode. This machine is called the Java Virtual machine and it exits only inside the computer memory.
Following figure shows the process of compilation.

The Virtual machine code is not machine specific. The machine specific code is generated. By Java interpreter by acting as an intermediary between the virtual machine and real machines shown below




Java Object Framework act as the intermediary between the user programs and the virtual machine which in turn act as the intermediary between the operating system and the Java Object Framework.



Fig: Layers of Interaction for Java programs

1.7 Java Environment:

Java environment includes a number of development tools, classes and methods. The development tools are part of the system known as Java Development Kit (JDK) and the classes and methods are part of the Java Standard Library (JSL), also known as the Application Programming Interface (API).
Java Development kit (JDK) – The JDK comes with a set of tools that are used for developing and running Java program. It includes:
1. Appletviewer( It is used for viewing the applet)
2. Javac(It is a Java Compiler)
3. Java(It is a java interpreter)
4. Javap(Java diassembler,which convert byte code into program description)
5. Javah(It is for java C header files)
6. Javadoc(It is for creating HTML document)
7. Jdb(It is Java debugger)

For compiling and running the program we have to use following commands:

a) javac (Java compiler)
In java, we can use any text editor for writing program and then save that program with ―.java‖ extension. Java compiler convert the source code or program in bytecode and interpreter convert ―.java‖ file in ―.class‖ file.
Syntax:
C:\javac filename.java
If my filename is ―abc.java‖ then the syntax will be
C:\javac abc.java

b) java(Java Interpreter)

As we learn that, we can use any text editor for writing program and then save that program with ―.java‖ extension. Java compiler convert the source code or program in bytecode and interpreter convert ―.java‖ file in ―.class‖ file.
Syntax:
C:\java filename
If my filename is abc.java then the syntax will be
C:\java abc

1.5 Simple Java Program:

class FirstProgram
{
public static void main(String args[])
{
System.out.println(―This is my first program‖);
}
}



  • The file must be named ―FirstProgram.java‖ to equivalent the class name containing the main method. 
  • Java is case sensitive. This program defines a class called ―FirstProgram‖. 
  • A class is an object oriented term. It is designed to perform a specific task. 
  • A Java class is defined by its class name, an open curly brace, a list of methods and fields, and a close curly brace. 
  • The name of the class is made of alphabetical characters and digits without spaces, the first character must be alphabetical. 
  • The line ―public static void main (String [] args )‖ shows where the program will start running. The word main means that this is the main method –
  • The JVM starts running any program by executing this method first. 
  • The main method in ―FirstProgram.java‖ consists of a single statement
  • System.out.println("This is my first program"); 
  • The statement outputs the character between quotes to the console.


Above explanation is about how to write program and now we have to learn where to write program and how to compile and run the program.

For this reason, the next explanation is showing the steps.
1. Edit the program by the use of Notepad.
2. Save the program to the hard disk.
3. Compile the program with the javac command.(Java compiler)
4. If there are syntax errors, go back to Notepad and edit the program.
5. Run the program with the java command.(Java Interpreter)
6. If it does not run correctly, go back to Notepad and edit the program.
7. When it shows result then stop.

Summary:

In this unit, we learn the concept of Object Oriented Programming, Introduction of Java, History of Java, Features of Java, Comparison between C++ and Java, Java virtual Machine and Java Environment.




7 comments:

  1. Learn and practice some important MCQ with answers on various categories useful for competitive exams
    http://www.gkindiaonline.com/

    ReplyDelete
  2. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai

    ReplyDelete
  3. I am regular reader of your blog from long time,What a Beautiful post! This is so chock full of useful information I can’t wait to dig and start using my time on blogging and I am looking for and I love to post a comment that "The content of your post is awesome" Great work!
    Java Training in Chennai

    Java Training in Velachery

    Java Training inTambaram

    Java Training in Porur

    Java Training in Omr

    Java Training in Annanagar

    ReplyDelete