Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction To Java Programming Lecture No. 1

7,584 views

Published on

What is Java?
Why Java?
Where it is used?
History of Java\
Creation of Java
History of Java Releases
Why sun choose "Oak" name?
Overview of Java
Application of Java
Principles of Java Programming language
Features of Java
How is Java different from C++
How is Java different from C
Basic of Java
Difference between JDK, JRE and JVM
Internal Architecture of JVM
Popular Java Editors
Download Java Development Kit
Installation of JDK
Installation of NetBeans
First Java
Explanation of Print Statement
Error Correction
Internal Details of Java First Program
Java Program Structure
Object and class in Java

Published in: Education
  • Dating direct: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • MADE $30 ON MY FIRST DAY! Being a fresh graduate and having lots of free time, I stumbled upon your site when I was searching for work at home opportunities, good thing I did! Just on my first day of joining I already made $30! Now I'm averaging close to $80 a day just for filling out surveys! ➤➤ http://t.cn/AieX2Loq
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • 7 Ways To Prolong The Life Of Deep Cycle Lead-Acid Batteries.. ◆◆◆ http://t.cn/AiFAb0DL
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sir could you please send me kindly it is very usefull. yasirkhidir3@gmail.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Introduction To Java Programming Lecture No. 1

  1. 1. Introduction To Java Programming Language Lecture No.1 Lecture Slides By Adil Aslam My Email Address is : adilaslam5959@gmail.com
  2. 2. What is Java? • Java is a programming language and a platform. • Java is a high level, robust, secured and object- oriented programming language. • Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own runtime environment (JRE) and API, it is called platform. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  3. 3. Introduction to Java programming language • Today Java programming language is one of the most popular programming language which is used in critical applications like stock market trading system on BSE, banking systems or android mobile application. • Java was developed by James Gosling from Sun Microsystems in 1995 as an object-oriented language for general-purpose business applications and for interactive, Web-based Internet applications. The goal was to provide platform- independent alternative to C++. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  4. 4. Introduction to Java programming language • In other terms it is architecturally neutral, which means that you can use Java to write a program that will run on any platform or device (operating system). • Java program can run on a wide variety of computers because it does not execute instructions on a computer directly. Instead, Java runs on a Java Virtual Machine (JVM). Introduction to Java Programming Language Lecture Slides By Adil Aslam
  5. 5. Why Java? • Java has been tested, refined, extended, and proven by a dedicated community of Java developers, architects and enthusiasts. • Simple Grammar – Java has a very simple grammar familiar to anyone with experience in C and C++ • Portability – These days Java really does run well on all the popular platforms • Speed – The latest JIT compilers for Suns JVM approach the speed of C/C++ code, and in some memory allocation intensive circumstances, exceed it. • Garbage Collection – the programmer doesn’t have to worry about memory (most of the time) • Huge library and developer community support available on Internet. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  6. 6. Where it is used? • According to Sun, 3 billion devices run java. There are many devices where java is currently used. Some of them are as follows: • Desktop Applications such as acrobat reader, media player, antivirus etc. • Web Applications such as irctc.co.in, javatpoint.com etc. • Enterprise Applications such as banking applications. • Mobile • Embedded System • Smart Card • Robotics • Games • etc. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  7. 7. History of Java • Java language developed by company Sun Microsystems and creator is Jamesh Gosling. • Java was developed by James Gosling, Patrick Naughton, Mike Sheridan at Sun Microsystems Inc. in 1991. It took 18 months to develop the first working version. • The initial name was Oak but it was renamed to Java in 1995 as OAK was a registered trademark of another Tech company. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  8. 8. Creation of Java • 1) James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team. • 2) Originally designed for small, embedded systems in electronic appliances like set-top boxes. • 3) Firstly, it was called "Greentalk" by James Gosling and file extension was .gt. • 4) After that, it was called Oak and was developed as a part of the Green project. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  9. 9. History of Java Releases Introduction to Java Programming Language Lecture Slides By Adil Aslam Java Version/ CodeName Release Date Important Features JDK 1.0 (Oak) 23rd Jan 1996 Initial release JDK 1.1 19th Feb 1997 Reflection, JDBC, Inner classes, RMI J2SE 1.2 (Playground) 8th Dec 1998 Collection, JIT, String memory map J2SE 1.3 (Kestrel) 8th May 2000 Java Sound, Java Indexing, JNDI J2SE 1.4 (merlin) 6th Feb 2002 Assert, regex, exception chaining, J2SE 5.0 (Tiger) 30th Sept 2004 Generics, autoboxing, enums Java SE 6.0 (Mustang) 11th Dec 2006 JDBC 4.0, java compiler API, Annotations Java SE 7.0 (Dolphin) 28th July 2011 String in switch-case, Java nio, exception handling new way
  10. 10. History of Java Releases • There are many java versions that has been released. Current stable release of Java is Java SE 8. • JDK Alpha and Beta (1995) • JDK 1.0 (23rd Jan, 1996) • JDK 1.1 (19th Feb, 1997) • J2SE 1.2 (8th Dec, 1998) • J2SE 1.3 (8th May, 2000) • J2SE 1.4 (6th Feb, 2002) • J2SE 5.0 (30th Sep, 2004) • Java SE 6 (11th Dec, 2006) • Java SE 7 (28th July, 2011) • Java SE 8 (18th March, 2014) Introduction to Java Programming Language Lecture Slides By Adil Aslam
  11. 11. Java Version History • A popular interview question in java is “What is new in Java version X?” Is that an intelligent question is debatable. You can find summarized important new features added in each major Java release till now. • Here target is to highlight important features in respective release. Apart from below list of features, every release has enhancements and lots of bug fixes. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  12. 12. Java Version History • Java Version SE 8 • Java 8 was released on 18 March 2014. The code name culture is dropped with Java 8 and so no official code name going forward from Java 8. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  13. 13. Java Version SE 8 • New features included in Java SE 8 • Lambda Expressions • Pipelines and Streams • Date and Time API • Default Methods • Type Annotations • Nashhorn JavaScript Engine • Concurrent Accumulators • Parallel operations • PermGen Error Removed • TLS SNI Introduction to Java Programming Language Lecture Slides By Adil Aslam
  14. 14. Java Version History • Java Version SE 7 • Codename Dolphin and released on July 28, 2011. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  15. 15. Java Version SE 7 • New features included in Java SE 7 • Strings in switch Statement • Type Inference for Generic Instance Creation • Multiple Exception Handling • Support for Dynamic Languages • Try with Resources • Java nio Package • Binary Literals, underscore in literals • Diamond Syntax • Automatic null Handling Introduction to Java Programming Language Lecture Slides By Adil Aslam
  16. 16. Java Version History • Java Version SE 6 • Codename Mustang and released on December 11, 2006. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  17. 17. Java Version SE 6 • New features included in Java SE 6 • Scripting Language Support • JDBC 4.0 API • Java Compiler API • Pluggable Annotations • Native PKI support • Java GSS, Kerberos and LDAP support • Integrated Web Services • Lot more enhancements Introduction to Java Programming Language Lecture Slides By Adil Aslam
  18. 18. Java Version History • J2SE Version 5.0 • Codename Tiger and released on September 30, 2004. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  19. 19. J2SE Version 5.0 • New features included in J2SE 5.0 • Generics • Enhanced for Loop • Autoboxing/Unboxing • Typesafe Enums • Varargs • Static Import • Metadata (Annotations) • Instrumentation Introduction to Java Programming Language Lecture Slides By Adil Aslam
  20. 20. Java Version History • J2SE Version 1.4 • Codename Merlin and released on February 6, 2002 (first release under JCP). Introduction to Java Programming Language Lecture Slides By Adil Aslam
  21. 21. J2SE Version 1.4 • New features included in J2SE 1.4 • XML Processing • Java Print Service • Logging API • Java Web Start • JDBC 3.0 API • Assertions • Preferences API • Chained Exception • IPv6 Support • Regular Expressions Introduction to Java Programming Language Lecture Slides By Adil Aslam
  22. 22. Java Version History • J2SE Version 1.3 • Codename Kestrel and released on May 8, 2000. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  23. 23. J2SE Version 1.3 • New features included in J2SE 1.3 • Java Sound • Jar Indexing • HotSpot JVM included (the HotSpot JVM was first released in April, 1999 for the J2SE 1.2 JVM). • RMI was modified to support optional compatibility with CORBA • Java Naming and Directory Interface (JNDI) included in core libraries (previously available as an extension) • Java Platform Debugger Architecture (JPDA) • Synthetic proxy classes Introduction to Java Programming Language Lecture Slides By Adil Aslam
  24. 24. Java Version History • J2SE Version 1.2 • Codename Playground and released on December 8, 1998. • This and subsequent releases through J2SE 5.0 were rebranded retrospectively Java 2 and the version name “J2SE” (Java 2 Platform, Standard Edition) replaced JDK to distinguish the base platform from J2EE (Java 2 Platform, Enterprise Edition) and J2ME (Java 2 Platform, Micro Edition). This was a very significant release of Java as it tripled the size of the Java platform to 1520 classes in 59 packages. Major additions included. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  25. 25. Java Version History • J2SE Version 1.2 • Codename Playground and released on December 8, 1998. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  26. 26. J2SE Version 1.2 • New features included in J2SE 1.2 • Collections framework. • strictfp keyword • Java String memory map for constants. • the Swing graphical API was integrated into the core classes • Just In Time (JIT) compiler (Sun’s JVM was equipped with a JIT compiler for the first time). • Jar Signer for signing Java ARchive (JAR) files. • Policy Tool for granting access to system resources. • Audio support in Applets. • Java Plug-in Introduction to Java Programming Language Lecture Slides By Adil Aslam
  27. 27. Java Version History • JDK Version 1.1 • Released on February 19, 1997 • New features included in JDK 1.1 • An extensive (covering or affecting a large area) retooling of the AWT event model • Inner Classes • Java Beans • JDBC (Java Database Connectivity) • RMI (Remote Method Invocation) • Reflection (introspection only, no modification at runtime was possible) Introduction to Java Programming Language Lecture Slides By Adil Aslam
  28. 28. Java Version History • JDK Version 1.0 • Codename Oak and released on January 23, 1996. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  29. 29. Summary Introduction to Java Programming Language Lecture Slides By Adil Aslam Designed By Sun Microsystems Designed In Early 1990s Basic Aim For Communicating Between Household things Earlier Name of Java OAK Creator of Java James Gosling First Public Release 27 May 1995 Java was targeted at Internet Development
  30. 30. Why sun choose "Oak" name? • Why Oak? • Oak is a symbol of strength and chosen as a national tree of many countries like U.S.A., France, Germany, Romania etc. • In 1995, Oak was renamed as "Java" because it was already a trademark by Oak Technologies. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  31. 31. Why sun choose "Java" name? • Why they choose java name for java language? • The team gathered to choose a new name. The suggested words were "dynamic", "revolutionary", "Silk", "jolt", "DNA" etc. They wanted something that reflected the essence of the technology: revolutionary, dynamic, lively, cool, unique, and easy to spell and fun to say. • According to James Gosling "Java was one of the top choices along with Silk". Since java was so unique, most of the team members preferred java. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  32. 32. Language was Created with 5 main Goals • It should be object oriented • A single representation of a program could be executed on multiple operating systems • It should fully support network programming • It should execute code from remote sources securely • It should be easy to use Introduction to Java Programming Language Lecture Slides By Adil Aslam
  33. 33. Overview of Java • Java divided into three categories, they are : • J2SE (Java 2 Standard Edition) • J2EE (Java 2 Enterprise Edition) • J2ME (Java 2 Micro or Mobile Edition) Introduction to Java Programming Language Lecture Slides By Adil Aslam
  34. 34. Overview of Java • J2SE • J2SE is used for developing client side applications. • J2EE • J2EE is used for developing server side applications. • J2ME • J2ME is used for developing mobile or wireless application by making use of a predefined protocol called WAP(wireless Access / Application protocol). Introduction to Java Programming Language Lecture Slides By Adil Aslam
  35. 35. Application of Java • Java is widely used in every corner of world and of human life. Java is not only used in software's but is also widely used in designing hardware controlling software components. There are more than 930 million JRE downloads each year and 3 billion mobile phones run java. • Following are some other usage of Java : • Developing Desktop Applications • Web Applications like Linkedin.com, Snapdeal.com etc. • Mobile Operating System like Android • Embedded Systems • Robotics and games etc. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  36. 36. Introduction of Java • Principles of Java Programming language: • There were five primary goals in the creation of the Java language. • It should be “simple, object-oriented and familiar” • It should be “robust and secure” • It should be “architecture-neutral and portable” • It should execute with “high performance” • It should be “interpreted, threaded, and dynamic” Introduction to Java Programming Language Lecture Slides By Adil Aslam
  37. 37. 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. • Simple • Object-Oriented • Platform independent • Secured • Robust • Architecture neutral • Portable • Dynamic • Interpreted • High Performance • Multithreaded • Distributed Introduction to Java Programming Language Lecture Slides By Adil Aslam
  38. 38. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  39. 39. Features of Java • 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. • And also removed many other confusing and/or rarely used features like explicit pointer, operator overloading etc. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  40. 40. Features of Java • Object-oriented • Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behavior. • Object-oriented programming(OOPs) is a methodology that simplify software development and maintenance by providing some rules. • Basic concepts of OOPs are: • Object • Class • Inheritance • Polymorphism • Abstraction • Encapsulation Introduction to Java Programming Language Lecture Slides By Adil Aslam
  41. 41. Features of Java • 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: • Runtime Environment • API(Application Programming Interface) Introduction to Java Programming Language Lecture Slides By Adil Aslam
  42. 42. Features of Java • Platform Independent • 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). • Java solves the problem of platform-independence by using byte code. The Java compiler does not produce native executable code for a particular machine like a C compiler does. Instead it produces a special format called byte code. Java byte code written in hexadecimal, byte by byte, looks like this: CA FE BA BE 00 03 00 2D 00 3E 08 00 3B 08 00 01 08 00 20 Introduction to Java Programming Language Lecture Slides By Adil Aslam
  43. 43. Platform Independent Introduction to Java Programming Language Lecture Slides By Adil Aslam
  44. 44. Platform Independent Introduction to Java Programming Language Lecture Slides By Adil Aslam
  45. 45. Features of Java • Secured • Java is a secure programming language because: • No explicit pointer • Program run inside virtual machine sandbox. • Array index limit checking • Code pathologies reduced by : • Bytecode verifier – Checks classes after loading (code fragments for illegal code that can violate access right to object.) • Classloader – confines objects to unique namespaces. Prevents loading a hacked “java.lang.SecurityManager” class. • Security manager – determines what resource a class can access such as reading and writing to the local disk. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  46. 46. Secured Introduction to Java Programming Language Lecture Slides By Adil Aslam Program run inside virtual machine sandbox
  47. 47. Features of Java • 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. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  48. 48. Features of Java • 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 architectures. • A Language or Technology is said to be Architectural neutral which can run on any available processors in the real world without considering there architecture and vendor (providers) irrespective to its development and compilation. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  49. 49. Features of Java • High performance • It have high performance because of following reasons; • This language uses Bytecode which is more faster than ordinary pointer code so Performance of this language is high. • Garbage collector, collect the unused memory space and improve the performance of application. • It have no pointers so that using this language we can develop an application very easily. • It support multithreading, because of this time consuming process can be reduced to execute the program. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  50. 50. Features of Java • Networked • It is mainly design for web based applications, J2EE is used for developing network based applications. • Dynamic • It support Dynamic memory allocation due to this memory wastage is reduce and improve performance of application. The process of allocating the memory space to the input of the program at a run-time is known as dynamic memory allocation, To programming to allocate memory space by dynamically we use an operator called 'new' 'new' operator is known as dynamic memory allocation operator. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  51. 51. Features of Java • 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. • 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. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  52. 52. Features of Java • What is Byte Code in java • The code which is converted by java compiler(javac) is called byte code in java. • Why Java is Portable? • The code which is converted by java compiler(javac) is non executable. • Byte code is a highly optimized set of instructions • Byte code is executed by Java run-time system, which is called the java virtual machine (JVM). • Byte code is intermediate language of source code and executable code. • JVM converts byte code of java into machine language to execute microprocessor of OS. • However internal details of JVM will differ from platform to platform but still all JVM understands the same java bytecode. Or in other word we can say JVM is platform dependent and java byte code is platform independent. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  53. 53. How is Java different from C… • C Language: • Major difference is that C is a structure oriented language and Java is an object oriented language and has mechanism to define classes and objects. • Java does not support an explicit pointer type • Java does not have preprocessor, so we cant use #define, #include and #ifdef statements. • Java does not include structures, unions and enum data types. • Java does not include keywords like goto, sizeof and typedef. • Java adds labeled break and continue statements. • Java adds many features required for object oriented programming. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  54. 54. How is Java different from C++… • C++ language Features removed in java: • Java doesn’t support pointers to avoid unauthorized access of memory locations. • Java does not include structures, unions and enum data types. • Java does not support operator over loading. • Preprocessor plays less important role in C++ and so eliminated entirely in java. • Java does not perform automatic type conversions that result in loss of precision. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  55. 55. How is Java different from C++… New features added in Java: • Multithreading, that allows two or more pieces of the same program to execute concurrently. • C++ has a set of library functions that use a common header file. But java replaces it with its own set of API classes. • It adds packages and interfaces. • Java supports automatic garbage collection. • break and continue statements have been enhanced in java to accept labels as targets. • The use of unicode characters ensures portability. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  56. 56. How is Java different from C++… • Java does not support global variables. Every method and variable is declared within a class and forms part of that class. • Java does not allow default arguments. • Java does not support inheritance of multiple super classes by a sub class (i.e., multiple inheritance). This is accomplished by using ‘interface’ concept. • It is not possible to declare unsigned integers in java. • In java objects are passed by reference only. In C++ objects may be passed by value or reference. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  57. 57. How is Java different from C++… Features that differ: • Though C++ and java supports Boolean data type, C++ takes any nonzero value as true and zero as false. True and false in java are predefined literals that are values for a Boolean expression. • Java has replaced the destructor function with a finalize() function. • C++ supports exception handling that is similar to java's. However, in C++ there is no requirement that a thrown exception be caught. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  58. 58. C++ vs Java Introduction to Java Programming Language Lecture Slides By Adil Aslam Comparison Index C++ Java Platform- independent C++ is platform- dependent. Java is platform- independent. Mainly used for C++ is mainly used for system programming. Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications. Goto C++ supports goto statement. Java doesn't support goto statement.
  59. 59. C++ vs Java Introduction to Java Programming Language Lecture Slides By Adil Aslam Comparison Index C++ Java Compiler and Interpreter C++ uses compiler only. Java uses compiler and interpreter both. Call by Value and Call by reference C++ supports both call by value and call by reference. Java supports call by value only. There is no call by reference in java. Structure and Union C++ supports structures and unions. Java doesn't support structures and unions.
  60. 60. C++ vs Java Introduction to Java Programming Language Lecture Slides By Adil Aslam Comparison Index C++ Java Thread Support C++ doesn't have built-in support for threads. Java has built-in thread support. Documentation comment C++ doesn't support documentation comment. Java supports documentation comment (/** ... */) to create documentation for java source code. unsigned right shift >>> C++ doesn't support >>> operator Java supports unsigned right shift >>> operator
  61. 61. Basic of Java • Java is a platform independent, more powerful, secure, high performance, multithreaded programming language. Here we discuss some points related to java. • Define byte • Byte code is the set of optimized instructions generated during compilation phase and it is more powerful than ordinary pointer code. • Define JRE • The Java Runtime Environment (JRE) is part of the Java Development Kit (JDK). It contains set of libraries and tools for developing java application. The Java Runtime Environment provides the minimum requirements for executing a Java application. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  62. 62. Basic of Java • Define JVM • JVM is set of programs developed by sun Micro System and supplied as a part of jdk for reading line by line of byte code and it converts into native understanding form of operating system. Java language is one of the compiled and interpreted programming language. • Garbage Collector • Garbage Collector is the system Java program which runs in the background along with regular Java program to collect un-Referenced (unused) memory space for improving the performance of our applications. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  63. 63. Basic of Java • What is JVM? • It is: • A specification where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Sun and other companies. • An implementation Its implementation is known as JRE (Java Runtime Environment). • Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  64. 64. Basic of Java • What it does • The JVM performs following operation: • Loads code • Verifies code • Executes code • Provides runtime environment • JVM provides definitions for the: • Memory area • Class file format • Register set • Garbage-collected heap • Fatal error reporting etc. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  65. 65. Basic of Java • Network Based Applications • Network based application are mainly classified into two types. • Centralized applications • Distributed applications Introduction to Java Programming Language Lecture Slides By Adil Aslam
  66. 66. Centralized Applications • In this scenario multiple clients system depends on single server system. • The major drawback in this architecture is if any problem occurred on server system that will be reflected on every client system. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  67. 67. Distributed Applications • In this scenario multiple client system are depends on multiple server systems so that even problem occurred in one server will never be reflected on any client system. • Java is very powerful language can be used to developed both client server architecture and distributed architecture based application. • Note: In this architecture same application is distributed in multiple server system. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  68. 68. Distributed Applications Introduction to Java Programming Language Lecture Slides By Adil Aslam
  69. 69. Difference between JDK, JRE and JVM • JVM • JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. • JVMs are available for many hardware and software platforms. JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent. • The JVM performs following main tasks: • Loads code • Verifies code • Executes code • Provides runtime environment Introduction to Java Programming Language Lecture Slides By Adil Aslam
  70. 70. Basic of Java • JRE • JRE is an acronym for Java Runtime Environment. It is used to provide runtime environment. It is the implementation of JVM. It physically exists. It contains set of libraries + other files that JVM uses at runtime. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  71. 71. Basic of Java • The Java Development Kit (JDK) is primary components. It physically exists. It is collection of programming tools and JRE, JVM. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  72. 72. Internal Architecture of JVM • JVM (Java Virtual Machine) is a software. It is a specification that provides Runtime environment in which java bytecode can be executed. • Operation of JVM • JVM mainly performs following operations. • Allocating sufficient memory space for the class properties. • Provides runtime environment in which java bytecode can be executed • Converting byte code instruction into machine level instruction. • JVM is separately available for every Operating System while installing java software so that JVM is platform dependent. • Note: Java is platform Independent but JVM is platform dependent because every Operating system have different- different JVM which is install along with JDK Software. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  73. 73. Internal Architecture of JVM Introduction to Java Programming Language Lecture Slides By Adil Aslam
  74. 74. Internal Architecture of JVM • 1) Class Loader Subsystem: • Class loader subsystem will load the .class file into java stack and later sufficient memory will be allocated for all the properties of the java program into following five memory locations. • Heap area • Method area • Java stack • PC register • Native stack Introduction to Java Programming Language Lecture Slides By Adil Aslam
  75. 75. Internal Architecture of JVM • 2) Heap Area: • In which object references will be stored. • 3) Method Area • In which static variables non-static and static method will be stored. • 4) Stack • java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return. • Each thread has a private JVM stack, created at the same time as thread. • A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes Introduction to Java Programming Language Lecture Slides By Adil Aslam
  76. 76. Internal Architecture of JVM • 5) Pc Register • Which holds the address of next executable instruction that means that use the priority for the method in the execution process? • 6) Native Stack • Native stack holds the instruction of native code (other than java code) native stack depends on native library. Native interface will access interface between native stack and native library. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  77. 77. Internal Architecture of JVM • 7) Execution Engine • It contains: I. A virtual processor II. Interpreter: Read bytecode stream then execute the instructions. III. Just-In-Time(JIT) compiler: It is used to improve the performance. IT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here the term ?compiler? refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  78. 78. What is JIT and Why use JIT • JIT is the set of programs developed by SUN Micro System and added as a part of JVM, to speed up the interpretation phase. • In the older version of java compilation phase is so faster than interpretation phase. Industry has complained to the SUN Micro System saying that compilation phase is very faster and interpretation phase is very slow. • So solve this issue, SUN Micro System has developed a program called JIT (just in time compiler) and added as a part of JVM to speed up the interpretation phase. In the current version of java interpretation phase is so faster than compilation phase. Hence java is one of the highly interpreted programming languages. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  79. 79. Internal Architecture of JVM •Native Method Interface • Native method interface gives an interface between java code and native code during execution. • Native Method Libraries • Native Libraries consist of files required for the execution of native code. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  80. 80. Heap Area • The heap is the run-time data area from which memory for all class instances and arrays is allocated. • Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. • By default size of heap is 64 MB • Garbage Collection runs on the heap memory to free the memory used by objects that doesn’t have any reference. • Heap Memory Types • Young Generation • Old Generation • Permanent Generation Introduction to Java Programming Language Lecture Slides By Adil Aslam
  81. 81. Heap Area • Heap Memory Types • Young Generation • Old Generation • Permanent Generation Introduction to Java Programming Language Lecture Slides By Adil Aslam
  82. 82. Heap Area • Heap Size • By default minimum size of heap is 64 MB and maximum size of heap is 1024 MB. But we can change heap size in JVM Introduction to Java Programming Language Lecture Slides By Adil Aslam VM Switch VM Switch Description -Xms To set initial heap size when JVM starts -Xmx To set maximum heap size when JVM starts -Xmn To set Young Generation memory size -XX:PermGen To set initial Perm Generation memory size -XX:MaxPermGen To set maximum Perm Generation memory size -XX:SurvivorRatio To set Survivor Space memory size
  83. 83. Popular Java Editors • To write your Java programs, We will need a text editor. There are even more sophisticated IDEs available in the market. But for now, you can consider one of the following: • Notepad: On Windows machine you can use any simple text editor like Notepad and TextPad. • NetBeans: is a Java IDE that is open-source and free which can be downloaded from http://www.netbeans.org/index.html. • Eclipse: is also a Java IDE developed by the eclipse open-source community and can be downloaded from http://www.eclipse.org/. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  84. 84. Tools We Will Need • For this Course We will need the following software's: • Linux 7.1 or Windows XP/7/8/10 Operating System. • Java JDK 8 • NetBeans 8.1 Introduction to Java Programming Language Lecture Slides By Adil Aslam
  85. 85. Download Java Development Kit • Download Java SE Development Kit 8 According to your Operating System architecture (32bit or 64bit) • http://www.oracle.com/technetwork/java/javase/d ownloads/jdk8-downloads-2133151.html • We can also download JDK from any site with latest version probably version 8 is latest. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  86. 86. Introduction to Java Programming Language Lecture Slides By Adil Aslam When you go JDK official site link is given in previous slide then you can see this type of webpage. Now download JDK According to your Operating System type If you have Windows 64bit Operating System then Click Here
  87. 87. Introduction to Java Programming Language Lecture Slides By Adil Aslam When you go JDK official site link is given in previous slide then you can see this type of webpage. Now download JDK According to your Operating System type If you have Windows 32bit Operating System then Click Here
  88. 88. Introduction to Java Programming Language Lecture Slides By Adil Aslam When you go JDK official site link is given in previous slide then you can see this type of webpage. Now download JDK According to your Operating System type If you have any other Operating System then you can download according to your OS
  89. 89. Please Note • If you don’t know about you Operating System Architecture is it 32bit or 64bit so follow me to find this.. • Go on my computer icon and right click, after that click on properties option Introduction to Java Programming Language Lecture Slides By Adil Aslam
  90. 90. Introduction to Java Programming Language Lecture Slides By Adil Aslam Step One
  91. 91. Introduction to Java Programming Language Lecture Slides By Adil Aslam Step Two
  92. 92. Introduction to Java Programming Language Lecture Slides By Adil Aslam Step Two Here You can find your computer Operating system type is it 32bit or 64bit. In my case 64bit.
  93. 93. Now Download NetBeans 8.1 • For Download NetBeans Go this Site • https://netbeans.org/downloads/ • You can also Download from any other site but remember Official Website is recommended. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  94. 94. Introduction to Java Programming Language Lecture Slides By Adil Aslam When you go to NetBeans Official Site then you can see this type of webpage, Then you can simply download All Bundles Version. Follow me
  95. 95. Introduction to Java Programming Language Lecture Slides By Adil Aslam When you go to NetBeans Official Site then you can see this type of webpage, Then you can simply download All Bundles Version. Follow me Simply Click here for download. Don’t Worry about 32bit and 64bit because this bundle contain both setup of 32bits and 64bits
  96. 96. Introduction to Java Programming Language Lecture Slides By Adil Aslam Installation Process
  97. 97. After Download you must have these two Software’s Setup Introduction to Java Programming Language Lecture Slides By Adil Aslam This is JDK
  98. 98. After Download you must have these two Software’s Setup Introduction to Java Programming Language Lecture Slides By Adil Aslam This is JDK This is NetBeans
  99. 99. Introduction to Java Programming Language Lecture Slides By Adil Aslam 1. Installation of JDK
  100. 100. First Install Java Development Kit (JDK) Introduction to Java Programming Language Lecture Slides By Adil Aslam Double Click on Setup for installation of JDK
  101. 101. Introduction to Java Programming Language Lecture Slides By Adil Aslam Then you can see this type of screen
  102. 102. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Click Next
  103. 103. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Click Next Please don’t Change Path
  104. 104. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Wait For Installation
  105. 105. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Some More Wait
  106. 106. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Click Close
  107. 107. Java Development Kit Installation Completed.! Introduction to Java Programming Language Lecture Slides By Adil Aslam
  108. 108. Introduction to Java Programming Language Lecture Slides By Adil Aslam 2. Installation of NetBeans
  109. 109. Secondly Now We Install NetBeans Introduction to Java Programming Language Lecture Slides By Adil Aslam Double click Here for Installation of NetBeans
  110. 110. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Click Next
  111. 111. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Click the “Accept” Checkbox.
  112. 112. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam After Click the “Next” Button
  113. 113. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Click Next Please Don’t Change the Installation Path Because Default Path is Recommended
  114. 114. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam If you don’t want auto Updates then you uncheck this Box
  115. 115. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam If you don’t want auto Updates then you uncheck this Box After Click Next
  116. 116. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Uncheck this Checkbox Uncheck this Checkbox
  117. 117. Then you can see this type of screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Uncheck this Checkbox Uncheck this Checkbox After Click Finish
  118. 118. NetBeans Installation Completed.! Introduction to Java Programming Language Lecture Slides By Adil Aslam
  119. 119. Introduction to Java Programming Language Lecture Slides By Adil Aslam 3.Create Your First Project
  120. 120. Create Your First Project Introduction to Java Programming Language Lecture Slides By Adil Aslam Click on .exe of NetBeans for Starting of NetBeans
  121. 121. After You Can See This Type of Screen Introduction to Java Programming Language Lecture Slides By Adil Aslam Wait Until Loading is Complete
  122. 122. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  123. 123. Introduction to Java Programming Language Lecture Slides By Adil Aslam Then you Can see this Type of Screen
  124. 124. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  125. 125. Introduction to Java Programming Language Lecture Slides By Adil Aslam For New Project Follow me Click File then Click New Project
  126. 126. Introduction to Java Programming Language Lecture Slides By Adil Aslam After You Can See This Type of Screen
  127. 127. Introduction to Java Programming Language Lecture Slides By Adil Aslam After You Can See This Type of Screen
  128. 128. Introduction to Java Programming Language Lecture Slides By Adil Aslam After You Can See This Type of Screen Click Next Don’t Change Anything
  129. 129. Introduction to Java Programming Language Lecture Slides By Adil Aslam After You Can See This Type of Screen
  130. 130. Introduction to Java Programming Language Lecture Slides By Adil Aslam You Can Change the Project Name as You Want Here
  131. 131. Introduction to Java Programming Language Lecture Slides By Adil Aslam You Can Change the Project Name as You Want Here You Can Also Change Project Saving Location
  132. 132. Introduction to Java Programming Language Lecture Slides By Adil Aslam You Can Change the Project Name as You Want Here You Can Also Change Project Saving Location After Click Finish
  133. 133. Introduction to Java Programming Language Lecture Slides By Adil Aslam After You Can See This Type of Screen
  134. 134. Introduction to Java Programming Language Lecture Slides By Adil Aslam After You Can See This Type of Screen Initially You can Write your First Program Here
  135. 135. Introduction to Java Programming Language Lecture Slides By Adil Aslam First Program This is the First Program Example
  136. 136. Introduction to Java Programming Language Lecture Slides By Adil Aslam First Program This is the First Program Example For Run this Program Click Here
  137. 137. Introduction to Java Programming Language Lecture Slides By Adil Aslam First Program Output of this Program is Here
  138. 138. Introduction to Java Programming Language Lecture Slides By Adil Aslam First Program Output of this Program is Here Coder is Here
  139. 139. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Class Keyword
  140. 140. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Class Name
  141. 141. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Starting of Class Level Scope
  142. 142. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam This is Called One Block
  143. 143. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam This is Called Main Method
  144. 144. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Body of Main Method
  145. 145. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Start of Main Method level scope
  146. 146. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Print on Screen
  147. 147. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam End of Main Method
  148. 148. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam End of Class
  149. 149. First Java Program class MyFirstProgram { public static void main(String[] args) { System.out.println ("My First Program"); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Semicolon use to terminate the statement.
  150. 150. Blocks in Java • A block (or a compound statement) is a group of statements surrounded by braces { }. • All the statements inside the block is treated as one unit. Blocks are used as the body in constructs like function, if-else and loop, which may contain multiple statements but are treated as one unit. • For example Introduction to Java Programming Language Lecture Slides By Adil Aslam public static void main(String[] args) { System.out.println ("My First Program"); } This is one block
  151. 151. • class – is use to declare a class in java. • public – is a access modifies which represent visibility. public means it is visible to everyone. • static – is a keyword. If we any method as static , it is known as static method. The advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it does not require to create object to invoke the main method. So it saves memory. • void – is the return type of the method. void means method does not return any value. • main – represent startup of the program. • String args[] – is used for command line argument. we will learn it later. • System.out.println() – is used to print statement. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  152. 152. First Java Program • class – is use to declare a class in java. • public – is a access modifies which represent visibility. public means it is visible to everyone. • static – is a keyword. If we any method as static , it is known as static method. The advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it does not require to create object to invoke the main method. So it saves memory. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  153. 153. First Java Program • void – is the return type of the method. void means method does not return any value. • main() : main() method is the most important method in a Java program. This is the method which is executed, hence all the logic must be inside the main() method. If a java class is not having a main() method, it causes compilation error. • String args[] – is used for command line argument. We will learn it later. • System.out.println() – is used to print statement. We will learn about the internal working of System.out.println statement later. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  154. 154. Explanation of main Method Introduction to Java Programming Language Lecture Slides By Adil Aslam public static void main( String[] args ) { } "public" means that main() can be called from anywhere. "static" means that main() doesn't belong to a specific object "void" means that main() returns no value "main" is the name of a function. main() is special because it is the start of the program. "String[]" means an array of String. String[] args” is a single parameter for the method. String[] is the type of the parameter, indicating an array of Strings. “args” is the name of the parameter. Parameters must be named. "args" is not special; you could name it anything else and the program would work the same.
  155. 155. Explanation of Print Statement • Java comes up with the pre-defined class to let us print strings or variables in the screen. The pre- defined or built-in class is the system class that provides a few useful methods and variables. • The whole line system.out.println is explained below: • System: System is the class provided by Java that contains variables and methods. • Out: Out is the system’s static variable. • Println: Println is the method of system class that is used to print the given text or variable etc. Introduction to Java Programming Language Lecture Slides By Adil Aslam system.out.println()
  156. 156. Error Correction Introduction to Java Programming Language Lecture Slides By Adil Aslam This is an Error Indication
  157. 157. Error Correction Introduction to Java Programming Language Lecture Slides By Adil Aslam This is an Error Indication For Error Correction Move Your Mouse Pointer In this Error dot and you can See Suggestion for Error Correction
  158. 158. Error Correction Introduction to Java Programming Language Lecture Slides By Adil Aslam This is an Error Indication For Error Correction Move Your Mouse Pointer In this Error dot and you can See Suggestion for Error Correction
  159. 159. Error Correction Introduction to Java Programming Language Lecture Slides By Adil Aslam This is an Error Indication For Error Correction Move Your Mouse Pointer In this Error dot and you can See Suggestion for Error Correction This is the Suggestion and Show that Semicolon is Missing at the end of this Statement
  160. 160. Error Correction Introduction to Java Programming Language Lecture Slides By Adil Aslam Before Error Correction After Error Correction
  161. 161. How to Open/Run saved Project of Java Simply Load/Run Your NetBeans and Follow me Introduction to Java Programming Language Lecture Slides By Adil Aslam All your Saved Projects are shown Here
  162. 162. Introduction to Java Programming Language Lecture Slides By Adil Aslam For Run/Open Your Project Simply Double on this Java File
  163. 163. Introduction to Java Programming Language Lecture Slides By Adil Aslam All Done! This is Your Saved Project
  164. 164. Internal Details of Java First Program • What happens at compile time? • At compile time, java file is compiled by Java Compiler (It does not interact with OS) and converts the java code into bytecode. Introduction to Java Programming Language Lecture Slides By Adil Aslam class MyFirstProgram { public static void main(String[] args) { System.out.println (“My First Program"); } } Compiler Bytecode MyFirstProgram.java MyFirstProgram.class
  165. 165. What Happens at Runtime? • Classloader: is the subsystem of JVM that is used to load class files. • Bytecode Verifier: checks the code fragments for illegal code that can violate access right to objects. • Interpreter: read bytecode stream then execute the instructions. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  166. 166. Basic Syntax of Java Program • About Java programs, it is very important to keep in mind the following points. • Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. • Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example class MyFirstJavaClass Introduction to Java Programming Language Lecture Slides By Adil Aslam
  167. 167. Basic Syntax of Java Program • Method Names - All method names should start with a Lower Case letter. • If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. • Example public void myMethodName() Introduction to Java Programming Language Lecture Slides By Adil Aslam
  168. 168. Basic Syntax of Java Program • Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile). Example: Assume 'MyFirstProgram' is the class name. Then the file should be saved as 'MyFirstProgram.java' Introduction to Java Programming Language Lecture Slides By Adil Aslam
  169. 169. Java Program Structure • As we seen in the previous slides first program example, a Java program may contain many classes of which only one class define a main method. • Classes contain data members and methods that operate on the data members of the class. Method may contain data type declarations and executable statements. • To wire a java program we first define classes and put them together. • A java Program may contain one or more sections as show in fig in next slide. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  170. 170. Introduction to Java Programming Language Lecture Slides By Adil Aslam Suggested Optional Optional Optional Optional Essential
  171. 171. Java Program Structure • Documentation Section • The documentation section comprises a set of comment lines giving the name of the program, the author and detail, which the programmer would like to refer to at a later stage. • Comments must explain why and what a classes and how algorithms. • This would greatly help in maintaining the program. • /**……*/ know as documentation comments. • This form of comment is used to generating documentation. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  172. 172. Java Program Structure • Package Statement • The package statement allowed in a Java file is a package statement . • This statement declares a package name and informs the compiler that the classes defined here belong to this package. • Example package myfirstprogram; • The package statement is optional. • That is, our classes do not have to be part of package. • More about packages we learn later in detail . Introduction to Java Programming Language Lecture Slides By Adil Aslam
  173. 173. Java Program Structure • Import Statement • The next thing after a package statement (but before any class definition) may be a number of import statements. • This is similar to the #include statement in C/C++. • Example import Math.min; • This statement instruct the interpreter to load the test class contained in the package student. • Using import statements, we can have access to classes that are part of other packages, • More about import statement we learn in upcoming lecture Introduction to Java Programming Language Lecture Slides By Adil Aslam
  174. 174. Java Program Structure • Interface statements • An interface is like a class but includes group of method declaration. • This is also an optional section and is used only when we wish to implement the multiple inheritance feature in the program. • Interface is a new concept in java and we discussed in detail in upcoming lectures. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  175. 175. Java Program Structure • Class Definition • A Java program may contain multiple class definition. • Classes are the primary and essential part of a Java program. • These classes are used to map the objects of real- world problem. • The number of classes used depends on the complexity of the problem. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  176. 176. Java Program Structure • Main Method Class • Since every Java stand-alone program require a main method as its starting point, this class is the essential part of a java program. • A simple Java program may contain only this part. • The main method create object of various classes and establish communication between them. • On reaching end of main the program terminates and the control passes back to the operating system (OS). Introduction to Java Programming Language Lecture Slides By Adil Aslam
  177. 177. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam
  178. 178. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam Package Statement
  179. 179. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam Documentation Section
  180. 180. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam Import Statement Yellow Sign indicate this Statement is Snused
  181. 181. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam Class Definition
  182. 182. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam Main Method Definition
  183. 183. Java Program Structure Introduction to Java Programming Language Lecture Slides By Adil Aslam This Show that, Line Number of Your Code
  184. 184. First Review • Object and class in Java • We Lean about, Objects and Classes in Detail in upcoming Lecture. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  185. 185. Object and class in Java • Object is the physical as well as logical entity where as class is the only logical entity. • Class: Class is a blue print which is containing only list of variables and method and no memory is allocated for them. A class is a group of objects that has common properties. • A class in java contains: • Data Member • Method • Constructor • Block • Class and Interface Introduction to Java Programming Language Lecture Slides By Adil Aslam
  186. 186. Object and class in Java • Object: Object is a instance of class, object has state and behaviors. • An Object in java has three characteristics: • State • Behavior • Identity • State: Represents data (value) of an object. • Behavior: Represents the behavior (functionality) of an object such as deposit, withdraw etc. • Identity: Object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. But, it is used internally by the JVM to identify each object uniquely. • Class is also can be used to achieve user defined data types. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  187. 187. Real life Example of object and class • In real world many examples of object and class like dog, cat, and cow are belong to animal's class. Each object has state and behaviors. • For example a dog has state: color, name, height, age as well as behaviors: barking, eating, and sleeping. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  188. 188. Real life Example of object and class • Vehicle class • Car, bike, truck these all are belongs to vehicle class. These Objects have also different states and behaviors. For Example car has state: color, name, model, speed, Mileage. And behaviors: distance travel Introduction to Java Programming Language Lecture Slides By Adil Aslam
  189. 189. Object and Class in Java Introduction to Java Programming Language Lecture Slides By Adil Aslam
  190. 190. Object and Class in Java Introduction to Java Programming Language Lecture Slides By Adil Aslam
  191. 191. Difference between Class and Object Class Object 1 Class is a container which collection of variables and methods. object is a instance of class 2 No memory is allocated at the time of declaration Sufficient memory space will be allocated for all the variables of class at the time of declaration. 3 One class definition should exist only once in the program. For one class multiple objects can be created. Introduction to Java Programming Language Lecture Slides By Adil Aslam
  192. 192. Syntax of declaring class access specifier class classname { type instance-variable1; .... type instance-variableN; type methodname1(parameter-list) { // body of method } .... type methodnameN(parameter-list) { // body of method } } Introduction to Java Programming Language Lecture Slides By Adil Aslam
  193. 193. Simple Example of Object and Class class Employee { int eid; // data member (or instance variable) String ename; // data member (or instance variable) eid=101; //Assign value to instance variable ename=“Adil"; //Assign value to instance variable public static void main(String args[]) { Employee e=new Employee(); // Creating an object of class Employee System.out.println("Employee ID: "+e.eid); System.out.println("Name: "+e.ename); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam
  194. 194. Simple Example of Object and Class class Employee { int eid; // data member (or instance variable) String ename; // data member (or instance variable) eid=101; //Assign value to instance variable ename=“Adil"; //Assign value to instance variable public static void main(String args[]) { Employee e=new Employee(); // Creating an object of class Employee System.out.println("Employee ID: "+e.eid); System.out.println("Name: "+e.ename); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Output is: Employee ID: 101 Name: Adil
  195. 195. Simple Example of Object and Class class Employee { int eid; // data member (or instance variable) String ename; // data member (or instance variable) eid=101; //Assign value to instance variable ename=“Adil"; //Assign value to instance variable public static void main(String args[]) { Employee e=new Employee(); // Creating an object of class Employee System.out.println("Employee ID: "+e.eid); System.out.println("Name: "+e.ename); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Output is: Employee ID: 101 Name: Adil Note: A new keyword is used to allocate memory at runtime, new keyword is used for create an object of class, later we discuss all the way for create an object of class.
  196. 196. Simple Example of Object and Class class Employee { int eid; // data member (or instance variable) String ename; // data member (or instance variable) eid=101; //Assign value to instance variable ename=“Adil"; //Assign value to instance variable public static void main(String args[]) { Employee e=new Employee(); // Creating an object of class Employee System.out.println("Employee ID: "+e.eid); System.out.println("Name: "+e.ename); } } Introduction to Java Programming Language Lecture Slides By Adil Aslam Output is: Employee ID: 101 Name: Adil Note: A new keyword is used to allocate memory at runtime, new keyword is used for create an object of class, later we discuss all the way for create an object of class.
  197. 197. Introduction to Java Programming Language Thank You  Lecture Slides By Adil Aslam

×