Breaking News

DIPLOMA PROJECT INTRODUCTION TO JAVA


                         INTRODUCTION TO JAVA


                             
A small history of Java
 Java is a programming language created by James Gosling from Sun Microsystems (Sun) in 1991. The target of Java is to write a program once and then run this program on multiple operating systems. The first publicly available version of Java (Java 1.0) was released in 1995. Sun Microsystems was acquired by the Oracle Corporation in 2010. Oracle has now the steermanship for Java. In 2006 Sun started to make Java available under the GNU General Public License (GPL). Oracle continues this project called OpenJDK.
Over time new enhanced versions of Java have been released. The current version of Java is Java 1.8 which is also known as Java 8.
Java is defined by a specification and consists of a programming language, a compiler, core libraries and a runtime (Java virtual machine) The Java runtime allows software developers to write program code in other languages than the Java programming language which still runs on the Java virtual machine. The Java platform is usually associated with the Java virtual machineand the Java core libraries.
The Java language was designed with the following properties:
           Platform independent: Java programs use the Java virtual machine as abstraction and do not access the operating system directly. This makes Java programs highly portable. A Java program (which is standard-compliant and follows certain rules) can run unmodified on all supported platforms, e.g., Windows or Linux.
           Object-orientated programming language: Except the primitive data types, all elements in Java are objects.
           Strongly-typed programming language: Java is strongly-typed, e.g., the types of the used variables must be pre-defined and conversion to other objects is relatively strict, e.g., must be done in most cases by the programmer.
           Interpreted and compiled language: Java source code is transferred into the bytecode format which does not depend on the target platform. These bytecode instructions will be interpreted by the Java Virtual machine (JVM). The JVM contains a so called Hotspot-Compiler which translates performance critical bytecode instructions into native code instructions.
           Automatic memory management: Java manages the memory allocation and de-allocation for creating new objects. The program does not have direct access to the memory. The so-called garbage collector automatically deletes objects to which no active pointer exists.
The Java syntax is similar to C++. Java is case-sensitive, e.g., variables called myValue andmyvalue are treated as different variables.
Hello world Java program
// a small Java program
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
Java virtual machine
The Java virtual machine (JVM) is a software implementation of a computer that executes programs like a real machine.
The Java virtual machine is written specifically for a specific operating system, e.g., for Linux a special implementation is required as well as for Windows
Java programs are compiled by the Java compiler into bytecode. The Java virtual machine interprets this bytecode and executes the Java program.



Features of Java
There is given many features of java. They are also known as java buzzwords. The Java Features given below are simple and easy to understand.

1.         Simple
2.         Object-Oriented
3.         Portable
4.         Platform independent
5.         Secured
6.         Robust
7.         Architecture neutral
8.         Dynamic
9.         Interpreted
10.       High Performance
11.       Multithreaded
12.       Distributed.
1.Simple
According to Sun, Java language is simple because:
      syntax is based on C++ (so easier for programmers to learn it after C++).
      removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading etc.
      No need to remove unreferenced objects because there is Automatic Garbage Collection in java.

2.Object-oriented
Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behaviour.
Object-oriented programming(OOPs) is a methodology that simplify software development and maintenance by providing some rules.
Basic concepts of OOPs are:
1.         Object
2.         Class
3.         Inheritance
4.         Polymorphism
5.         Abstraction
6.         Encapsulation

3.Platform Independent
 A platform is the hardware or software environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides software-based platform.
The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on the top of other hardware-based platforms. It has two components:
1.         Runtime Environment
2.         API(Application Programming Interface)
Java code can be run on multiple platforms e.g. Windows, Linux, Sun Solaris, Mac/OS etc. Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent code because it can be run on multiple platforms i.e. Write Once and Run Anywhere(WORA).
4.Secured
Java is secured because:
o          No explicit pointer
o          Java Programs run inside virtual machine sandbox

o          Classloader: adds security by separating the package for the classes of the local file system from those that are imported from network sources.
o          Bytecode Verifier: checks the code fragments for illegal code that can violate access right to objects.
o          Security Manager: determines what resources a class can access such as reading and writing to the local disk.
These security are provided by java language. Some security can also be provided by application developer through SSL, JAAS, Cryptography etc.

