The objects in our programs exist only while the program is executing. When the program closed, these objects cease to exist. How can we save an object in our program and restore it when the program rerun? For example, suppose that we are playing a computer chess game. We close the game before it finished. When we restart the game, it should resume from where we had left it, instead of from the beginning. One way to accomplish this would be to save information about the game (such as the locations of various game pieces, scores, and so forth) to a file, and then read this information back from the file to restore the game to the state where we had left it when it runs next. This is the idea behind serialization. Serialization is saving an object’s state as a binary stream (that is, as a sequence of bytes). When an object is serialized, it is said to be flattened or deflated. The reverse process of constructing an object from the binary data is known as deserialization. Thus, a deserialised (or inflated) object is one whose state has restored. [Read more…] about Serialization and Deserialization in Java with Example
In Java 1.5, a new class known as Scanner class was introduced to simplify the task of getting input from the user. The Scanner class is in java.util package which allows the user to read the data dynamically from the keyboard. It can be used to read a File on the disk. The Java Scanner class extends Object class is present in java.lang package and implements Iterator and Closeable interfaces. [Read more…] about Scanner Class in Java With Example
Immutable class means unmodifiable or unchangeable, i.e., once the object has been created, they are immutable objects, there is no way to modify the text it represents. In Java, all primitive java.lang package wrapper classes (like String, Boolean, Byte, Short, Integer, Long, Float, Double, etc.) and String classes are immutable. [Read more…] about What is an Immutable Class in Java? How to create it.
In this section, we will see the implementation of a simplified version of linked list class provided by the Java library. This shows how the lists of operations manipulate the links when the list is modified. [Read more…] about How to Implementing linked lists in java
You’ve probably used a computer for work or leisure. Many people use computers for everyday tasks such as check the bank balance or write a school report. Computers are good for these tasks. They can treat repetitive tasks, such as adding numbers or insert words on a page without getting bored or exhausted. Computers are also good for games because they can play sequences of sounds and images, involving the human user in the process. [Read more…] about What is programming?
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. [Read more…] about What is RMI Architecture?
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. [Read more…] about What is RMI (Remote Method Invocation)?
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. [Read more…] about What is applet?
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:
● Nested classes and an interface [Read more…] about Java Class Example Code
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. [Read more…] about Write a java program to calculate the simple and compound interest using Scanner class.
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. [Read more…] about Write a java program to get the input through the keyboard using scanner class.
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. [Read more…] about How to compiling and running a Java program
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. [Read more…] about Difference between Procedural and Object Oriented Programming
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. [Read more…] about Java this keyword with example
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. [Read more…] about Garbage Collection in Java
Java interface use for achieving 100% abstraction because the interface only contains methods without any implementation or body. However, it has only abstract methods and constants (final fields). Any field declared inside the interface is public, static, and final by default, and any method is an abstract public method. It specifies what must do but not how. Once an interface is defined, the class implements an interface by implementing each method declared by the interface. Also, one class can implement any number of interfaces. [Read more…] about Interface in java with Example Programs
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. [Read more…] about Java Classes and Objects (With Example) – Definition
The objects are the building blocks of the object oriented programming language. A programmer may use multiple objects belonging to different classes in some situations, which may have some 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 motorcycle information, respectively. Both Car and Motorcycle classes exhibit some relationship as both are vehicles and share some common features like speed, engine specification, etc. To represent the relationship between classes, we use the concept of Inheritance. [Read more…] about Inheritance in 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. [Read more…] about What is Polymorphism in java? With Example
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. [Read more…] about What is Encapsulation in Java? – Definition
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: [Read more…] about What is Constructor in Java with Example
Java is the object-oriented, platform-independent programming language used to develop distributed applications that run on the Internet. It is similar to C++ high-level programming language and architecture-neutral developed by James Gosling, an engineer at Sun Microsystems in 1995 and later acquired by Oracle Corporation. He decided to create a new language since he was not very happy with the C++ programming language used and first named it Oak after the oak tree that he could observe from his office window. [Read more…] about What is Java? – Definition and Meaning
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. [Read more…] about What is enum in java?