Table of Contents
Java For Beginners
A Simple Start To Java Programming (Written By A Software Engineer)
Scott Sanderson
Table of Contents
Copyright 2016 by Globalized Healing, LLC - All rights reserved.
Click here to receive incredible ebooks absolutely free!
Introduction
Java, the programming language, was introduced by Sun Microsystems. This work was initiated by James Gosling and the final version of Java was released in the year 1995. However, initially Java was released as a component of the core Sun Microsystem platform for Java called J2SE or Java 1.0. The latest release of Java or J2SE is Java Standard Version 6.
The rising popularity of Java, as a programming platform and language has led to the development of several tools and configurations, which are made keeping Java in mind. For instance, the J2ME and J2EE are two such configurations. The latest versions of Java are called Java SE and Java EE or Java ME instead of J2SE, J2EE and J2ME. The biggest advantage of using the Java platform is the fact that it allows you to run your code at any machine. So, you just need to write your code once and expect it to run everywhere.
As far as the features of Java are concerned, they are as follows:
In Java, everything is an object. Java can be effectively stretched out and extended to unimaginable dimensions since it is focused around the Object model.
- Independent of the platform
Dissimilar to numerous other programming dialects including C and C++, when Java is aggregated, it is not converted into a form, which is particular to any machine. Instead, it is converted into a machine-independent byte code. This byte code is conveyed over the web and deciphered by Virtual Machines or JVM on whichever stage it is generally run.
Java is intended to be not difficult to learn. In the event that you comprehend the essential idea of OOP, Java would not be difficult to ace.
With Java's security framework, it empowers to create frameworks, which are free of viruses and tampering. Public-key encryption is used as the core authentication strategy.
- Independent of Machine Architecture
Java compiler produces an object file format, which is independent of the architecture of the machine. The assembled code can be executed on numerous processors, with the single requirement that they must all have Java runtime framework.
The fact that Java code is machine and platform independent makes it extremely compact. Compiler in Java is composed in ANSI C with a clean conveyability limit, which is a POSIX subset.
Java tries to kill circumstances, which can lead to potential system failures, by stressing chiefly on runtime checking and compile time checking.
- Support for Multithreaded Applications
With Java's multithreaded feature, it is conceivable to compose programs that can do numerous assignments at the same time. This configuration gimmick permits designers to build easily running intelligent applications.
Java byte code is interpreted on the fly to local machine. The advancement methodology is more quick and expository since the interfacing is an incremental and lightweight process.
With the utilization of Just-In-Time compilers, Java enhances the performance of the system.
Java is intended for the conveyed environment of the web.
Java is thought to be more dynamic than C or C++ since it is intended to adjust to an advancing environment. Java projects can convey broad measure of run-time data that can be utilized to check for accesses and respond to the same on run-time.
History of Java
James Gosling started working on the Java programming language in June 1991 for utilization in one of his numerous set-top box ventures. The programming language, at first, was called Oak. This name was kept after an oak tree that remained outside Gosling's office. This name was changed to the name Green and later renamed as Java, from a list of words, randomly picked from the dictionary.
Sun discharged the first open usage as Java 1.0 in 1995. It guaranteed Write Once, Run Anywhere (WORA), giving no-expense run-times on prominent stages. On 13 November 2006, Sun discharged much of Java as free and open source under the terms of the GNU General Public License (GPL). On 8 May 2007, Sun completed the procedure, making the greater part of Java's center code free and open-source, beside a little parcel of code to which Sun did not hold the copyright.
Pre-requisites
In order to run and experiment with the examples given in this book, you shall require a Pentium 200-Mhz machine with at least 64 MB of RAM. You additionally will require the accompanying programming platforms:
- Microsoft Notepad or Any Word Processor
- Java JDK 5
- Linux 7.1 or Windows XP or higher Operating Systems
Java - Basic Syntax
A basic Java program can be broken down into several constructs and elements. Typically, it can be characterized as a collection of objects, which communicate with each other by calling each others routines. The basic definitions of objects and classes are given below:
A class can be described as a blueprint that portrays the practices/expresses all the behaviors and states of its objects.
Objects are characterized by two components namely, methods and attributes or variables. For instance, if you consider the example of a puppy, then it has the following attributes or states: name, color and breed. In addition, it also has the following behaviours, which include woofing, wagging and consuming. Any object is nothing but an instance of a class.
Each object has its set of variables. An object's state is made by the qualities alloted to these variables during program execution.
A method is the definition of a method. Moreover, a class can contain numerous methods. It is in these methods that behaviours like where the rationales are composed, information is controlled and all the activities are executed.
First Java Program:
In order to start with basic basic Java programming, let us look at the standard Hello World program.
public class MyFirstJavaProgram {
public static void main(String []args) {
System.out.println("Say Hello World To The World!");
}
}
As you can see, the program uses a single line of code in the main() function, which prints the statement Hello World!. However, before that can be done, let us look at the steps that you must follow in your quest to execute the file.
- Open any text editor and paste this code in that file.
- Save the file with a .java extension. For example, you can save the file as Sample.java.
- The next step is to to open the command prompt of the system and relocate its reference to the directory in which the file is saved. For instance, if you have saved the file in C:\, then you must take the prompt to the same directory.
- In order to compile the code, you must type the following:
javac Sample.java
- If there are no errors, you will automatically be taken to the next line. You can now execute the code using the following command:
java Sample.java
- You should be able to see the following output on the screen.
Say Hello World To The World!
Basic Syntax
About Java programs, it is paramount to remember the accompanying points.