5.Robust
Robust simply means strong. Java uses strong memory management. There are lack of pointers that avoids security problem. There is automatic garbage collection in java. There is exception handling and type checking mechanism in java. All these points makes java robust.
6.Architecture-neutral
There is no implementation dependent features e.g. size of primitive types is fixed.
In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64-bit architecture. But in java, it occupies 4 bytes of memory for both 32 and 64 bit architecture
Portable
We may carry the java bytecode to any platform.
7.High-performance
Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++)
8.Distributed
We can create distributed applications in java. RMI and EJB are used for creating distributed applications. We may access files by calling the methods from any machine on the internet
9.Multi-threaded
A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications etc.
Java™ has significant advantages over other languages and environments that make it suitable for just about any programming task.
The advantages of Java are as follows:
           Java is easy to learn.
Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages.
           Java is object-oriented.
This allows you to create modular programs and reusable code.
           Java is platform-independent.
One of the most significant advantages of Java is its ability to move easily from one computer system to another. The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels.
Because of Java's robustness, ease of use, cross-platform capabilities and security features, it has become a language of choice for providing worldwide Internet solutions.
Introduction to the ATM system:
  Automated Teller Machine enables the clients of a bank to have access to their account without going to the bank. This is achieved only by development the application usingonline concepts. When the product is implemented, the user who uses this product will be able to see allthe information and services provided by the ATM, when he enters the necessary optionand arguments. The product also provides services like request for cheques, depositcash and other advanced requirement of the user. The data is stored in the database andis retrieved whenever necessary. The implementation needs ATM machine hardware tooperate or similar simulated conditions can also be used to successfully use thedeveloped product.To develop this ATM system the entire operation has been divided into the  following step:1.
 verification process2.
 language, service and account selection3.
 Banking services4.
 Transactions5.

Special servicesThe program is designed in such a way that the user has to card and pin number. Once verified, he is provided a menu and he/she had to enter the option provided in themenu. For example, when the user wants to view the list of payment history thanhe/she had to enter the option for payment history provided in the main menu. Whenthe option is entered alone with the respective argument, then the payment history isdisplayed on the screen.The user also must be given option to browse through the pages like previous page, nextpage, etc. The user may experience a delay in retrieving or viewing the data, when thereare many users logged on to the same bank branch system.
 Need for the ATM system:
 Millions of times per day around the globe people are instantly withdrawing money atautomatic teller machines (ATMs). Given the fast-pace of the world today, it is notsurprising that the demand for access to quick cash is so immense. The power of ATMs

Java Program to Display the ATM Transaction
This is a Java Program to Display the ATM Transaction.
The user will choose from any one of the available options as input. Different cases using switch case have been provided for different operations like withdraw, deposit and check balance.
Here is the source code of the Java Program to Display the ATM Transaction. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner; 
public class ATM_Transaction
{
  public static void main(String args[] )
{
int balance = 5000, withdraw, deposit;
Scanner s = new Scanner(System.in);
while(true)
{
System.out.println("Automated Teller Machine");
System.out.println("Choose 1 for Withdraw");
System.out.println("Choose 2 for Deposit");
 System.out.println("Choose 3 for Check Balance");
System.out.println("Choose 4 for EXIT");
System.out.print("Choose the operation you want to perform:");
int n = s.nextInt();
switch(n)
{
case 1:
System.out.print("Enter money to be withdrawn:");
withdraw = s.nextInt();
if(balance >= withdraw)
{
balance = balance - withdraw;
System.out.println("Please collect your money");
}
else
{
System.out.println("Insufficient Balance");
}
System.out.println("");
break;
case 2:
System.out.print("Enter money to be deposited:");
deposit = s.nextInt();
balance = balance + deposit;
System.out.println("Your Money has been successfully depsited");
System.out.println("");
break;

case 3:
System.out.println("Balance : "+balance);
System.out.println("");
break;

case 4:
System.exit(0);
}
}
}
}











Output:
$ javac ATM_Transaction.java
$ java ATM_Transaction
 Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:1
Enter money to be withdrawn:2000
Please collect your money
 Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXITChoose the operation you want to perform:3
Balance : 3000
Automated Teller Machine
Choose 1 for Withdrawl
Choose 2 for Deposit
Choose 3 for Check BalanceChoose 4 for EXIT
Choose the operation you want to perform:

No comments