Java is a general-purpose computer programming language that is concurrent, class-based object-oriented etc. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. The latest version is Java 8.
èWhat is a class?
In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is a blueprint from which individual objects are created.
The following Bicycle class is one possible implementation of a bicycle:
public class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;
void changeCadence(int newValue) {
cadence = newValue;
}
void changeGear(int newValue) {
gear = newValue;
}
void speedUp(int increment) {
speed = speed + increment;
}
void applyBrakes(int decrement) {
speed = speed - decrement;
}
void printStates() {
System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear);
}
}
èWhat Is an Object?
Objects are key to understanding Object-Oriented Technology. Look around right now and you’ll find many examples of real-world Objects: Your dog, your desk, your television set your bicycle.
Example :
èReal-world objects share two characteristics: They all have state and behavior. Dogs have state(name,color,breed,hungry) and behavior (barking ,fetching ,wagging tail).
èBicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior of real-world objects is a great way to begin thinking in terms of object-oriented programming.
Setting up the environment in Java
Below are the environment settings for both Linux and Windows. JVM, JRE, and JDK all three are platform dependent because the configuration of each Operating System is different. But, Java is platform independent.
There are few things which must be clear before setting up the environment
1.JDK(Java Development Kit): JDK is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.
2. JRE(Java Runtime Environment): JRE contains the parts of the Java libraries required to run Java programs and is intended for end users. JRE can be view as a subset of JDK.
3. JVM: JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides the runtime environment in which Java bytecode can be executed. JVMs are available for many hardware and software platforms.
4. JIT: The JIT Compiler is enable by default and is activated when a Java method is called. The JIT compiler compiles the bytecodes of that method into native machine code, compiling it “”Just in time” to run.When a method has been compiled, the JVM calls the compiled code of that method directly instead of interpreting it.
Steps for Setting up Java Environment for Windows
1. Java8 JDK is available at :
Click the below link to find the JDK:
2. After download, run the .exe file and follow the instructions to install Java on your machine. Once you installed Java on your machine, you have to setup environment variable.
3. Go to Control Panel -> System and Security -> System.
Under Advanced System Setting option click on Environment Variables as highlighted below.
4. Now, you have to alter the “Path” variable under System variables so that it also contains the path to the Java environment. Select the “Path” variable and click on Edit button as highlighted below.
5. You will see a list of different paths, click on New button and then add the path where java is installed. By default, Java is installed in “C:\Program Files\Java\jdk\bin” folder OR “C:\Program Files(x86)\Java\jdk\bin”. In case, you have installed java at any other location, then add that path.
6. Click OK, Save the settings and you are done !! Now to check whether the installation is done correctly, open command prompt and type java -version. You will see that java is running on your machine.
7. In order to make sure whether the compiler is set up, type javac in command prompt. You will see a list related to javac.
Steps for Linux
In Linux, there are several ways to install java. But we will refer to simplest and easy way to install java using the terminal. For Linux we will install OpenJDK. OpenJDK is a free and open source implementation of the Java programming language.
1. Go to Application -> Accessories -> Terminal.
2. Type command as below.
3. sudo apt-get install OpenJDK-8-jdk
4. For “JAVA_HOME” (Environment Variable) type command as shown below, in “Terminal” using your installation path…(Note: The default path is as shown, but if you have to install OpenJDK at other location then set that path.)
5. export JAVA_HOME = /usr/lib/jvm/java-8-openjdk
6. For “PATH” (Environment Value) type command as shown below, in “Terminal” using your installation path…Note: the default path is as shown, but if you have to install OpenJDK at other location then set that path.)
7. export PATH = $PATH:/usr/lib/jvm/java-8-openjdk/bin
8. You are done !! Now to check whether the installation is done correctly, type java -version in the Terminal.You will see that java is running on your machine.
Popular Java Editors/IDE :
§ Notepad/gedit : They are simple text-editor for writing java programs. Notepad is available on Windows and gedit is available on Linux.
§ Eclipse IDE: It is most widely used IDE(Integrated Development Environment) for developing software in java. You can download Eclipse from here.
§ Netbeans: NetBeans IDE provides Java developers with all the tools needed to create professional desktop, mobile and enterprise applications.