Skip to main content

Hi! I'm Java...

Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a “high-level” language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its “syntax”. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute.



Who Created Java?

In the early nineties, Java was created by a team led by James Gosling for Sun Microsystems. It was originally designed for use on digital mobile devices, such as cell phones. However, when Java 1.0 was released to the public in 1996, its main focus had shifted to use on the Internet. It provided more interactivity with users by giving developers a way to produce animated webpages . Over the years it has evolved as a successful language for use both on and off the Internet. A decade later, it’s still an extremely popular language with over 6.5million developers worldwide.

Why Choose Java?

Java was designed with a few key principles in mind:
  • Easy to Use: The fundamentals of Java came from a programming language called c++. Although c++ is a powerful language, it was felt to be too complex in its syntax, and inadequate for all of Java's requirements. Java built on, and improved the ideas of c++, to provide a programming language that was powerful and simple to use.
  • Reliability: Java needed to reduce the likelihood of fatal errors from programmer mistakes. With this in mind, object-oriented programming was introduced. Once data and its manipulation were packaged together in one place, it increased Java’s robustness.
  • Secure: As Java was originally targeting mobile devices that would be exchanging data over networks, it was built to include a high level of security. Java is probably the most secure programming language to date.
  • Platform Independent: Programs needed to work regardless of the machine they were being executed on. Java was written to be a portable language that doesn't care about the operating system or the hardware of the computer.
The team at Sun Microsystems were successful in combining these key principles, and Java's popularity can be traced to it being a robust, secure, easy to use, and portable language.


What Is Object-Oriented Programming?

To put it simply, object-oriented programming focuses on data before anything else. How data is modeled and manipulated through the use of objects is fundamental to any object-oriented program.

What Are Objects?

If you look around you, you will see objects everywhere. Perhaps right now you are drinking coffee. The coffee mug is an object, the coffee inside the mug is an object, even the coaster it's sitting on is one too. Object-oriented programming realizes that if we're building an application it's likely that we will be trying to represent the real world. This can be done by using objects.
Let's look at an example. Imagine you want to build a Java application to keep track of all your books. The first thing to consider in object-oriented programming is the data the application will be dealing with. What will the data be about? Books.
We've found our first object type - a book. Our first task is to design an object that will let us store and manipulate data about a book. In Java, the design of an object is done by creating a class. For programmers, a class is what a blueprint of a building is to an architect, it lets us define what data is going to be stored in the object, how it can be accessed and modified, and what actions can be performed on it. And, just like a builder can build more than more building using a blueprint, our programs can create more than one object from a class. In Java, each new object that is created is called an instance of the class.

What Is the State of an Object?

Every object has a state. That is, at any point in time it can be described from the data it contains. Let's look at Bob from next door again. Let's say we designed our person class to store the following data about a person: their name, hair color, height, weight, and address. When a new person object is created and stores data about Bob, those properties go together to make Bob's state. For instance today, Bob might have brown hair, be 205 pounds, and live next door. Tomorrow, Bob might have brown hair, be 200 pounds and have moved to a new address across town.
If we update the data in Bob's person object to reflect his new weight and address we have changed the state of the object. In Java, the state of an object is held in fields. In the above example, we would have five fields in the person class; name, hair color, height, weight, and address.

What Is the Behavior of an Object?

Every object has behaviors. That is, an object has a certain set of actions that it can perform. Let's go back to our very first object type – a book. Surely a book doesn't perform any actions? Let's say our book tracking application is being made for a library. There a book has lots of actions, it can be checked out, checked in, reclassified, lost, and so on. In Java, behaviors of an object are written in methods. If a behavior of an object needs to be performed, the corresponding method is called.
Let's go back to the example once more. Our booking tracking application has been adopted by the library and we have defined a check out method in our book class. We have also added a field called borrower to keep track of who has the book. The check out method is written so that it updates the borrower field with the name of the person who has the book. Bob from next door goes to the library and checks out a book. The state of the book object is updated to reflect that Bob now has the book.

What Is Data Encapsulation?

One of the key concepts of object-oriented programming is that to modify an object's state, one of the object's behaviors must be used. Or to put it another way, to modify the data in one of the object's fields, one of its methods must be called. This is called data encapsulation.
By enforcing the idea of data encapsulation on objects we hide the details of how the data is stored. We want objects to be as independent of each other as possible. An object holds data and the ability to manipulate it all in one place. This makes it is easy for us to use that object in more than one Java application. There's no reason why we couldn't take our book class and add it to another application that might also want to hold data about books.


Comments

Post a Comment

Popular posts from this blog

I'm the Server Operating System

Server Operating System A server operating system is software that was especially developed to serve as a platform for running multi-user computer programs, applications that are networked and programs critical to business computing. This type of operating system (OS) often comes bundled with the most common types of applications deployed in the client-server model, a term used to indicate the exchange of information between computers. For example, a hypertext transfer protocol (HTTP) or web server hosts or "holds" the text files, images files and scripts that work together to form a website. When someone connects to the Internet and types in a web address, the server that holds the files of the site delivers or "serves" the requested pages to the client computer or the machine that made the request. Frequently used applications in the client-server model handle operations for sharing files and printers across a network, hosting and serving web pages via the

A Hit Count Using Java Servlet's Session Tracking

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SessionTracker extends HttpServlet {         public void doGet(HttpServletRequest req,HttpServletResponse res)         throws ServletException,IOException         {                res.setContentType("text/html");                PrintWriter out=res.getWriter();                HttpSession session=req.getSession(true);                Integer count=(Integer)session.getValue("tracker.count");                if(count==null)                {                         count=new Integer(1);                }else{                         count=new Integer(count.intValue()+1);                }                session.putValue("tracker.count",count);                out.println("<HTML><BODY><H1>SESSION TRACKING DEMO</H1>");                out.println("You've visited this page "+count+((count.intValue()==1)?" time.":"times."