top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Let’s see JAVA from different perspective!


Why Java?

Java is a high-level, compiled, strongly typed object-oriented programming (OOP) language. The advantages of Java are many: it is platform independent, has a C-language inspired syntax, provides automatic memory management, has an extensive built-in runtime library, is supported by the Oracle corporation, and has a rich open source community.

Who invented Java?

Java was invented at Sun Microsystems by a team led by James Gosling. It was first released in 1995.

Who currently maintains Java?

Java is currently owned and maintained by the Oracle Corporation, which acquired Java when it acquired Sun Microsystems in 2010.

What is "object-oriented"?

When we say Java is object-oriented, we mean that it has the constructs of classes and objects built into the language. It also allows us to use various principles of object-oriented programming, which are covered in a separate module. An object in code can represent a real-world entity, or a conceptual entity.

Classes are the blueprints for how to create objects that contain a certain state - which is represented by fields (variables) - and behavior - which is defined via methods.

Objects are instances of class definitions. However, Java is not 100% object-oriented because it still has primitive values

What is the Java Language Specification?

It is the syntax and semantics of Java. Analogies to syntax and semantic errors in the English language follow:

  • "Bob are playing." is a syntax (Grammatical) error because the verb "is" should be used instead of "are."

  • "My freezer just rode a bicycle to Tampa." is a semantic (Meaning) error. Although the syntax is correct, the sentence does not make sense.

Real World Application for the Language Overview topic

• Desktop GUI Applications of Java Desktop applications can be easily developed using Java.

• We use APIs like AWT, Swing, JavaFX to build these applications.

• Examples of desktop GUI applications are Acrobat Reader, ThinkFree, Media Player, Antiviruses, etc.

• Mobile Applications of Java

• A mobile application is an application created for mobile phones and tablets. In today’s era, the majority

of phones and smart devices have Android OS and Android development is not possible without Java.

• Examples of mobile applications are Photo and video gallery apps, Simple Calendar, Netflix,

Tinder, QRReader, Google Earth, Uber, etc.

• Enterprise Applications of Java

• An enterprise application is a large software system which operates in a corporate environment, to satisfy

the needs of an organization, rather than of individual users.

• Examples of enterprise applications are Business corporations, schools, banks, ERP

(Enterprise Resource Planning) and CRM (Customer Resource Management) systems, clubs,

charities, governments, interest-based user groups, etc.

• Scientific Applications of Java

• A scientific application is an application that affects real-world activities using mathematics. Java

supports the development of scientific applications, because of its powerful features.

• Examples of scientific applications are applications related to research, science, medical science, space,

aeronautics, etc.

• Web-based Applications of Java

• A web application is a client-server program that is delivered on the Internet through a browser interface

• Examples of web-based applications are irctc.co.in, online forms, shopping carts, Gmail, Google Sheets,

Google Slides and many more.

• Embedded Systems

• An embedded system, also known as an integrated system, is a combination of many small computing units

that assemble together to perform dedicated functions for the larger systems.

• Embedded systems are present everywhere. Don’t believe it? Most of us use them without knowing. For

example, a motor system, entertainment and multimedia in a car, E-commerce, wireless communication,

mobile computing and networking use an embedded system.

• Embedded systems use Java for development. Originally, Java was designed for the purpose of developing

embedded systems.

• SIM (Subscriber Identity Module) cards in our phones have been running a variant of the JVM (Java Card) for

nearly 20 years.

• Big Data Technologies

• The term big data is defined as “extremely large and complex datasets that may be analyzed to extract

patterns, trends, and useful information. It is one of the most popular topics in the world of the latest

technology.

• Java is the perspective of big data. Today, many developers are switching their careers to Big Data

Technology.

• Hadoop and other big data technologies are also using Java in one way or the other. For example, Apache’s

Java-based HBase and Accumulo (open source), and ElasticSearch as well.

• Distributed Applications of Java

• A distributed application is an application or software that executes or runs on multiple computers within a

network.

• RMI (Remote Procedure Invocation) and CORBA (Common Object Request Broker Architecture) are the APIs

to develop distributed applications.

• Cloud-based Applications of Java

• Cloud computing means on-demand delivery of IT resources via the Internet, including storage, servers,

databases, networking, and software with a pay-as-you-go pricing model.

• It provides a solution for IT infrastructure at a low cost, as we can save files on remote databases and

retrieve them on demand.

• Java has long been the programming language that provides a structure for web applications, and now it

has reached cloud applications, because of its distributed nature.

• There are many Java cloud development tools. For example, Oracle Java cloud service provides a platform

to develop and configure the Oracle servers

• Web Servers and Application Servers

• A web server is a computer program that uses HTTP (Hypertext Transfer Protocol) and other protocols, to

store, process, and respond to client requests made over WWW (World Wide Web). A web server is a system

that runs websites and delivers web pages to users.

• An application server (or app server) is a software framework that stores the business logic for an

