Java Tutorial

by Dinesh Thakur Category: Introduction to Java

Java program has two types. They are:

 

1. Application Program (Stand-alone application)

2. Applets Program.

 
by Dinesh Thakur Category: Introduction to Java

The first step of compiling and running a Java program is to write the text of your program in a document and save it on the hard drive. This document is called a source file, and you must name it with a .java extension. Next, compile this program using a Java compiler. The compiler checks the program for errors and, if no errors are found, it generates a new document containing Java bytecode. This document is called a class file, and its name ends with a .class extension.



 
by Dinesh Thakur Category: Introduction to Java

The different languages reflect the different styles of programming. OOP or object-oriented programming is a style of programming with a firm basis in several concepts. Those concepts revolve around objects and classes and include Polymorphism, Encapsulation, Inheritance, Abstraction and more.  Java is one of the most popular of all the object-oriented programming languages, as well as one of the easiest to learn and use.   
Any application built on objects in Java is an object-oriented application and is based on the declaration of one or more classes, with an object created from those classes and the interaction between the objects.    

 
by Dinesh Thakur Category: Introduction to Java

Public keyword is an access specifier.

Static allows main() to be called without having to instantiate a particular instance of class.

 
by Dinesh Thakur Category: Introduction to Java

Modifiers are keywords used to define the scope and behaviour of classes, methods and variables in Java. Access modifiers specified who can access them. Java has a wide variety of modifiers that can be categorized as shown below:

 
by Dinesh Thakur Category: Introduction to Java

The this keyword in Java is used when a method has to refer to an object that has invoked it. It can be used inside any method to refer to the current object. This means that this is always used as a reference to the object on which the method was invoked. We can use this anywhere as reference to an object of the current class type is permitted.

 
by Dinesh Thakur Category: Introduction to Java

When you create an object by instantiating a class, the object uses some memory. After an object in memory has been used and is no longer needed, it is sensible to free memory from that object. Unlike some object-oriented languages where you have to explicitly destroy the objects that are no more references to that object. References that held in a variable naturally dropped when the variable goes out of scope. Alternatively, we can explicitly drop an object reference by setting the variable to null. which is a tedious and error-prone task, Java follows a different approach.

 
by Dinesh Thakur Category: Introduction to Java

Java interface used for achieving 100% abstraction because of the interface only contains methods without any implementation or body. However, it contains only abstract methods and constants (final fields). Any field that declared inside interface is public, static, and final by default, any method is an abstract public method. It specifies what must be done but not how. Once an interface is defined, class implements an interface by providing an implementation for each method declared by the interface. Also one class can implement any number of interfaces. Interfaces have the following advantages.

 
by Dinesh Thakur Category: Introduction to Java

Objects and classes are the essential concepts in OOP as they are what we use for writing our programs. Java objects may be both physical and logical entities, but classes are only logical entities.

In the real world, you'll often find many individual objects all of the same kind.All the objects that have similar properties and similar behavior are grouped together to form a class.

 
by Dinesh Thakur Category: Introduction to Java

Defination : The objects, are the building blocks of the object oriented programming language. In some situations, a programer may use multiple objects belonging to different classes which may have some kind of relationship among themselves as they share some common features.

Let us consider an example of a program containing objects of two different classes Car and Motorcycle for maintaining car and motor cycle information respectively. Both Car and Motorcycle classes exhibit some kind of relationship as both are a kind of vehicle and share some common features like speed, engine specification etc. To represent relationship between classes, we use the concept of Inheritance.



 
by Dinesh Thakur Category: Introduction to Java

Polymorphism is a very powerful concept that allows you to design amazingly flexible applications. The word 'Polymorphism: is derived form two Greek words 'poly' which means many and 'morphos' which means forms. So, polymorphism means the ability to take many forms.

 
by Dinesh Thakur Category: Introduction to Java

Definition: Encapsulation and data hiding are the key features of object oriented programming. Encapsulation refers to the ability to package related behavior in an object bundle and control or restrict their access in both function and data from other objects. It necessarily is all about packaging related stuff together and keeping them away from external elements. You will note that keywords encapsulation along with data hiding is used interchangeably all over.

 
by Dinesh Thakur Category: Introduction to Java

Initializing a variable is considered very helpful while making programs. We can initialize variables of primitive types at the time of their declarations. For example:

int a =10;

In Object Oriented Programming language (OOPL) like Java, the need of initialization of fields of a new object is even more common. We have already done this using two approaches.

 
by Dinesh Thakur Category: Introduction to Java

Java is the object-oriented programming language, similar to C++ high-level programming language and architecture neutral developed by Sun Microsystems in 1995 and later acquired by Oracle Corporation. Java was originally called OAK. Java is a computing platform for application development. Object-Oriented meaning the capability to reuse code. Secondly, it is platform independent, i.e., we don't have to develop separate applications for different platforms. It is possible to develop a single application which can run on multiple platforms like Windows, UNIX, and Macintosh systems. Java designed for hand-held devices and set-top boxes.

 
by Dinesh Thakur Category: Introduction to Java

The Java Compiler (Javac) is a command line tool that reads java source code files and compiles them into executable Java bytecode classes. The Java source code must be contained in files whose file names end with .java extension.



 
by Dinesh Thakur Category: Introduction to Java

Enumeration (enum) was not originally available in Java though it was available in other language like C and C++ but eventually Java realized and added to version 5 of Java were the safe type enumerations (Type Safe Enums), which allows you to create enums in Java, just as they exist in other technologies. It is defined by the reserved word enum, and each item in the enumeration is represented by an object of the same type as the Enum. The definition of an enumeration is no more than the definition of a special kind of class. If they were in another package, they should be imported like any other normal classes.

 
by Dinesh Thakur Category: Java Evolution

The JAR file (Java ARchive) is a way to compress multiple files in Java, as well as a ZIP. Usually the classes and other configuration files are stored.
As they grouped several classes in a single file, they are great for distributing libraries, such as database drivers, frameworks, systems modules, etc.



 
by Dinesh Thakur Category: Java Evolution

(Open Database Connectivity) An APPLICATION PROGRAMMING INTERFACE published by Microsoft which, by loading the appropriate ODBC driver at run time, enables the same program code to have access to data from many different brands of database.



 
by Dinesh Thakur Category: Java Evolution

Java Virtual Machine (JVM)

JVM is a set of computer software programs and data structures which implements a specific Virtual machine model.



 
by Dinesh Thakur Category: Java Evolution

The means that allows Java to solve both the security and the portability problems is that the output of a Java compiler is not executable code but it is the Bytecode. Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the lava Virtual Machine (JVM). JVM is an interpreter for bytecode. The fact that a Java program is executed by JVM helps solve the major problems associated with downloading programs over the Internet. Translating a Java program into bytecode helps makes it much easier to run a program in a wide variety of environments. This is because only the JVM needs to be implemented for each platform.

 

Page 2 of 40



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.