Java Tutorial

by Dinesh Thakur Category: Introduction to Java

The RMI architecture, shown in Figure, describes how remote objects behave and how parameters are passed between remote methods. Remote method invocation allows the program to define separately the behaviour and the code that implements the behaviour and allows running them on separate JVMs. This principle facilitates the clients to focus on the definition of a service while the servers can focus on providing the service.

 
by Dinesh Thakur Category: Introduction to Java

The Java RMI comes along with Java JDK l.l and higher versions. It is a true distributed computing application interface for Java. Java RMI is language-specific, and can provide more advanced features like serialization, security and so on.

 
by Dinesh Thakur Category: Introduction to Java

Applet: A small program for specific functions, which usually come with the operating system. Examples in Windows are Paint and Notepad. On a Macintosh, examples are Calculator and Scrapbook. The name comes from the term "applications" which is one variety of a software program.



 
by Dinesh Thakur Category: Introduction to Java

We will now make a small program that will input two integers in Java and display their sum. In this program, we will use the methods available in Scanner class to read data typed at keyboard and place it into variables that we specify.



 
by Dinesh Thakur Category: Introduction to Java

Our first program is composed of three logical parts :

1. Definition of the class;
2. Definition of the method main ();
3. Content of the method main ().

 
by Dinesh Thakur Category: Introduction to Java

A Java class is a group of Java objects all of which have the same or similar properties in common. Classes are logical entities and can never be physical. In a class  you may find:  
● Fields  
● Methods  
● Constructors  
● Blocks  
● Nested classes and an interface

In the Following Java Example, shows how to Create a Class Using Java Example. in this example we show that Syntax of java object creation is <className> objectName = new <classConstructor>; and the Syntax of defining methods of the java class is <modifier> <return-type> method-Name(<optionalParameterList>) <ExceptionList>



 
by Dinesh Thakur Category: Introduction to Java

In this Example we Reading amount, Year and interest in the class Scanner becomes analogous to reading string. In this example, the three numbers are read from the console, and then perform Simple Interest,Compound Interest operations and results printed on the screen in formatted output.

 
by Dinesh Thakur Category: Introduction to Java

In this Example we Reading the numbers and string in the class Scanner becomes analogous to reading string. In this example, the two numbers are read from the console, results printed on the screen formatted output.

 
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.



 

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.