application program and handles all operations between the client-end and the back-end of organizations.

  • Software Tools

    • A software tool is a set of computer programs that developers use to develop, analyze, maintain, debug, or support other applications and programs. Many developers use Java to write and develop useful software tools.

    • Examples of software tools are Eclipse, IntelliJ Idea, and NetBeans IDE.

    • Gaming Applications

    • Java proves to be one of the best platforms for developing 2-Dimensional games. Today almost every person has an Android phone that has Android games in it. Android games cannot be built without Java.

    • Android platform.Android games use Java as a primary language because Java supports the Dalvik Virtual Machine (DVM) which is specially designed to run on the

Conclusion of the Language Overview

  • Java is a high-level, compiled, strongly typed object-oriented programming (OOP) language.

  • Java advantages include platform independence, C-language-inspired syntax, automatic memory management, an extensive built-in runtime library, support from the Oracle corporation, and a rich open-source community.

  • Classes are the blueprints for how to create objects. They are characterized by state and behavior.

  • Objects are instances of class definitions.

  • However, Java is not 100% object-oriented because it still has primitive values

  • The Java Language Specification involves

    • Syntax (Grammar)

    • Semantics (Meaning)

  • The Java Application Programming Interface (API) provides the programmer with a built-in library of functions that the programmer does not have to re-create.

  • The different editions of Java are Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME).


What is the role of the Method in JAVA


What is a Method?

A method is a block of reusable code that can be invoked as many times as we want.

Parts of a Method

There are 3 minimum required parts we need to know to write a method:

  • Method name: we give our method a unique name so we can identify it from other methods

  • Method parameters: variables passed inside of the parenthesis of the method which we are able to utilize inside of our method. These values are given to us by the entity that invokes the method.

  • Return type: The datatype that we are going to return from the method

Let's identify the 3 parts above in the "addNumbers" written below:

int addNumbers(int num1, int num2){ return num1 + num2; }

  • The method name of this specific method is the text right before the parenthesis. So the method name of this specific method is "addNumbers".

  • The method parameters in the above method are num1 and num2. The entity that invoked this method gave us those two values so we can add them together inside of the method.

  • The return type of the above method is an "int". This means that you need to return a whole-number value before the method ends. If you don't need to return anything from a method, you can utilize the "void" keyword in the return type instead.

How do we invoke a method?

Let's say we wanted to call our newly created "addNumbers" method. We can do that as shown below:

public class Main { public static void main(String[] args){ addNumbers(1,3); } }

In the example above, we are invoking the "addNumbers" method from our main method. All we needed to do was type out the method name and provide the values required to the parameter list. In the above example we aren't storing the result of the method however we can do this by assigning the method to a variable.

NOTE: The variable datatype and the return type of the method must be the same if you are going to store the value into a variable

public class Main { public static void main(String[] args){ int sum = addNumbers(1,3); } }

In the above example, we are storing the result of the addNumbers method into the variable sum. In this case, since we passed the values 1 and 3 to the method, the value in the variable sum will be 4.

Entities of Java

To really get a head start in understanding java, we need to be able to identify the 3 core entities that you will see in any java file.

  • Classes: The blueprint for creating objects

  • Variables: Entities that allow us to store data

  • Methods: Blocks of reusable code that can be invoked again and again

Class

A class is a blueprint for creating objects. Objects in java are meant to represent real world objects. Since most objects in the real world have state or behavior, there is a way to represent those in java classes as well. Any line of code that you write in java has to be within a class since it is an object-oriented programming language.

class Dog { }

In the above syntax we created a class called Dog. The open curly brace represents the beginning of class Dog and the closing curly brace represents the end of class Dog. Any code within those two curly braces is considered to be “within” class Dog.

State and Behavior

We stated in the previous section that objects can have state and behavior. This means that we need a way to define these attributes within a class.

How do we represent State?

When we talk about objects having state in java, this refers to a construct called variables. A variable is a way to store data within code. Let’s give our Dog class a variable called age.

class Dog { int age; }

We just added one line of code within our Dog class. We can identify this because the variable age is in between the open and closed curly brace within the class. The word int in java is a primitive datatype. We don't need to know what this means right now. Just know that java is a strongly-typed language. This means that all variables in java must define what type of data we can store into that variable. The word age is just the label we decided to give that variable.

How do we represent Behavior?

When we talk about objects having behavior, this refers to a construct in code called a method. A method is a block of code that we can invoke again and again. Methods in java usually represent some sort of action. Since a common behavior of a dog is to bark, lets write a method to in our Dog class that represents barking.

class Dog { int age; String bark() { return "WOOF!"; } }

We can identify what a method looks like by its syntax. Methods always have parenthesis after the method name. No other construct in java does this. In the above example, the method name is bark which then has the parenthesis followed by curly braces which represents the opening and closing of the method. The datatype String before the method name represents what datatype we are expecting to return from this method.

Note: If your method does not need to return any data, we can put the keyword void in replace of String.

