670 likes | 676 Views
Learn about the essential building blocks of Java programming, from expressions and variables to control structures, classes, objects, methods, inheritance, interfaces, and packages. Understand Java's unique features like platform independence, object-oriented design, and multithreading.
E N D
Unit –I:java Fundamentals MC5304-PROGRAMMING WITH JAVA REGULATION-2017
Java Features • Simple • Object-oriented • Platform Independent • Dynamic and distributed • Multithreaded
Java Platform • Java Language: Like any programming language, the java language has its own structure ,syntax , rules. • Java Compiler: when you program for the java platform , you write source code in .java files and then compile them . • Java virtual Machine(JVM): JVM intercepts the byte code into the machine code. • Garbage Collector : Garbage collector will automatically removes unused objects from the memory. • Java Development Kit: JDK contains tools needed to devlep the java programs.
Expression • Expression are essential building blocks of any java program. • They are built using variables, values, operators and method calls . • Expressions produce values as results and will be used as part of another expression or in a statement.
Comments • Comments should be used to give overview of code and provide additional information that is not readily available in the code it self
Variables • Variable is a name o memory location • Variable is name of reserved area allocated in memory
Data Types • Data types defines a set of permitted values on which the legal operations can be performed. • In ,java all the variables needs to be declared in first before using particular variables.
Keywords • In the java programming language , a keyword is one of 50 reserved words. • Already predefined to it so the user cannot able to change it • Example: void , return etc.
Operators: • Operators are special characters used to instruct the java compiler to perform an operations on one , two , or three operands. • The operators are: • Arithmetic Operators • Assignment Operators • Relational operators • Logical operators • Conditional operator • Bitwise and Bit Shift operator • Increment and decrement operator
Control structures • Java control statements control the order of execution in a java program based on data values and conditional logic. • Basically control statements are define in two ways: • 1)Decision making/Selection statement: • I )If Statement • ii)If else statement • iii) switch statement • 2) looping statement: • i) for loop • ii) while loop • iii) do…. While loop
Decision making statements • Decision / selection statements provide the means of choosing between two more execution paths in a program. Such statements are fundamental and essential parts of all programming languages . • Basic statements are ; • i) if statement • ii) if else statement • iii) switch statement
Loops • Loops means repeating the statements un till some of the specified conditions are satisfied . • Looping statements are: • i) For loop • ii) while loop • iii) do….while loop
Class and Objects • A class can be defined as a template/blue print that describes the behaviors /states that object of its type support. • Class is a collection objects. • Object are the real time entities , which take/ occupies memory place. • Object is used to access class members .
Methods • A java method is equivalent to a function ,procedures , or subroutines in other languages , except that it must be defined inside a class definition • In the other word, there is no support for global methods in java; every method must be defined with in a class
Inheritance • Inheritance can be defined at the process where one object acquires the properties of another . • Inheritance is a way to form new classes using classes. • The new class is known as derived class. • Old class is known is known parent class: • Types of inheritance: • Single inheritance • Multiple inheritance • Hieararchal inheritance
Interface • In the java programming language ,an interface is reference type, similar to a class that can contain only constants, methods signatures , and nested types. • Interface cannot be instantiated – they can only ne implemented by classes or extended by other interface. • An interface defines a protocol of communications between two objects • An interface declaration contains signatures, but no implementations, for a set of methods ,and might also contain constant definitions. • Interface can be implemented using implements keyword . • Interface extended using extend keyword .
Package • A package is a grouping of related types of providing access protection and namespace management . • The types refer to classes , interfaces , enumerations and annotation types • To import package we have use the import statement. • There are two types of package: • 1) Built in package • 2) user-defined package
Boxing and Un boxing • Boxing is the process of converting a primitive type data into its corresponding wrapper class object instance . • Un boxing is the process of converting wrapper instance into its primitive type • Java auto boxing and un boxing features
Variable length arguments • In java, a method can talk a variable number of arguments. • This feature is called varargs and the method that takes a variable number of arguments is called a varargs method . • The varargs allow he method to accept zero or multiple arguments .
Exception handling • The java programming language users exceptions to handles errors and other exceptional events. • An exception is an event that occurs during the execution of a program that disrupts the normal floe of instructions . • To handle exception java provides exception handling mechanism.
Introduction to collection • A collection represents a group of objects , known as ist elements. • Some collection allow duplicate elements and others do not • Some are ordered and unordered • It provides implementations of more specific sub interfaces like set and list
Hierarchy of collection framework • When designing software with the collections framework, it is useful to remember the relationships of the basic interfaces of the framework • The entire collections framework is divided into four interfaces. • List: It handles sequential list of objects • Queue: It handles special list of objects in which elements are removed only from the head. • Set: It handles list if objects which must contain unique element. • map: this is the one interface in collection framework which is not inherited form collection interface .
Generics • Generics in java allow application to create classes and objects that can operate on any defined types • There is no need for un necessary casting when deaking with objects in a collection • Generics have types of the parameters T ,E ,K ,N ,V
ArrayList • Java array list uses a dynamic array for storing the elements . • It inherits abstract list class and implements List interface • Java array list class contains duplicate elements. • Java array list class maintains insertion order
Linked list • The linked list class extends abstract sequential list and implements the list interface • It provides linked list data structures • It can be dyanmic
Hashset • Hash set in java is a collection which implements set interface and backed by an hash map • It performs operations like add , remove , contains and size • It permits null element
Treeset • Tree set provides an implementation of the set interface that uses a tree for storage • Objects stored in sorted ,ascending order . • Access and retrieval times are quite fast , which makes tree set an excellent choice • When storing large amount of sorted information that must be found quickly
Hashmap • Java hash map class implements the map interface by using a hash table. • It inherits Abstract map class and implements map interface • A hash map contains values based on the key • It contains only unique elements
Tree map • Java tree map class implements the map interface by using a tree • It provides an efficient means of storing key/value pairs in sorted order • A tree map contains values based on the key . • It implements the navigable map interface and extends Abstract map class
Comparators • A object is capable of composing two different objects • The class is not comparing its instances , but other class instances • The comparator class implements the java.util.Comparator.interface
Java Annotation(Meta Data) • Annotation is a rag that represents the metadata. • It is attached with class , interface ,methods or fields to indicate some additional information that can be used by java compiler and JVM • Annotations provides data about a program that is not part of the program itself. • Annotations has two types: • Built in annotation • User defined annotation
Premain method • Java agent is a regular java class which follows a strict conventions • Agent class contains the premain method and that is key in java instrumentation. • This is similar to main method
Input and Output packages • The java .io . Package provides an extensive library of classes for dealing with input and output. • Java provides streams as a general mechanism for dealing with data I/O • Streams implements sequential access of data. • It provide input to and get output from the system
Input stream • The java. util. input stream class is the super class of all classes representing an input stream of bytes . • Applications that need to define a subclass of Input stream must always provide a method that returns the next byte of input • It uses public inputstram()
Output Stream • The java. util .Output stream class is the super classes representing an output stream of bytes. • An output stream accepts output bytes and sends them to some link. • It uses public output Stream()
Inner classes • Inner classes are the non static member classes. • Non static inner classes are defined without the keyword static • It also nested any depth. • Method s of non static inner class can directly refer to any member of any enclosing class , including private members.
JDBC Database Connectivity • JDBC is java application programming interface that allows the java programmers to access database using java code • It was developed by java soft, a subsidairy of sun micro systems .it is a java API which enables the java programs to execute SQL statements • Generally all relational database management system supports SQL and JDBC make it possible to write a single database application • It provides four types of drivers
JDBC connectivity with Mysql • The java . sql package contains the entire JDBC API that sends SQL statements to relational databases and retrieves the results of executing those SQL commands • It provides set of steps to connect with sql.
Prepared statement & Result set • To retrieve the data out of the result set and into a java variable , one needs to use one of the result set “get” methods • The “get “ methods retrieves the data from the result set and converts it to java type • Each get method is used to retrieve a different java type • The prepared statement interface extends the statement interface which gives you added functionality with a couple of advantage over a generic statement object
JDBC Stored procedures/collable statement • A stored procedure is a group of SQL statements that form a logical unit and perform a particular task, and they are used to encapsulate a set of operations or queries to execute on a database server • Stored procedure can be compiled and executed with different parameters and results , and they can have any combination of input , output and input/output parameters
Servlets • Servlets are java programs running on a web server that procedure results viewed remotely on a web server • Java servlet technology provides web developers with a simple, consistent mechanism for extending the functionality of a webserver • Servlet can also access a library of HTTP- specific calls and receive all the benefits of the mature java language
RMI(Remote Method Invocation) • The remote method invocation (RMI) is an API that provides a mechanism to create distributed application in java. • The RMI allows an object to invoke methods on an object running in another JVM • The RMI provides remote communication between the applications using two objects sub and Skeleton • Remote Method Invocations facilities object function calls between java virtual Machine (JVM)
Swing fundamentals • “swing” is a set of classes that provides more powerful and flexible components that are possible with “AWT” • Familiar components , such as buttons, check boxes, and labels , swing supplies several exciting additions , including tabbed panes , scroll panes , trees , and tables . • Familiar components such as button have more capabilities
Swing Classes • The class J component , descended directly from container which is the root class for most of swing’s user interface components • Swing components that one will use to build a GUI. • The Swing toolkit includes a rich set of components for building GUIs and adding interactivity to java applications • Swing includes all components such as tree controls , buttons , labels
Java servers • There are two types of servers: • 1). Web server • 2)Application server • Web server: It contains only web or servlet container . It can be used for servlet , jsp, structs, jsfect. • It is a computer where the web content can be stored. • Examples : Apache tomcat and resin . • Application server : Application servers contains web and EJB containers . • It can be used for servlet , jsp ,strcuts ,jsf etc. • It is a component based product that lies in the middle • Tier of a server centric architetcture. • Example of application server : • Jboss , Glassfish , Weblogic , Websphere • It provides the middleware services for state maintanence and security
Containers • A component runs with in a context called container. • The container is an important component of web application in java based java EE technology • It is responsible for maintaining the individual components on the server side ,which include java servlets, java server pages (jsp) and java server faces(jsf) • How the services will be provided and accessed is determined by a contract, which is an agreement between the web application and the container
Creating web application using servlet/ jsp • Servlets are java programs running on a web server that produce results viewed remotely on a web server • Servlet technology provides web developers with a simple , consistent mechanism for extending the functionality of a web server and for accessing existing business systems • Servlet uses javax.servlet , javax. Servlet.http • Jsp or java server page was developed by sun micro systems . • Jsp technology is object –oriented programming language and is based on java technology • Jsp is a server side technology that allows software developers to create dynamically generated web pages , with HTML , XML or other document types in response to a web client request to a java web application container (server)