Java Programming MCA-301 Rajeev Gupta, MMICTBM (MCA), MMU, Mullana 1
Java Programming Java is a general purpose Object-Oriented Programming Language It is intended to let application developers "Write Once, Run Anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. It was conceived by Bill Joy, James Gosling, Patrick Naughton, Chris Warth, Ed Frank and Mike Sheridan at Sun Microsystems Inc. in 1991. The original impetus for Java was not the Internet. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. The primary motivation was the need for a platform independent (Architectural-Neutral) language that could be used to create Software to be embedded in various consumer electronic devices, such as Microwave Ovens and Remote Controls. The language was initially called Oak after an oak tree that stood outside Gosling's office; it went by the name Green later, and was later renamed Java. Internet Version of C++ 2
History of Java 1990 - Sun Microsystems decided to develop special s/w that could be used to manipulate consumer electronic devices - A team of Sun Microsystems programmers headed by James Gosling was formed to undertake this task. 1991 - Team announced a new language named Oak 1992 - Team ( known as Green Project team by Sun), demonstrated the application of their new language. 1993 - WWW appeared on the Internet & transformed the text-based Internet into a graphical-rich environment. - Team came up with the idea of developing web applets. 1994 - The team developed a Web browser called HotJava to locate and run applet programs on Internet. 1995 - Oak renamed as Java 1996 - Java established itself not only as a leader for Internet programming but also as a general purpose, Object oriented programming language. 3
Major Release Versions of Java Major release versions of Java, along with their release dates: JDK 1.0 (January 23, 1996) JDK 1.1 (February 19, 1997) J2SE 1.2 (December 8, 1998) J2SE 1.3 (May 8, 2000) J2SE 1.4 (February 6, 2002) J2SE 5.0 (September 30, 2004) Java SE 6 (December 11, 2006) Java SE 7 (July 28, 2011) Java SE 8 (March 18, 2014, updated version on October 14, 2014) 4
5
Java Buzzwords / Features of Java Compiled & Interpreted Platform-Independent / Architectural Neutral Portable Simple, Familiar and Small Secure Object-oriented Robust Multi-threaded & Interactive Automatic Memory Management High Performance Distributed Dynamic Binding Extensible Write Once, Run Anywhere Network-Centric Programming Programmer Efficiency and Time-to-Market 6
Java Program Structure 7
Java: Data Types There are two data types available in Java: Primitive / Basic Data Types Reference / Object Data Types Primitive data types are predefined by the language and named by a keyword. Data Type Memory Space Range Default Value byte 8-bits -128 to +127 0 short 2 bytes -32,768 to +32,767 0 int 4 bytes -2147483648 to + 2147483647 0 long 8 bytes -2 63 to 2 63-1 (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 ) float 4 bytes 3.4e 038 to 3.4e+038 0.0f double 8 bytes 1.7e 308 to 1.7e+308 0.0d boolean 1 bit True / False false Char 2 bytes '\u0000' (or 0) to '\uffff' (or 65,535 ) \u0000' [null] 0L 8
Java: Data Types Reference Data Types: Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. Class objects, and various type of array variables come under reference data type. Default value of any reference variable is null. A reference variable can be used to refer to any object of the declared type or any compatible type. Example: Scanner s = new Scanner(System.in); 9
Java: Operators Operator is an entity, which perform some operations on operands. We categorized the operator in two categories: According to their Nature. According to their Functionality. According to their Nature: Operator Description Example Unary Operator which take single operand ++, --, - (unary minus) Binary Operator which take two operands +, -, >, ==, && etc. Ternary Operator which take three operands?, : 10
Java: Operators According to their Functionality: Operator Arithmetic +, -, *, /, % Relational >, >=, <, <=,!=, == Increment/Decement ++, -- Logical &&,,! Conditional?, : Assignment =, *=, +=, -=, /=, &= etc. Bitwise ~, &,!, ^ Bit-Shift >>, <<, >>> Other/Special (), [ ],., new, instanceof, (type) 11