Programming in Java (Cspe-02)
Total Page:16
File Type:pdf, Size:1020Kb
Master of Science(Cyber Security) (MSCS) PROGRAMMING IN JAVA (CSPE-02) Block 1 INTRODUCTION TO JAVA Unit – 1: Overview of Java Unit – 2: Key Features of Java Unit – 3: Operators Unit – 4: Control Statements Master of Science(Cyber Security) (MSCS) EXPERT COMMITTEE Dr. P.K Behera (Chairman) Reader in Computer Science Utkal University Bhubaneswar, Odisha Dr.J.RMohanty (Member) Professor and HOD KIIT University Bhubaneswar, Odisha Sri PabitranandaPattnaik (Member) Scientist-E, NIC Bhubaneswar, Odisha Sri Malaya Kumar Das (Member) Scientist-E, NIC Bhubaneswar, Odisha Dr. Bhagirathi Nayak (Member) Professor and Head (IT & System) Sri Sri University, Bhubaneswar,Odisha Dr.Manoranjan Pradhan (Member) Professor and Head (IT & System) G.I.T.A Bhubaneswar, Odisha Sri Chandrakant Mallick (Convener) Consultant (Academic) School of Computer and Information Science Odisha State Open University Sambalpur, Odisha Master of Science(Cyber Security) (MSCS) Course Writers Sunita Padhi Bijay Kumar Paikaray Centurion University of Technology and Management, Odisha Editor Aseem Kumar Patel Academic Consultant Odisha State Open University, Sambalpur, Odisha Material Production Dr. Jayanta Kar Sharma Registrar Odisha State Open University, Sambalpur © OSOU, 2017. Promoting Use and Contribution of Open Education Resources is made available under a Creative Commons Attribution- ShareAlike4.0http://creativecommons.org/licences/by-sa/4.0 Printers by : Sri Mandir Publication, Sahid Nagar, Bhubaneswar UNIT-1 Overview of Java Unit Structure 1.0 Introduction 1.1 Learning Objectives 1.2 History of Java 1.3 Edition of Java 1.4 What is Java? 1.5 Why learn Java? 1.6 Languages and Paradigms 1.7 The Basics of Java 1.8 Features of Java 1.9 OOPS Concepts 1.9.1 OOPS (Object Oriented Programming System) 1.10 Evolution of Java 1.11 How Java program works 1.12 Major Different Between C++ and JAVA 1.13 Java and Internet 1.14 Java and World Wide Web 1.15 Java Support System 1.16 Java Environment 1.17 Components of JDK 1.18 Components of API 1.19 Let Us Sum Up 1.20 Self-Assessment Questions 1.21 Model Questions 1.22 References & Suggested Readings Page 1 1.0 Introduction Java is a general purpose, simple, high level, platform independent, purely object oriented programming language that combines a well-designed language with dominant features which makes java Robust and secure languages. In addition to the core language components, Java software distributions include many software libraries for graph ical user interface (GUI), database, network and programming. In this Block, we will emphasis on basic features of Java language and got familiar with JVM, JDK, JRE and API. Java is a purely object-oriented programming language. The main objective of this is that in order to write a java programs we have to use object-oriented concept like class and object etc. 1.1 Learning Objectives After learning this unit you should be able to Know the history of Java. Understand what Java is and why learn java. Know why java is easy to learn. Study different Programming Paradigms. Know the basics of Java and its features. Study OOPS Concepts. Differentiate C++ and JAVA. Know the difference between Java and Internet. Know the components of JDK and API. 1.2 History of Java Java programming Language was written by James Gosling along with two other team member (team named as Green Team) at Sun Microsystems, Inc. (US) in 1991. This language was initially designed for small electronics devices and named it “Greentalk” (.gt was the file extension), after that it was called "Oak" but later it was renamed to "Java" in 1995 as Oak was a registered trademark of another company. (James Gosling) Initially, it was an advance model. But, it was fit for internet programming. Later, Java technology as merged by Netscape. Currently, Java is used in web programming, mobile devices, games, embedded device etc. In 1990, Sun Microsystems Inc. got a project to develop an application software for electronics devices that could be managed by remote control. Page 2 They named this project as Stealth Project but later it renamed to Green Project. In 1991, Green Team divide project module and James Gosling took the responsibility to identify the proper programming language for the project and C and C++ was the best choice for the project. But the problem was that these are system dependent language and hence they can’t use it in different processors of embedded devices. So he started developing a new programing language, which was simple and system independent. In 1994, the team started developing a java based Web Browser named HotJava. HotJava was the first Web browser having the potential to execute applets, which are programs that runs dynamically in internet. In 1995, Sun Microsystems Inc. formally announced Java and HotJava. On January 23rd 1996, Sun Microsystems Inc. released the first version of Java i.e. JDK 1.0. Over time new enhanced versions of Java have been released. The current version of Java i.e. OpenJDK 10 was released at 20 March 2018 which is also known as Java 9. Today more than 5 million developers use java and 2 billion devices run java. Thus Java saturated the world. 1.3 Edition of Java There are three editions of Java available. Each has its own use. Editions have had many name changes over the years; the current names of the editions are as follows: Java Standard Edition(JSE) (Core Java) o JSE can be used to develop client-side standalone applications or applets. Java Enterprise Edition(JEE) (Advance Java) o JEE can be used to develop Server-side applications such as java servlets and java server Pages. Java Micro Edition(JME) o JME can be used to develop applications for mobile devices such as cell phones. In 2010 Oracle Corporation takes over the Sun Microsystems. 1.4 What is Java? Java is commonly used to refer to the Java platform, a set of tools allowing for easy cross-platform application development, as well as the Java programming language, which is a general-purpose programming language often used to develop programs for this platform. The important thing about Java is that differentiates it from many other technologies is that it is designed such that code written in Java can be run on any system that a Java virtual machine (JVM) can run on. This concept of write Page 3 once, run anywhere was used as a slogan to promote Java’s cross-platform abilities. Java environments can be found on all sorts of devices, large and small, and therefore a Java developer has more flexibility when it comes to being able to treat code as agnostic to the system on which it runs. The Java programming language itself is an object-oriented language, which is syntactically similar to C++. Unlike some other languages which came before it, which implemented classes but did not require their use, Java programs are always designed with an object-oriented design. While the Java language and the Java virtual machine which runs Java code are closely paired, the two are separate. Code from other languages which is designed specifically for the JVM, like Groovy and Scala, can also run on the Java virtual machine. 1.5 Why Learn Java? From web to mobile, electronic appliances to servers, Java is used everywhere. This highly secure language sits at the heart of world’s most robust systems at present. That’s what keeps Java an evergreen winner in the world of programming languages. There are several reason to learn java but few are 1. Job Opportunity 2. Java is Open Source 3. It is Purely object Oriented 4. Rich API 5. Robust Development Tools 6. Easy to absorb 1.6 Languages and Paradigms One of the characteristics of a language is its support for particular programming paradigms. For example, Smalltalk has direct support for programming in the object-oriented way, so it might be called an object- oriented language. OCaml, Lisp, Scheme, and JavaScript programs tend to make heavy use of passing functions around so they are called “functional languages” despite having variables and many imperative constructs. There are two very important observations here: Very few languages implement a paradigm 100%. When they do, they are pure. It is incredibly rare to have a “pure OOP” language or a “pure functional” language. A lot of languages have a few escapes; for example in OCaml, you will program with functions 90% or more of the time, but if you need state, you can get it. Another example: very few languages implement OOP the way Alan Kay envisioned it. A lot of languages will facilitate programming in one or more Page 4 paradigms. In Scala you can do imperative, object-oriented, and functional programming quite easily. If a language is purposely designed to allow programming in many paradigms is called a multi-paradigm language. If a language only accidentally supports multiple paradigms, we don’t have a special word for that. 1.7 The Basics of Java Java, like C++, shares much of its syntax with the C programming language. If you know how to write statements, including variable declarations and loops, in one of these three languages, then you have a head start in learning the others. However, many other details differ among the languages. In particular, the data types and libraries available are considerably different. Java was developed at Sun Microsystems. It has a useful combination of features that, combined with the fact that it is a member of the C/C++ family, have made it very popular in recent years: • Platform independence: Java is designed to be run using a virtual machine, or VM.