Introduction to Programming with Java 1 Chapter 1

























![First Java Program class Hello { public static void main (String[] args) { System. First Java Program class Hello { public static void main (String[] args) { System.](https://slidetodoc.com/presentation_image_h2/81ef10fdd91a9471ad3b5b007eacc6ed/image-26.jpg)

- Slides: 27

Introduction to Programming with Java 1

Chapter 1 Basics of Java 2

Short History of Java Java was developed by James Ghosling and his team at Sun Microsystems in California in 1991. It took 18 months to develop the first working version. The development of java solves the limitation of C and C++. This language was first called as Oak named after the oak tree that stood outside Ghosling’s office. But the name was already taken, so the team renamed it Java in 1995 Java is the name of hot drinks which is very popular in USA. All java team like this hot drink very much, so they decided to give name of the language as a java. 3

Features of Java 1) Simple Java is easy to learn and its syntax is quite simple, clean and easy to understand. The confusing and ambiguous concepts of C++ are either left out in Java or they have been re-implemented in a cleaner way. Pointers and Operator Overloading are not there in java but were an important part of C++. 4

Conti…. . 2) Object Oriented Java is a true objected-oriented language. Almost everything in Java is an object. All program code and data resides within objects and classes. 3) Platform-independent Unlike other programming languages such as C, C++ etc. which are compiled into platform specific machines. Java is guaranteed to be write-once, run-anywhere language. Java programs can be easily moved from anywhere at anytime. Changes in OS and processors do not force any changes in Java program. 5

Conti…. . On compilation Java program is compiled into byte-code. This byte-code is platform independent and can be run on any machine, plus this byte-code format also provides security. Any machine with Java Runtime Environment(JRE) can run Java Programs. 6

Conti…. . 4) Secure When it comes to security, Java is always the first choice. With java secure features it enables us to develop virus free system. Java program always runs in Java runtime environment with almost null interaction with system OS, hence it is more secure. 5) Multi Threading Java multithreading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multithreading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along. 7

Conti…. . 6) Portable Java Byte code can be carried to any platform. 7) High performance Java performance is impressive due to the use of byte-code and multithreading. 8) Distributed Java is designed as a distributed language for creating applications on networks. Java applications can access remote objects on Internet. 8

How Java is different from C++? Java is a true object oriented language while C++ is basically C with object-oriented extensions. Java has replaced multiple inheritances of classes with a new feature called interface. Java doesn’t support pointers. There are no header files in Java does not support global variables. Every variable and method forms part of a class. Java does not structures and unions. Java supports automatic garbage collection and makes a lot of programming problems vanish. 9

Java Environment This includes a large number of development tools and hundreds of classes and methods. ◦ The development tools are part of JDK(Java Development Kit). ◦ Classes and methods are part of JSL(Java Standard Library). 10

Conti…. . 1) Java Development Kit (JDK) Tools in JDK are used for developing and running Java programs: Sr. no Tool Description 1 appletviewer Enables to view Java applets without actually using a Java-compatible browser. 2 Javac Java compiler, which translates Java source code to byte-code files. 3 Javap Java disassembler, which converts byte-code files into a program description. 4 Javah Produces header files for use with native methods 5 Java It is the launcher for Java applications 6 Javadoc Creates HTML documents from Java source code files. 7 Jar Create and manage Java Archive (JAR) files. 11

Conti…. . 2) Application Programming Interface Java Standard Library or (API) includes hundreds of classes and methods grouped into several packages such as: Sr. no Package Description 1 Language Support Package Required for implementing basic features of Java. 2 Utilities Package Provides utility functions such as date and time functions. 3 Input/Output Package Required for input/output manipulation. 4 Networking Package Enables to communicate with other computers via Internet 5 AWT Package The Abstract Window Tool Kit package contains classes that implement platform-independent GUI. 6 Applet Package Includes a set of classes that allows to create Java applets. 12

JVM Java virtual Machine(JVM) is a virtual Machine that provides runtime environment to execute java byte-code. JVM are most often implemented to run on existing operating system. JVM control execution of every Java program. JVM is distributed with Java class library, a set of standard class library in byte -code. That implements the Java Application Programming Interface (API). 13

14

15

16

17

18

19

20

Setting Java Environment Java is freely available on Oracle's Website. Download the latest version of JDK (Java Development Kit) on your operating system. Install JDK on your machine. Once you have installed Java on your machine you would need to set environment variable to point to correct installation directory. 21

Setting up path for windows OS 1) Right click on my computer and select properties 22

Conti…. . 2) Go to the advanced system settings tab. 23

Conti…. . 3) Click on the Environment Variables button 24

Conti…. . 3) Enter the variable name and variable value as follows 25
![First Java Program class Hello public static void main String args System First Java Program class Hello { public static void main (String[] args) { System.](https://slidetodoc.com/presentation_image_h2/81ef10fdd91a9471ad3b5b007eacc6ed/image-26.jpg)
First Java Program class Hello { public static void main (String[] args) { System. out. println ("Hello World program"); } } 26

Conti…. . Step to compile and execute java program 1) Open a text editor i. e. notepad++ and write the code as above. 2) Save the file as Hello. java. 3) Open the command prompt and go to the directory where you saved your java program. 4) Type javac Hello. java and press enter to compile your code. if there is no error then the command prompt will take you to the next line. 5) Now type java Hello on command prompt to run your program. 6) You will be able to see Hello world program printed on the command prompt. 27