1. Introduction to Java
1.1. A small history of Java
Java is a programming dialect made by James Gosling from Sun Microsystems (Sun) in 1991. The objective of Java is to compose a program once and afterwards run this program on various working frameworks. The principal freely accessible variant of (Java 1.0) was discharged in 1995. Sun Microsystems was gained by the Oracle Corporation in 2010. Prophet has now the steermanship for Java. In 2006 Sun began to make Java accessible under the GNU General Public License (GPL). Prophet proceeds with this undertaking called OpenJDK.
After some time new upgraded forms of Java have been discharged. The present adaptation of Java will be Java 1.8 which is otherwise called Java 8.
Java is characterized by a determination and comprises of a programming dialect, a compiler, centre libraries and a runtime (Java virtual machine) The Java runtime enables programming engineers to compose program code in different dialects than the Java programming dialect which still keeps running on the Java virtual machine. The Java stage is normally connected with the Java virtual machine and the Java centre libraries.
The Java dialect was outlined with the accompanying properties:
Stage autonomous: Java programs utilize the Java virtual machine as deliberation and don't get to the working framework specifically. This makes Java programs very convenient. A Java program (which is standard-agreeable and takes after specific principles) can run unmodified on every single bolstered stage, e.g., Windows or Linux.
Question orientated programming dialect: Except the crude information composes, all components in Java are objects.
Specifically programming dialect: Java is specifically, e.g., the kinds of the utilized factors must be pre-characterized and transformation to different items is moderately strict, e.g., must be done much of the time by the software engineer.
Translated and arranged dialect: Java source code is moved into the bytecode design which does not rely upon the objective stage. These bytecode guidelines will be translated by the Java Virtual machine (JVM). The JVM contains a purported Hotspot-Compiler which deciphers execution basic bytecode directions into local code guidelines.
Programmed memory administration: Java deals with the memory designation and de-allotment for making new questions. The program does not have guide access to the memory. The supposed city worker consequently erases articles to which no dynamic pointer exists.
The Java linguistic structure is like C++. Java is case-delicate, e.g., factors called myValue and myvalue are dealt with as various factors.
1.2. Hello world Java program
// a small Java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
1.3. Java virtual machine
The Java virtual machine (JVM) is a product usage of a PC that executes programs like a genuine machine.
The Java virtual machine is composed particularly for a particular working framework, e.g., for Linux an exceptional usage is required and also for Windows.
Java programs are compiled by the Java compiler into bytecode. The Java virtual machine interprets this bytecode and executes the Java program.
1.4. Java Runtime Environment vs. Java Development Kit
A Java dispersion ordinarily comes in two flavors, the Java Runtime Environment (JRE) and the Java Development Kit (JDK).
The JRE comprises of the JVM and the Java class libraries. Those contain the important usefulness to begin Java programs.
The JDK moreover contains the improvement instruments important to make Java programs. The JDK along these lines comprises of a Java compiler, the Java virtual machine and the Java class libraries.
1.5. Development Process with Java
Java source records are composed as plain content reports. The developer ordinarily composes Java source code in an Integrated Development Environment (IDE) for programming. An IDE underpins the software engineer in the undertaking of composing code, e.g., it gives auto-formating of the source code, featuring of the critical watchwords, and so on.
Eventually, the software engineer (or the IDE) calls the Java compiler ( javac ). The Java compiler makes the bytecode guidelines. These directions are put away in .class records and can be executed by the Java Virtual Machine.
1.6. Garbage collector
The JVM naturally re-gathers the memory which isn't alluded to by different articles. The Java trash specialist checks all question references and finds the items which can be naturally discharged.
While the trash specialist calms the software engineer from the need to unequivocally oversee memory, the developer still needs to guarantee that he doesn't keep unneeded protest references, generally, the city worker can't discharge the related memory. Keeping unneeded protest references are normally called memory spills.
1.7. Classpath
The classpath characterizes where the Java compiler and Java runtime search for .class records to stack. These directions can be utilized in the Java program.
For instance, on the off chance that you need to utilize an outer Java library you need to add this library to your classpath to utilize it in your program.
2. Installation of Java
2.1. Check installation
To run Java programs on your PC you should, in any event, have the Java runtime condition (JRE) introduced. This may as of now be the situation on your machine. You can test is the JRE is introduced and in your present way by opening a reassure (on the off chance that you are utilizing Windows: Win+R, enter cmd and press Enter) and by composing in the accompanying summon:
java –version
In the event that the JRE is introduced and inside your way, this summons prints data about your Java establishment. For this situation, you can avoid the Java establishment depiction.
In the event that the summon line restores the data that the program couldn't be discovered, you need to introduce Java.
How might you let you know are utilizing a 32 bit or 64 bit variant of Java?
You can run a 32 bit or a 64 bit variant of Java on a 64-bit framework. On the off chance that you utilize java - variant and the yield contains the "64-Bit" string you are utilizing the 64-bit form of Java generally your are utilizing the 32-bit rendition. The accompanying is the yield of a 64-bit rendition.
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
2.2. Install Java on Ubuntu
On Ubuntu, you can introduce Java 8 by means of the accompanying summon on the charge line. These summonses may change after some time, on the off chance that they don't work any longer please Google for the establishment.
# install Java from the OpenJDK project
sudo apt-get install openjdk-8-jdk
# in case you prefer the Oracle Java distribution
# you can alternatively use the following commands
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
2.3. Install Java on MS Windows
For Microsofts Windows, Oracle gives a local installer which can be found on the Oracle site. The focal site for introducing Java is situated under the accompanying URL and furthermore contains guidelines on how to introduce Java for different stages: https://java.com/en/
2.4. Installation problems and other operating systems
In the event that you have issues introducing Java on your framework, look by means of Google for How to introduce JDK on YOUR OS. This should result in supportive connections. Supplant YOUR OS with your working framework, e.g., Windows, Ubuntu, Mac OS X, and so forth.
2.5. Validate installation
Change again to the summon line and run the accompanying order.
java -version
The output should be similar to the following output.
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
Object Oriented Programming
Object Oriented programming is a programming type that is associated with the concept of Class, Objects and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation, Overloading etc.
Give us a chance to attempt to comprehend somewhat about all these, through a basic illustration. Individuals are living structures, comprehensively classified into two kinds, Male and Female. Correct? It's actual. Each Human being(Male or Female) has two legs, two hands, two eyes, one nose, one heart and so forth. There are body parts that are basic for Male and Female, yet then there are some particular body parts, exhibit in a Male which is absent in a Female, and some body parts display in Female however not in Males.
Every single Human Being walks, eat, see, talk, hear and so forth. Presently once more, both Male and Female play out some regular capacities, however, there are a few specifics to both, which isn't substantial for the other. For instance: A Female can conceive an offspring, while a Male can't, so this is just for the Female.
Human Anatomy is intriguing, would it say it isn't? In any case, how about we perceive how this is identified with Java and OOPS. Here we will attempt to clarify all the OOPS ideas through this illustration and later we will have the specialized definition for this.
Object Oriented Programming Concept Definitions
Now, let us discuss some of the main features of Object Oriented Programming which you will be using in Java(technically).
1. Objects
2. Classes
3. Abstraction
4. Encapsulation
5. Inheritance
6. Overloading
7. Exception Handling
Class
Here we can take Human Being as a class. A class is a blueprint for any functional entity which defines its properties and its functions. Like Human Being, having body parts, and performing various actions.
Inheritance
Let
HumanBeing
a class, which has properties like hands, legs, eyes, ears, mouth etc and functions like walk, talk, eat, see etc. Male
and Female
are also classes, but most of the properties and functions are included in HumanBeing
, hence they can inherit everything from class HumanBeing
using the concept of Inheritance.
Objects
My name is Subham, and I am an instance or object of class
Male
. When we say, Human_Being, Male or Female, we just mean a kind, you, your friend, me we are the forms of these classes. We have a physical existence while a class is just a logical definition. We are the objects.
Abstraction
Abstraction means, showcasing only the required things to the outside world while hiding the details. Example, Human Being can talk, walk, hear, eat, but the details are hidden from the outside world. We can take our skin as the Abstraction for hiding the inside mechanism.
Encapsulation
This concept is a little tricky to explain with an example. Our Legs are bound to help us walk. Our hands, help us hold things. This binding of the properties to functions is called Encapsulation.
Polymorphism
Polymorphism is a concept, which allows us to redefine the way something works, by either changing how it is done or by changing the parts using which it is done. Both the ways have different terms for them.
If we walk using our hands, and not legs, here we will change the parts used to perform something. Hence this is called Overloading.
And if there is a defined way of walking, but I wish to walk differently, but using my legs, like everyone else. Then I can walk like I want, this will be called as Overriding.
Exception Handling
Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at runtime.
JAVA APPLICATIONS
Java has advanced from a basic dialect giving intuitive unique substance to website pages to a dominating undertaking empowered programming dialect reasonable for creating huge and basic applications. Today, It is utilized for some sorts of utilizations including Web-based applications, Financial applications, Gaming applications, implanted frameworks, Distributed undertaking applications, portable applications, Image processors, work area applications and some more. This site diagrams the building squares of java by expressing few java cases alongside some java instructional exercises.
Can u explain what is static binding and dynamic binding in java with an example?
ReplyDelete