0% found this document useful (0 votes)
48 views

Java Complete Notes

Na
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
48 views

Java Complete Notes

Na
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 125
Save COMPLETE * NOTES Scanned with CamScanner MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY INDEX Topic 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. Scanned with CamScanner Topic 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 pack Understanding CLASSPATH, importing packages, 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 specif 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. Scanned with CamScanner Topic 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- Sweams- Byte streams, Character streams, Text inpuVoutput, Binary input/output Random access file operations, File management using File class. Connecting to Database - JDBC Type | to 4 drivers, Connecting to a a database, Querying a database and processing the results, updating data with JDBC. GUI Programming with Java- The AWT class hierarchy, Introduction to Swing, Swing Vs AWT, Hierarchy for Swing | 95-100 components Containers ~ Jframe, JApplet, JDialog, JPanel 100-104 Overview of some Swing components — Jbutton, JLabel, . JTextField, JTextArea, simple Swing applications, aed Layout management — Layout manager types ~ border, grid and | 99.144 flow Event Handling- Events, Event sources, Event classes, Event 112 Listeners, 1-112 Relationship between Event sources and Listeners, Delegation 2 event model, 112-113, Handling a button click, Handling Mouse events, Adapter 14-116 classes. Applets — Inheritance hierarchy for applets 18-119 Differences between applets and applications, Life cycle of an applet, re Passing parameters to applets, applet security issues. 121 Scanned with CamScanner MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY Unit-1 OOP Concepts Object. Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc. Simula is considered as the first object-oriented programming language. The programming paradigm where everything is represented as an object is known as truly object-oriented programming language. Smalltalk is considered as the first truly object-oriented programming language. 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 Object Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike ete. It can be physical and logical. Class Collection of objects is called class. It is a logical entity. Inheritance ‘When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism, JAVA PROGRAMMING Scanned with CamScanner Polymorphism When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle ete In java, we use method overloading and method overriding to achieve polymorphism. Another example can be to speak something e.g. cat speaks meaw, dog barks woof ete. Abstraction Hiding internal details and showing functionality is known as abstraction. For example: phone call, we don't know the internal processing. In java, we use abstract class and interface to achieve abstraction. Encapsulation Binding (or wrapping) code and data together into a single unit is known as encapsulation For example: capsule, it is wrapped with different medicines. A java class is the example of encapsulation, Java bean is the fully encapsulated class because all the data members are private here. Benefits of Inheritance One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organization of code and smaller, simpler compilation units, + Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass Reusability - facility to use public methods of base class without rewriting the same. Extensibility - extending the base class logic as per business logic of the derived class, JAVA PROGRAMMING Scanned with CamScanner + Data hiding - base class can decide to keep some data private so that it cannot be altered by the derived class Procedural and object oriented program Features Procedural Object Oriented Progr Programming (OOPS) Divided into In POP. program is divided | im OOPs . the program is into smaller parts called as | divided into parts known as functions objects. In POP. importance is not | In OOPs. Importance is given to data but to | given to the data rather than functions as well. as| procedures or fictions sequence of actions to be | because it works as a real Approach POP follows Top Down | OOPs follows Bottom Up approach approach POP docs not have any | OOPs has acce access specifier amed Publi Pr et Data Moving In POP. Data can move | In OOPs. an move freely from fimction to | and communicate with each function in the system other through member Data Access In POP. Most function uses | In OOPs. data can not move Global data for sharing that | easily from function to can be accessed freely from | functionit can be kept function to function in the ate so we can system cess of data POP does not proper way for hi so provides more security so it is less secure Overloading In POP. Overloading is not | In OOPs. overloading is possible in the form o} Function Overloading and Operator Overloa: Examples c JAVA NET. c JAVA PROGRAMMING Scanned with CamScanner Java Programming- History of Java The history of java starts from Green Team. Java team members (also known as Green Team), initiated a revolutionary task to develop a language for digital devices such as set-top boxes, televisions etc. For the green team members, it was an advance concept at that time. But, it was suited for internet programming. Later, Java technology as incorporated by Netscape. Currently, Java is used in internet programming, mobile devices, games, e-business solutions etc, There are given the major points that describes the history 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 .at. 4) After that, it was called Oak and was developed as a part of the Green project. Java Version History ‘There are many java versions that has been released. Current stable release of Java is Java SE 8. 1, JDK Alpha and Beta (1995) 2. JDK 1.0 (23rd Jan, 1996) 3. 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) 10.Java SE 8 (18th March, 2014) JAVA PROGRAMMING Scanned with CamScanner Features of Java There is given many features of java. They are also known as java buzzwords. The Java Features below are simple and easy to understand. Simple Object-Orie Portable Platform independent Secured Robust Se - Architecture neutral High Platform Pertomance $———__, Features of Java, independent eefonmance, lnerpetee 11. Multithreaded oy Robust 12,Distributed amie Architecture Portable Newral Java Comments The java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for specific time. Types of Java Comments ‘There are 3 types of comments in java Single Line Comment Multi Line Comment Documentation Comment Java Single Line Comment ‘The single line comment is used to comment only one lin Syntax: IThis is single line comment JAVA PROGRAMMIN( Scanned with CamScanner Example: public class CommentExample! [ public static void main(Stringt] args) { int i=10,//Here, iis a variable System.out.printin(i); Output: 10 Java Multi Line Comment ‘The multi line comment is used to comment multiple lines of code. Syntax: rp This is multi line comment ” Example: public class CommentExample? [ public static void main(String{] args) { * Let's declare and print variable in java. */ int System.out.printin(i); vy Output: 10 JAVA PROGRAMMIN( Scanned with CamScanner Java Documentation Comment The documentation comment is used to create documentation API. To create documentation API, you need to use javadoc tool Syntax: ” Example: /** The Calculator class provides methods to get addition and subtraction of given 2 numbers.*/ public class Calculator ( /** The add) method returns addition of given numbers.*/ public static int add(int a, int b){return a+b;} /*’The sub() method returns subtraction of given numbers.*/ public static int sub(int a, int b){return ah;) ) Compile it by javac tool: jvac Calculator java Create Documentation API by ja javadoc Calculator java Now, there will be HTML files created for your Calculator class in the current directory. Open the HTML files and see the explanation of Calculator class provided through document JAVA PROGRAMMIN Scanned with CamScanner Data Types Data types represent the different values to be stored in the variable, In java, there are two types of data types: © Primitive data types © Non-primitive Primitive Non-Primitive TS byte shore int Data Type Default Value Default size Java Variable Example: Add Two Numbers class Simple{ public static void main(String{] args)[ int int ystem.out.printin(c); yh Output:20 JAVA PROGRAMMIN( Scanned with CamScanner Variables and Data Types in Java Variable is a name of memory location. There are three types of variables in java: local, instance and statie. ‘There are two types of data types in java: primitive and non-primitive. Types of Variable There are three types of variables in java: © local variable instance variable ce. static variable 1)Local Variable A variable which is declared inside the method is called local variable. 2) Instance Variable A variable which is declared inside the class but outside the method, is called instance variable - It is not declared as static, 3) Statie variable A variable that is declared as static is called static variable. It cannot be local. ‘We will have detailed learning of these variables in next chapters. Example to understand the types of variables in java class A{ int data=50;//instance variable static int m=100;//static variable void method(){ int n=90;//local variable 1 Viend of class Constants in Java A constant is a variable which cannot have its value changed after declaration. It uses the ‘final’ keyword. Syntax modifier final dataType variableName = value; modifier static final dataType variableName = value: JAVA PROGRAMMIN Scanned with CamScanner

You might also like