Listen to your teachers when they tell you WHAT to do. But more importantly, think about it later and ask yourself WHY they told you to do it.
--Your friends at LectureNotes

Note for Core Java - cjava By Bholendra Singh

  • Core Java - cjava
  • Note
  • Sikkim manipal university - SMIT
  • Computer Science Engineering
  • 3 Topics
  • 135 Offline Downloads
  • Uploaded 1 year ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

Java Programming Unit 1 Unit 1 Getting Started Structure 1.1 Introduction Objectives Self Assessment Questions 1.2 Features of Java 1.3 Java Magic: Byte Code 1.4 Summary 1.5 Terminal Questions 1.1 Introduction Although the Java programming language is usually associated with the World Wide Web, its origin predates the web. Java began life as the programming language Oak. Oak was developed by the members of the Green Project, which included Patrick Naughton, Mike Sheridan and James Gosling, a group formed in 1991 to create products for the smart electronics market. The team decided that the existing programming languages were not well suited for use in consumer electronics. The chief programmer of sun Microsystems, James Gosling, was given the task of creating the software for controlling consumer electronic devices. The team wanted a fundamentally new way of computing, based on the power of networks, and wanted the same software to run on different kinds of computer, consumer gadgets and other devices. Patenting issues gave a new name to Oak – Java. During that period, Mosaic, the first graphical browser, was released. Nonprogrammers started accessing the World Wide Web and the Web grew dramatically. People with different types of machines and operating systems Sikkim Manipal University Page No. 1

Text from page-2

Java Programming Unit 1 started accessing the applications available on the web. Members of the Oak team realized that Java would provide the required cross-platform independence that is, independence from the hardware, the network, and the operating system. Very soon, Java became an integral part of the web. Java software works just about everywhere, from the smallest devices to supercomputer. Java technology components (programs) do not depend on the kind of computer, telephone, television, or operating system they run on. They work on any kind of compatible device that supports the Java platform. Objectives In this chapter, you will learn about the:  History of Java  Features of Java  Types of Java programs. 1.2 Features of Java Java is a simple language that can be learned easily, even if you have just started programming. A Java programmer need not know the internal of Java. The syntax of Java is similar to C++. Unlike C++, in which the programmer handles memory manipulation, Java handles the required memory manipulations, and thus prevents errors that arise due to improper memory usage. Java defines data as objects with methods that support the objects. Java is purely object-oriented and provides abstraction, encapsulation, inheritance and polymorphism. Even the most basic program has a class. Any code that you write in Java is inside a class. Java is tuned of Web. Java programs can access data across the Web as easily as they access data from a local system. You can build distributed applications in Java that use resources from any other networked computer. Sikkim Manipal University Page No. 2

Text from page-3

Java Programming Unit 1 Java is both interpreted and compiled. The code is complied to a bytecode that is binary and platform independent. When the program has to be executed, the code is fetched into the memory and interpreted on the user’s machine. As an interpreted language, Java has simple syntax. When you compile a piece of code, all the errors are listed together. You can execute only when all the errors are rectified. An interpreter, on the other hand, verifies the code and executes it line by line. Only when the execution reaches the statement with error is the error reported. This makes it easy for a programmer to debug the code. The drawback is that this takes more time than compilation. Compilation is the process of converting the code that you type, into a language that the computer understands- machine language. When you compile a program using a compiler, the compiler checks for syntactic errors in code and list all the errors on the screen. You have to rectify the errors and recompile the program to get the machine language code. The Java compiler compiles the code to a bytecode that is understood by the Java environment. Bytecode is the result of compiling a Java program. You can execute this code on any platform. In other words, due to the bytecode compilation process and interpretation by a browser, Java programs can be executed on a variety of hardware and operating systems. The only requirement is that the system should have a Java-enabled Internet browser. The Java interpreter can execute Java code directly on any machine on which a Java interpreter has been installed. Thanks to bytecode, a Java program can run on any machine that has a Java interpreter. The bytecode supports connection to multiple databases. Java code is portable. Therefore, other people can use the programs that Sikkim Manipal University Page No. 3

Text from page-4

Java Programming Unit 1 you write Java event if they have different machines with different operating systems. Java forces you to handle unexpected errors. This ensures that Java programs are robust (reliable), and bug free and do not crash. Due to strong type-checking done by Java on the user’s machine, any changes to the program are tagged as error and the program will not execute. Java is, therefore, secure. Java is faster than other interpreter-based language like BASIC since it is compiled and interpreted. Multithreading is the ability of an application to perform multiple tasks at the same time. You can create multithreading programs using Java. The core of Java is also multithreaded. The following definition of Java by Sun Microsystems lists all the features of Java. ‘Java is a simple, Object-oriented, distributed, interpreted, robust, secure, architecture neural, portable, high-performance, multithreaded, and dynamic language’. Self Assessment Questions 1. What are the features of Java? 2. ___________ is the ability of an application to perform multiple tasks at the same time. 3. Java is tuned of _________. 1.3 Java Magic: Byte Code The key that allows Java to solve both the security and the portability problems just described is that the output of a Java compiler is not Sikkim Manipal University Page No. 4

Lecture Notes