DevOps Prerequisite (Part 3): Application basics and Java
Tags: devops
Published: 2023-03-20 16:02:38

Programming language can be classified as Compiled and interpreted.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z3zbxyzapb0mufjdsz62.png)



1.Compiled (Developed-> Compiled -> Executed): C, C++, Java. Compiled program is first written and then it is compiled for a machine . It works for the specific machine it is designed for. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6h3x07o41gya5piasn3h.png)
For java, it it:







and
2. Interpreted (Developed ->Executed): Node.js, ruby, python. Here the program is developed and then it runs. The basic code is generally encrypted as a bytecode and then it runs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jzvcsrhm886jy2lfrjt.png)


Basics:

In old days, _for Python_
This is what compiler used to do:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exk44w9wugpxha173lhj.png)
It would create a machine code which is different for different languages. 

Nowadays,
But to solve this issue, there came bytecode .

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vy60v0unoigkx0p9a2s7.png)
This bytecode is then interpreted by the python interpreter

The bytecode is then converted into a machine language by the python virtual machine (an environment to run python)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0br7b0abdd1mj8k7e0dm.png)
So, as long as the environment exists, it creates a machine language from source code . The machine language is implemented and the code runs.

So, running main.py does all of these in background.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tgxvgzohelo2f8k0dr2.png)

_For Java_,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pswdbpo7o0bjh3wovfts.png)
you can develop your code once and compile it and then run it everywhere. This makes java cross platform.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0klo2jd0z4sd1yew0kqp.png)



**Basics of Java**
It is a free and open sourced community

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/289y4lm2z0hczed63ttk.png)
Install java on CenTos:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f8lr3k8s4bnjocjsqcr.png)
Let's check a situation:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zvqdr7fndl2fbhmt2pj.png)
Here what happened is :

ssh app01 to login to app01 server and run below command to download
sudo curl https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_linux-x64_bin.tar.gz --output /opt/openjdk-13.0.2_linux-x64_bin.tar.gz

To uncompress run sudo tar -xf /opt/openjdk-13.0.2_linux-x64_bin.tar.gz -C /opt/

To verify run /opt/jdk-13.0.2/bin/java -version on app01 and confirm correct version is installed.

This is how we are going to install java in this situation.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38nef8j2vpdfombzwowz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84vxp7khzylvyvg5928k.png)


Done with installing!!!

Here you will need jdk which is actually installed while installing java:



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ct3n2n8m85m9vyvbcg0l.png)

This is what develops, builds and runs your code.

before the version 9 of java, JDK & JRE had to be installed differently. They were not in one single package.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7oob553syzzmizap20ds.png)



But after that JRE is within the JDK

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i7tkv0471t5rre4ndhnn.png)


**More about java**
Java is compiled like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxxms1woelb157p831sb.png)
Java code is compiled to a bytecode and then run in a Virtual Machine.


This is how java code is packaged:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwkf27y9s8twp1tmtkww.png)
using the jar command , we create a output file named Myapp.jar using the contents MyClass.class,Service1.class..........

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1ia57gj3pxc87a5w0qp.png)


When this file is created it automatically generates a manifest file within the package at path "META-INF/MANIFEST.MF"


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86upgm33bqmwg4p973ry.png)


The contains information about the package details.

Once built and compile , java code can be run any where.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nygs3womdkwowy1esxgc.png)


For documentation, we use `javadoc`
It is basically shown in a html version after documentated.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6vnd8fssy9jqwxucacs.png)

So, in the build process the code is developed, compiled, packaged and documented.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o273m3d312mabocrxzgs.png)

For the complex  codes, this can become messy and thus there are some build tools which can be used for Java:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l243fltqv7l93lpytxyp.png)
You can specify the build rules or the order to proceed for the build tools:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g5rsis8l7h47v9sa75qr.png)

For example, lets use a build tool ANT:
Generally or manually we would develop, document and package the code:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t3c7t1ekz4gruz8lrheq.png)

But using build tool,
This is how we will use XML format :
To develop
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8r474qnr1xisxbw8cnr6.png)
To document

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7z54t740vwc2vpfjjm0i.png)
To package

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhjbua4hzf7m78mrdmpd.png)

Then we run the command

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7d3cxk1xmspo2izf02ai.png)

For other build tools like Maven,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0yyii1d10b8syof8m6aq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mbeqmp69d82q9l5zphn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rarwox1hmsehuoegl99h.png)


That was it for this blog, check the other part from [here](https://dev.to/mitul3737/devops-prerequisite-part-3-application-basics-nodejs-python-50e1)

<img src="https://media.giphy.com/media/26ufdipQqU2lhNA4g/giphy.gif">