What’s the point?

Alright so we created our first class. What’s the point of creating this class? The class itself isn't representing the “real world object” so why did we do this? Again, the point of classes is to define how to create an object. It is the “blueprint”. Now that we created a class, we can write statements like this...

Dog max = new Dog();

The above creates a dog object with the variable name “max” and since we defined what a dog object can do, max has the behavior of barking!

String dogBarking = max.bark(); System.out.println(dogBarking);

This invokes the bark method in the dog object which will return the String “WOOF!”. We can then print that to the console if desired.

Takeaways

Classes are blueprints for creating objects in java. Classes can have variables and methods within them. Be able to identify classes, variables and methods in code. The first lab will test your knowledge regarding this.

Let’s see for the “JVM-JRE-JDK” topic.

Programs that are written in Java are executed utilizing the Java Virtual Machine (JVM). The JVM is a special program that knows how to execute the programs that you write in Java

The Java Virtual Machine is able to run our code because it runs our compiled bytecode. This is unique as it does this in a virtual environment that is the same across every platform. However, the JVM that you use is specific to your operating system.

In order to run our code it has something in it called the Just-In-Time Compiler (JIT). The JIT turns your bytecode into machine code, in most instances on a line-by-line basis.

Thus, programs in Java are technically compiled twice.

In order to run Java code, you also need a Java Runtime Environment (JRE), which contains all the runtime libraries that your code will be calling and using. The JRE contains the JVM within it, so if you want to run a Java program, all you need to install is the JRE.

But how do we actually compile the Java code that we write down to bytecode that the JVM will understand? For that, you need a JDK - Java Development Kit, which provides developer tools like a compiler, debugger, documentation tools, and other command-line utilities. The JDK also has a JRE inside of it, so if you install a JDK you can compile your Java code as well as execute it.

This diagram illustrates how these components work together:


Step 1: The developer would write the source code in which the JDK would compile the source code into bytecode.

Step 2: The JRE processes the bytecode line by line using the JIT.

Step 3: Finally the JIT compiler turns the bytecode into machine code line by line.

Phases of the Process

  • Compile time: This is when source code is converted at one time to byte code.

  • Runtime: This is when Java uses the JIT. The bytecode that the developer wrote is then turned into instructions for the JVM to execute.

Recap

The JDK contains tools for Java development as well as JRE, which actually executes the Java bytecode and runs it on the specific operating system on which it is installed.

Implementation for the “JVM-JRE-JDK”

Here we will download, install, and verify the Java Development Kit (JDK) for Windows.

· Step 1: Download JDK

· Step 2: Install JDK

  • Run the downloaded installer. Accept the defaults and follow the screen instructions to complete the installation.

· Step 3: Set the PATH environment variable

· General Information

  • The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window.

  • The PATH system variable can be set using System Utility in control panel on Windows, or in your shell's startup file on Linux and Solaris.

  • Making changes to the system PATH variable is typically not necessary for computers running Windows or Mac OS X.

· Windows

  • In Search, search for and then select: System (Control Panel)

  • Click the Advanced system settings link.

  • Click Environment Variables. In the section System Variables find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

  • Reopen Command prompt window, and run your java code.

· Mac OS X

  • To run a different version of Java, either specify the full path, or use the java_home tool:

·       % /usr/libexec/java_home -v 1.8.0_73 --exec javac -version

· Solaris and Linux

  • To find out if the path is properly set:

  • In a terminal window, enter:

·       % java -version
  • This will print the version of the java tool, if it can find it.

  • If the version is old or you get the error java: Command not found then the path is not properly set.

  • Determine which java executable is the first one found in your PATH

  • In a terminal window, enter:

·       % which java
  • Set the PATH permanently

    • To set the path permanently, set the path in your startup file.

    • Bash Shell

      • Edit the startup file (~/.bashrc)

      • Modify PATH variable

·    PATH=/usr/local/jdk1.8.0/bin:$PATH
·    export PATH
  • Save and close the file

  • Load the startup file

·    % . /.profile
  • Verify that the path is set by repeating the java command

·    % java -version
  • C Shell (csh)

    • Edit the startup file (~/.cshrc)

    • Set Path

·    set path=(/usr/local/jdk1.8.0/bin $path)
  • Save and close the file

  • Load the startup file

·    % source ~/.cshrc
  • Verify that the path is set by repeating the java command

% java -version

Conclusion for the “JVM-JRE-JDK” topic.

  • A Java Development Kit (JDK) is used to create Java code.

  • The Java code is then compiled into bytecode for a particular Java Runtime Environment (JRE)

  • The JRE runs the bytecode in a Java Virtual Machine (JVM) which is specific to the machine and operating system.

  • Since every machine can implement its own JREs and JVMs, Java source code does not have to be rewritten to be machine-specific. This is known as Write Once, Run Anywhere (WORA).

Happy reading!!!

25 views0 comments

Recent Posts

See All
bottom of page