1 / 216

Core java

Core java. Jun 15, 2017. By : Prof. Gharu Anand N. Agenda. What is JAVA? Features of Java Hello World Program Brief Concept JDK , JRE and JVM Java OOP Concepts. Project Execution Traditional Approach. History Of Java?. Programming Language & a Platform. Java Version?.

kristinab
Télécharger la présentation

Core java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Core java Jun 15, 2017 By : Prof. Gharu Anand N.

  2. Agenda What is JAVA? Features of Java Hello World Program Brief Concept JDK , JRE and JVM Java OOP Concepts

  3. Project Execution Traditional Approach History Of Java? Programming Language & aPlatform Java Version? Where it is used? Features of java?? What comes to your mind ??? Java Runtime Environment Java OOP Concepts? Java New features Java Virtual Machine Java Development Kit 3

  4. What is Java? • Java is a Programming language and a Platform • Any hardware or software environment in which a program runs, known as a platform. Since Java has its own Runtime Environment (JRE) and API, it is called platform. • Java Version • 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)

  5. What it is Used? • Desktop Applications such as acrobat reader, media player, antivirus etc. • Web Applications such as irctc.co.in..etc. • Enterprise Applications such as banking applications. • Mobile • Embedded System • Smart Card • Robotics • Games etc.

  6. Types of Java Application? • There are mainly 4 type of applications that can be created using java: • 1) Standalone Application It is also known as desktop application or window-based application. An application that we need to install on every machine such as media player, antivirus etc. AWT and Swing are used in java for creating standalone applications. • 2) Web Application An application that runs on the server side and creates dynamic page, is called web application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating web applications in java.

  7. Types of Java Application • 3) Enterprise Application An application that is distributed in nature, such as banking applications etc. It has the advantage of high level security, load balancing and clustering. In java, EJB is used for creating enterprise applications. • 4) Mobile Application An application that is created for mobile devices. Currently Android and Java ME are used for creating mobile applications.

  8. Brief History of JAVA • James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. • originally designed for small, embedded systems in electronic appliances like set-top boxes. • initially called Oak and was developed as a part of the Green project • In 1995, Oak was renamed as "Java". Java is just a name not an acronym. • originally developed by James Gosling at Sun Microsystems(which is now a subsidiary of Oracle Corporation) and released in 1995. • JDK 1.0 released in(January 23, 1996).

  9. Features of Java • Simple • Object-Oriented • Platform Independent • Secured • Robust • Architecture Neutral • Portable • High Performance • Distributed • Multi-threaded

  10. Java is Simple?? • Java is simple in the sense that: • 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.

  11. Java is Object Oriented? • Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behaviour. • Object-oriented programming(OOPs) is a methodology that simplify software development and maintenace by providing some rules. • Basic concepts of OOPs are: 1. Object 2. Class 3. Inheritance 4. Polymorphism 5. Abstraction 6. Encapsulation

  12. Java is 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's a software-based platform that runs on top of other hardware-based platforms. It has two components: • Runtime Environment & API(Application Programming Interface) • Java code can be run on multiple platforms e.g. Windows,Linux,SunSolaris,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).

  13. Platform Independent

  14. Java is Secure • Java is Secured because: • No explicit pointer • Programs run inside virtual machine sandbox. • Class loader- adds security by separating the package for the classes of the local file system from those that are imported from network sources. • Byte code Verifier- checks the code fragments for illegal code that can violate accesss right to objects. • Security Manager- determines what resources a class can access such as reading and writing to the local disk. Some security can also be provided by through SSL, JAAS,cryptography etc.

  15. Java is Robust Java is Robust because - • 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. • Architecture-neutral • There is no implementation dependent features e.g. size of primitive types is set.

  16. C++ Program Execution

  17. Java Program Execution

  18. Portable High-Performance Distributed • Portable We may carry the java byte code to any platform. • High-performance Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++) • 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.

  19. Multi-Threaded • 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 shares the same memory. Threads are important for multi-media, Web applications etc.

  20. Hello Word Java Program!! • Requirement for Hello Java Example For executing any java program, you need to • create the java program. • install the JDK if you don't have installed it You may also use the eclipse different version. • set path of the bin directory under jdk. In Case of Eclipse you may also do the same. • compile and execute the program.

  21. Hello Word Java Program!! Creating hello java example Let's create the hello java program: class Simple{ public static void main(String args[]){ System.out.println("Hello Java") } } save this file as Simple.java

  22. Understanding First Java Program • class is used to declare a class in java. • publicis an access modifier which represents visibility, it means it is visible to all. • static is a keyword, if we declare any method as static, it is known as static method. The core 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 doesn't require to create object to invoke the main method. So it saves memory. • void is the return type of the method, it means it doesn't return any value.

  23. Understanding First Java Program • mainrepresents startup of the program. • String[] args is used for command line argument. We will learn it later. • System.out.println()is used print statement. To write the simple program, open notepad and write simple program as displayed below:

  24. Understanding First Java Program

  25. Understanding First Java Program • write the simple program of java in notepad and saved it as Simple.java. • To compile and run this program, you need to open command prompt by start -> All Programs -> Accessories -> command prompt.-> set path To compile: javac Simple.java To execute: java Simple Output: Hello Java

  26. What happen 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.

  27. Step follow at Compile Time..

  28. How many ways, we can write a java program? There are many ways to write a java program. The modifications that can be done in a java program are given below: 1) By changing sequence of the modifiers, method prototype is not changed. Let's see the simple code of main method. static public void main(String args[]) 2) subscript notation in java array can be used after type, before variable or after variable. Let's see the different codes to write the main method. public static void main(String[] args) public static void main(String []args) public static void main(String args[])

  29. How many ways, we can write a java program? 3) You can provide var-args support to main method by passing 3 ellipses (dots) Let's see the simple code of using var-args in main method. We will learn about var-args later in Java New Features chapter. public static void main(String... args) 4) Having semicolon at the end of class in java is optional. Let's see the simple code. class A{ static public void main(String... args){ System.out.println("hello java4"); } };

  30. How to Set Permanent Path of JDK? • Class loader:is the subsystem of JVM that is used to load class files. • Bytecode Verifier: checks the code fragments for illegal code that can violate accesss right to objects. • Interpreter: read bytecode stream then execute the instructions. • Setting Permanent Path of JDK in Windows: • For setting the permanent path of JDK, you need to follow these steps: • Go to MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok

  31. How to Set Permanent Path of JDK? • Click on new tab of user variables • write path in variable name • Copy the path of bin folder • Paste path of bin folder in variable value • Click on ok button • Click on ok button • Now your permanent path is set. You can now execute any program of java from any drive.

  32. Difference between JDK,JRE and JVM • Difference between JDK,JRE and JVM 1. Brief summary of JVM 2. Java Runtime Environment (JRE) 3. Java Development Kit (JDK) • 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 (i.e.JVM is plateform dependent).

  33. Difference between JDK,JRE and JVM The JVM performs four main tasks: • Loads code • Verifies code • Executes code • Provides runtime environment 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.

  34. Difference between JDK,JRE and JVM

  35. Difference between JDK,JRE and JVM • JDK • JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.

  36. JVM (Java Virtual Machine) 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 (i.e.JVM is plateform dependent). The JVM performs four main tasks: • Loads code • Verifies code • Executes code • Provides runtime environment

  37. JVM (Java Virtual Machine) JVM provides definitions for the: • Memory area • Class file format • Register set • Garbage-collected heap • Fatal error reporting etc.

  38. Internal Architecture of Java

  39. Internal Architecture of Java 1) Classloader: Class loader is a subsystem of JVM it is used to load class files. 2) Class(Method) Area: stores per-class structures such as the runtime constant pool, field and method data, the code for methods. 3) Heap: It is the runtime data area in which objects are allocated. 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. 5) Program Counter Register: PC (program counter) register. It contains the address of the Java virtual machine instruction currently being executed.

  40. Internal Architecture of Java 6) Native Method Stack: It contains all the native methods used in the application. 7) Execution Engine: It contains: 1) A virtual processor 2) Interpreter: Read byte code stream then execute the instructions. 3) Just-In-Time(JIT) compiler:It is used to improve the performance.JIT 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.

  41. Variable Declaration and Operator Program of swapping two numbers without using third variable. class SwapTwoNumbers{ public static void main(String args[]){ int a=40,b=5; a=a*b; b=a/b; a=a/b;  System.out.println("a= "+a); System.out.println("b= "+b);   } }

  42. Java OOPs Concepts • OOPs (Object Oriented Programming System) • Object means a real word entity such as pen, chair, table etc. • Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts: • Object • Class • Inheritance • Polymorphism • Abstraction & Encapsulation

  43. Advantage of OOPs over Procedure-oriented programming language 1) OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grows. 2) OOPs provides data hiding whereas in Procedure-oriented prgramming language a global data can be accessed from anywhere. 3) OOPs provides ability to simulate real-world event much more effectively. We can provide the solution of real word problem if we are using the Object-Oriented Programming language.

  44. What is difference between object-oriented programming language and object-based programming language? • Object based programming language follows all the features of OOPs except Inheritance. JavaScript and VBScript are examples of object based programming lang • usages.

  45. Naming convention • Naming convention A naming convention is a rule to follow as you decide what to name your identifiers (e.g. class, package, variable, method, etc.), but it is not mandatory to follow that is why it is known as convention not rule. • Advantage: By using standard Java naming conventions they make their code easier to read for themselves and for other programmers. Readability of Java code is important because it means less time is spent trying to figure out what the code does.

  46. Naming Convention • Class Name - should begin with uppercase letter and be a noun e.g. String, System,Thread etc. • Interface name -should begin with uppercase letter and be an adjective (whereever possible). e.g. Runnable, ActionListener etc. • Method name - should begin with lowercase letter and be a verb. e.g. main(),print(),println(),actionPerformed() etc. • variable name - should begin with lowercase letter e.g. firstName,orderNumber etc. • Package name- should be in lowercase letter. e.g. java,lang,sql,util etc. • constants name - should be in uppercase letter. e.g. RED,YELLOW,MAX_PRIORITY etc.

  47. Object and Class (Object-Oriented Programming) Object and Class (Object-Oriented Programming) 1. Object 2. Class 3. Instance Variable 4. Method 5. Advantage of Method 6. new keyword 7. Example of Object and class that maintains the records of student 8. Different ways to create an object in java 9. Anonymous Object 10. Creating multiple objects by one type

  48. Object • Object • A runtime entity that has state and behaviour is known as an object. For example: chair, table, pen etc. It can be tengible or intengible (physical or logical). • An object has three characteristics: • state: represents the data of an object. • behavior: represents the behavior of an object. • identity: Object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user, but is used internally by the JVM to identify each object uniquely.

  49. Class • For Example: Pen is an object. Its name is Reynolds, color is white etc. known as its state. It is used to write, so writing is its behavior. • Object is an instance of a class.Class is a template or blueprint from which objects are created. So object is the instance(result) of a class. Class - A class is a group of objects that have common property. It is a template or blueprint from which objects are created. •  A class in java can contain: Data member • Method • Constructor • Block

  50. Syntax of Class declaration Syntax to declare a class: class <class_name> { data member; method; } • We are creating the object of the Student class by new keyword and printing the objects value.

More Related