Java Programming [R17a0507]
Total Page:16
File Type:pdf, Size:1020Kb
JAVA PROGRAMMING [R17A0507] LECTURE NOTES B.TECH II YEAR – II SEM (R17) (2018-19) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY (Autonomous Institution – UGC, Govt. of India) (Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015 Certified) Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, INDIA. MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING (R17A0507)JAVA PROGRAMMING Objectives: This subject aims to introduce students to the Java programming language. Upon successful completion of this subject, students should be able to create Java programs that leverage the object-oriented features of the Java language, such as encapsulation, inheritance and polymorphism; use data types, arrays and other data collections; implement error-handling techniques using exception handling, create and event-driven GUI using Swing components. UNIT-I OOP Concepts:- Data abstraction, encapsulation, inheritance, Benefits of Inheritance, Polymorphism, classes and objects, Procedural and object oriented programming paradigms. Java Programming- History of Java, comments, Data types, Variables, Constants, Scope and Lifetime of variables, Operators, Operator Hierarchy, Expressions, Type conversion and casting, Enumerated types, Control flow- block scope, conditional statements, loops, break and continue statements, simple java stand alone programs, arrays, console input and output, formatting output, constructors, methods, parameter passing, static fields and methods, access control, this reference, overloading methods and constructors, recursion, garbage collection, building strings, exploring string class. UNIT – II Inheritance – Inheritance hierarchies super and sub classes, Member access rules, super keyword, preventing inheritance: final classes and methods, the Object class and its methods. Polymorphism – dynamic binding, method overriding, abstract classes and methods. Interfaces- Interfaces Vs Abstract classes, defining an interface, implement interfaces, accessing implementations through interface references, extending interface. Inner classes- Uses of inner classes, local inner classes, anonymous inner classes, static inner classes, examples. Packages- Defining, creating and accessing a package, Understanding CLASSPATH, importing packages. UNIT-III Exception handling- Dealing with errors, benefits of exception handling, the classification of exceptions- exception hierarchy, checked exceptions and unchecked exceptions, usage of try, catch, throw, throws and finally, rethrowing exceptions, exception specification, built in exceptions, creating own exception sub classes. Multithreading – Differences between multiple processes and multiple threads, thread states, creating threads, interrupting threads, thread priorities, synchronizing threads, inter-thread communication, producer consumer pattern,Exploring java.net and java.text. UNIT-IV Collection Framework in Java – Introduction to java collections, Overview of java collection framework, Generics, Commonly used collection classes- Array List, Vector, Hash table, Stack, Enumeration, Iterator, String Tokenizer, Random, Scanner, Calendar and Properties. Files- Streams- Byte streams, Character streams, Text input/output, Binary input/output, random access file operations, File management using File class. Connecting to Database – JDBC Type 1 to 4 drivers, Connecting to a database, querying a database and processing the results, updating data with JDBC. UNIT-V GUI Programming with Java- The AWT class hierarchy, Introduction to Swing, Swing Vs AWT, Hierarchy for Swing components, Containers – Jframe, JApplet, JDialog, JPanel, Overview of some Swing components – Jbutton, JLabel, JTextField, JTextArea, simple Swing applications, Layout management – Layout manager types – border, grid and flow Event Handling- Events, Event sources, Event classes, Event Listeners, Relationship between Event sources and Listeners, Delegation event model, Examples: Handling a button click, Handling Mouse events, Adapter classes. Applets – Inheritance hierarchy for applets, differences between applets and applications, Life cycle of an applet, Passing parameters to applets, applet security issues. TEXT BOOK: 1. Java Fundamentals – A Comprehensive Introduction, Herbert Schildt and Dale Skrien, TMH. REFERENCE BOOKS: 1. Java for Programmers, P.J.Deitel and H.M.Deitel, PEA (or) Java: How to Program , P.J.Deitel and H.M.Deitel, PHI 2. Object Oriented Programming through Java, P. Radha Krishna, Universities Press. 3. Thinking in Java, Bruce Eckel, PE 4. Programming in Java, S. Malhotra and S. Choudhary, Oxford Universities Press. Course Outcomes: An understanding of the principles and practice of object oriented analysis and design in the construction of robust, maintainable programs which satisfy their requirements; A competence to design, write, compile, test and execute straightforward programs using a high level language; An appreciation of the principles of object oriented programming; An awareness of the need for a professional approach to design and the importance of good documentation to the finished programs. Be able to implement, compile, test and run Java programs comprising more than one class, to address a particular software problem. Demonstrate the ability to use simple data structures like arrays in a Java program. Be able to make use of members of classes found in the Java API (such as the Math class). MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING INDEX S. No Unit Topic Page no 1 OOP Concepts:- Data abstraction, encapsulation inheritance 1 I 2 Benefits of Inheritance 2 I 3 I Polymorphism, classes and objects 2 4 I Procedural and object oriented programming paradigms 3 5 I Java Programming- History of Java 4 6 I Comments, Data types, Variables, Constants 5-9 7 I Scope and Lifetime of variables 10 8 I Operators, Operator Hierarchy, Expressions 11-12 9 I Type conversion and casting, Enumerated types 12-13 Control flow- block scope, conditional statements, loops, break 10 I 13-14 and continue statements 11 I Simple java stand alone programs, arrays 14-18 12 I Console input and output, formatting output 18-19 13 I Constructors, methods, parameter passing 19-20 14 I Static fields and methods, access control, this reference, 21-30 Overloading methods and constructors, recursion, garbage 15 I 30-34 collection, Building strings, exploring string class. 16 I 34-36 S. No Unit Topic Page no Inheritance – Inheritance hierarchies super and sub classes, 17 II 37-40 Member access rules super keyword, preventing inheritance: final classes and 18 II 40-41 methods, the Object class and its methods. 19 II Polymorphism – dynamic binding, method overriding, 41-42 20 II abstract classes and methods. 43 Interfaces- Interfaces Vs Abstract classes, defining an 21 II 43-44 interface, implement interfaces Accessing implementations through interface references, 22 II 45 extending interface. 23 II Inner classes- Uses of inner classes, local inner classes 45-46 24 II Anonymous inner classes, static inner classes, examples. 46 25 II Packages- Defining, creating and accessing a package, 46-47 26 II Understanding CLASSPATH, importing packages. 47 Exception handling- Dealing with errors, benefits of exception 27 III 48 handling The classification of exceptions- exception hierarchy, checked 28 III 48-50 exceptions and unchecked exceptions 29 III Usage of try, catch, throw, throws and finally, 50-54 30 III Rethrowing exceptions, exception specification, 54 31 III Built in exceptions, creating own exception sub classes. 54 Multithreading – Differences between multiple processes and 32 III 55-56 multiple threads, thread states Creating threads, interrupting threads, thread priorities, 33 III 56-59 synchronizing threads 34 III Inter-thread communication, producer consumer pattern 59 35 III Exploring java.net and java.text. 60 S. No Unit Topic Page no Collection Framework in Java – Introduction to java 36 IV 62 collections, Overview of java collection framework, Generics Commonly used collection classes- Array List, Vector, Hash 37 IV 63-71 table, Stack, Enumeration, Iterator 38 IV String Tokenizer, Random, Scanner, Calendar and Properties. 71-76 Files- Streams- Byte streams, Character streams, Text 39 IV 77-82 input/output, Binary input/output Random access file operations, File management using File 40 IV 83-84 class. Connecting to Database – JDBC Type 1 to 4 drivers, 41 IV 85-88 Connecting to a a database, Querying a database and processing the results, updating data 42 IV with JDBC. 89-94 GUI Programming with Java- The AWT class hierarchy, 43 V Introduction to Swing, Swing Vs AWT, Hierarchy for Swing 95-100 components 44 V Containers – Jframe, JApplet, JDialog, JPanel 100-104 Overview of some Swing components – Jbutton, JLabel, 45 V 104-108 JTextField, JTextArea, simple Swing applications, Layout management – Layout manager types – border, grid and 46 V 109-111 flow Event Handling- Events, Event sources, Event classes, Event 47 V 111-112 Listeners, Relationship between Event sources and Listeners, Delegation 48 V 112-113 event model, Handling a button click, Handling Mouse events, Adapter 49 V 114-116 classes. 50 V Applets – Inheritance hierarchy for applets 118-119 Differences between applets and applications, Life cycle of an 51 V 120 applet, 52 V Passing parameters to applets, applet security issues. 121 MALLA