SlideShare a Scribd company logo
1 of 23
Download to read offline
Java course - IAG0040




              Advanced stuff:
              Ant, Scripting,
             Spring, Hibernate




Anton Keks                            2011
Ant
 ●
     Ant == Another Neat Tool, http://ant.apache.org/
 ●
     In short, it is a cross-platform make for Java
 ●
     Is the de-facto standard build tool for Java projects
 ●   You just have to write an XML file, describing the
     build process
     –   usually named build.xml
     –   Java IDEs provides auto-completion, running, and
         sometimes debugging of Ant build files
 ●
     It is also very good for automating of complex tasks
Java course – IAG0040                                 Lecture 15
Anton Keks                                                Slide 2
Hello, Ant!
 ●   <?xml version="1.0"?>
     <project name="HelloAnt" default="sayHello"
        basedir=".">
        <property name="text.hello"
          value="Hello, Ant!"/>
        <target name="sayHello">
          <echo>${text.hello}</echo>
        </target>
        <target name=”compile” depends=”sayHello”>
          <javac srcdir=”src” destdir=”bin”/>
        </target>
     </project>



Java course – IAG0040                          Lecture 15
Anton Keks                                         Slide 3
Ant essentials
 ●   The root tag is <project> that defines the name of the project
 ●   <property> defines global properties for usage within the file
      –   name and value are mandatory attributes
      –   properties are further referenced as ${name}
 ●   <target> specifies runnable build targets (sequences of
     actions) that can depend on each other
      –   name specifies target's name
      –   if and unless can check whether certain property is set
      –   depends – comma-separated list of other targets
      –   description can be used for documenting
Java course – IAG0040                                       Lecture 15
Anton Keks                                                      Slide 4
Ant essentials (cont)
 ●   Within targets, Ant tasks can be used
      –   There are many predefined tasks, e.g. echo
      –   You can define tasks yourself or run other targets with
          <antcall>
      –   You can use 3rd-party tasks from jar files
 ●   Many tasks use FileSets
      –   they are filters using patterns to select specific files
      –   ? matches a character, * matches zero or more characters, **
          matches zero or more directories (processed recursively)
      –   <fileset dir=”${basedir}” includes=”**/*.java”/>
           ●   <include> and <exclude> can be specified within

Java course – IAG0040                                                Lecture 15
Anton Keks                                                               Slide 5
Most common Ant tasks
●   Filesystem tasks:
     –   copy, delete, get, mkdir, move, rename, touch, chmod
●   Remote tasks:
     –   ftp, scp, sshexec, telnet, setproxy, mail, cvs, cvschangelog
●   Compilation and Deployment:
     –   javac, javadoc, rmic, depend, jar, tar, zip, war, gzip
●   Testing
     –   junit, junitreport
●   Miscellaneous
     –   echo, exec, fail, sleep, buildnumber, condition
●   More info at http://ant.apache.org/manual/tasksoverview.html
●
    Tons of 3rd party tasks available

Java course – IAG0040                                                   Lecture 15
Anton Keks                                                                  Slide 6
Java Scripting
 ●
     Java 1.6 introduced embedded scripting
     –   allows running of scripts inside of the JVM
          ●
              scripts can be written in many languages, e.g.
              JavaScript, Ruby, Groovy, Python, etc
          ●   each language needs its engine to be available
          ●
              JavaScript is available by default (Mozilla Rhino)
     –   Scripts and Java classes can interoperate
 ●   Reasons
     –   Java is a platform, not only a language
     –   interoperability, faster development of non-critical code,
         specific domain usage, etc
Java course – IAG0040                                              Lecture 15
Anton Keks                                                             Slide 7
Java Scripting API
●
    Java Scripting API is in javax.script package
●
    ScriptEngine – interface for implementing of different
    scripting languages
●
    ScriptEngineFactory – interface for implementing
    ScriptEngine factories, provides detailed information about
    the language
●
    ScriptEngineManager – class for registering and obtaining of
    ScriptEngines
●   ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine jsEngine =
         mgr.getEngineByName("JavaScript");
    jsEngine.eval("print('Hello, world!')");
Java course – IAG0040                                  Lecture 15
Anton Keks                                                 Slide 8
Evaluation / Invocation
●   ScriptEngine's eval() method accepts both String and Reader
    –   so the script can come from virtually any source
    –   ScriptEngine engine = mgr.getEngineByExtension("js");
        engine.eval(new InputStreamReader(
           this.getClass().getResourceAsStream(“runme.js”)));
●   Engines implementing Invocable can invoke individual
    functions or methods
    –   engine.eval(   "function sayHello() {" +
                       " println('Hello, world!');" +
                       "}");
        ((Invocable)engine).invokeFunction("sayHello");
●   Engines implementing Compilable can precompile scripts
    –   ((Compilable)engine).compile("print('Hello')").eval();
Java course – IAG0040                                      Lecture 15
Anton Keks                                                     Slide 9
Java Binding
 ●   Java classes are available to scripts and can be used
     using the language's syntax, e.g. JavaScript:
     –   importPackage(java.util)
         var javaDate = new Date()
         var dateString = javaDate.toString()
 ●
     ScriptEngine provides put() and get() methods for
     storing/retrieving bound variables
     –   engine.put(“javaDate”, new Date());
         engine.eval(“print(javaDate.toString())”);
 ●   Objects can be returned from scripts to Java using the
     return from eval() or invokeXXX() methods as Objects
     –   Rhino maps numbers to Double, strings to String
Java course – IAG0040                                      Lecture 15
Anton Keks                                                   Slide 10
Spring Framework
 ●   http://www.springframework.org/
 ●   The leading full-stack Java/J2EE application framework
 ●
     Spring delivers significant benefits for many projects, reducing
     development effort and costs while improving test coverage
     and quality
 ●   Was created as an alternative/companion to J2EE
      –   J2EE should be easier to use
      –   Reduces the complexity cost of using interfaces to zero
      –   JavaBeans offer a great way of configuring applications
      –   OO design is more important than any implementation technology
      –   Checked exceptions are overused in Java
      –   Testability is essential
Java course – IAG0040                                               Lecture 15
Anton Keks                                                            Slide 11
Spring Features
 ●
     Advertised features:
      –   The most complete lightweight container
      –   A common abstraction layer for transaction management
      –   A JDBC abstraction layer
      –   Integration with Hibernate, Toplink, JDO, and iBATIS
      –   AOP functionality
      –   A flexible MVC web application framework
 ●
     Most of these can be used in both Java SE and Java EE
 ●
     Spring allows for reusable business and data access objects
     that are not tied to specific services (POJO-based approach)

Java course – IAG0040                                        Lecture 15
Anton Keks                                                     Slide 12
Spring Overview




Java course – IAG0040                     Lecture 15
Anton Keks                                  Slide 13
AOP
 ●
     Aspect-Oriented Programming
     –   a new approach to programming since OOP
 ●   Solves the problem of cross-cutting concerns in the
     code, e.g. logging or database transactions spread in
     different places
     –   Usually there is functionality that is spread in many places
     –   AOP allows to write this code as an aspect
     –   Aspects alter the behavior of base-code by applying advice
         (additional behavior) over a quantification of join points
     –   Join points are points in the structure or execution of a
         program; they are specified using pointcuts (descriptions
         of sets of join points)
Java course – IAG0040                                         Lecture 15
Anton Keks                                                      Slide 14
Dependency Injection / IoC
 ●
     Dependency Injection == Inversion of Control (IoC)
     –   is a design pattern upon which Spring's core is based
 ●
     Is a way to achieve loose coupling
     –   it allows for complete separation of interfaces and
         implementations
     –   concrete implementations of classes are injected on
         demand as configured
     –   responsibility of object creation is removed from objects
 ●   Spring defines BeanFactory for that purpose
 ●   The container (BeanFactory) injects dependencies
     into beans hence the term IoC
Java course – IAG0040                                            Lecture 15
Anton Keks                                                         Slide 15
BeanFactories
 ●   BeanFactory actually instantiates, configures, and manages state of
     beans
 ●
     There are several default implementations
      –   XmlBeanFactory – bean definitions are in XML files
      –   DefaultListableBeanFactory – bean definitions specified
          programmatically
 ●
     XmlBeanFactory loads XML bean definition file from a specified
     Resource, i.e. FileSystemResource, ClassPathResource, UrlResource,
     etc
 ●
     ApplicationContext is an extension to BeanFactory, providing
     additional more complex features
 ●   The following basic methods are provided: getBean, getType,
     isSingleton, containsBean
Java course – IAG0040                                               Lecture 15
Anton Keks                                                            Slide 16
Bean definition XML
 ●   Bean definition file:
     <?xml version="1.0" encoding="UTF-8"?>
     <beans xmlns="http://www.springframework.org/schema/beans">
        <bean id="..." class="...">...</bean>
        <bean id="..." class="...">...</bean>
        ...
     </beans>
 ●   Many beans can be defined and configured this way
 ●   Beans define class names, properties, constructor arguments, collaborator
     beans (dependencies), etc
 ●   Beans can be singletons (scope=”singleton”, default) or prototypes
 ●   Autowiring means injection of dependencies automatically either byName or
     byType (autowire attribute, default is none)
 ●   A bean can have FactoryBean specified that creates bean instances


Java course – IAG0040                                                  Lecture 15
Anton Keks                                                               Slide 17
ORM
 ●
     Object-Relational Mapping
      –   links relational databases to object-oriented language concepts,
          creating a “virtual object database”
 ●   The goal is to be able to store and retrieve Java objects or
     their hierarchies using the database
 ●   The most basic scenario:
      –   Java class corresponds to a DB table
      –   Class fields correspond to columns in the table
      –   Java object (instance) corresponds to a row in the table
 ●
     Basic usage (storing and retrieving):
      –   orm.save(myObject);
      –   myObject = orm.load(MyObject.class, objectId);
Java course – IAG0040                                                Lecture 15
Anton Keks                                                             Slide 18
Hibernate
 ●
     http://www.hibernate.org/
 ●
     Is the de-facto standard open-source ORM
     (Object-Relational Mapping) tool
     –   Lets you develop persistent classes following OO
         idiom, including association, inheritance,
         polymorphism, composition, and collections
     –   Provides its own portable object-oriented HQL
         language in addition to native SQL as well as Criteria
         and Example APIs
 ●
     Can be used for persisting of POJOs to database
Java course – IAG0040                                  Lecture 15
Anton Keks                                               Slide 19
Hibernate Mapping
 ●
     Mappings are usually expressed as XML files
 ●   Mapping of class Dog to table DOGS using mapping file Dog.hbm.xml:
 ●   <?xml version="1.0"?>
     <!DOCTYPE hibernate-mapping PUBLIC
     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     <hibernate-mapping>
        <class name="net.azib.Dog" table="DOGS">
            <id name="id" column="uid" type="long">
               <generator class="increment"/>
            </id>
            <property name="name"/>
            <property name="dateOfBirth" type="date"/>
            <property name="weight" column="mass"/>
        </class>
     </hibernate-mapping>


Java course – IAG0040                                            Lecture 15
Anton Keks                                                         Slide 20
Hibernate Sessions
 ●
     Session is a conversation between the application and the
     persistent store (short-lived, single-threaded)
      –   wraps and hides the real JDBC connection
      –   is used for storing/retrieving of persistent objects
 ●
     SessionFactory is used for creation of Sessions. It caches
     compiled mappings (long-lived, thread-safe)
 ●
     Persistent objects are POJOs, they can be attached to a Session
      –   Upon retrieval, objects are automatically attached to the
          session
      –   Attached objects are automatically checked for changes and
          stored if needed
 ●   Session provides methods like: get, load, save, update, find, etc
Java course – IAG0040                                            Lecture 15
Anton Keks                                                         Slide 21
Hibernate basic overview




Java course – IAG0040                 Lecture 15
Anton Keks                              Slide 22
Hibernate complex example




Java course – IAG0040           Lecture 15
Anton Keks                        Slide 23

More Related Content

What's hot

Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Kernel Training
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeOmar Bashir
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java CertificationVskills
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsMahika Tutorials
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIAnton Keks
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz SAurabh PRajapati
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machineLaxman Puri
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)Shaharyar khan
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platformsIlio Catallo
 

What's hot (20)

Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
An Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and RuntimeAn Introduction to Java Compiler and Runtime
An Introduction to Java Compiler and Runtime
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java Certification
 
Core java
Core java Core java
Core java
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Core Java
Core JavaCore Java
Core Java
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Java basic
Java basicJava basic
Java basic
 
Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUI
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Core java
Core javaCore java
Core java
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
Java features
Java featuresJava features
Java features
 
Java training in delhi
Java training in delhiJava training in delhi
Java training in delhi
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
 

Similar to Java Course 15: Ant, Scripting, Spring, Hibernate

Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentationdhananajay95
 
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Vadym Kazulkin
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design PatternsAnton Keks
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containersDocker, Inc.
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Arun Gupta
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And BeyondVMware Tanzu
 
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Dan Allen
 
02-Java Technology Details.ppt
02-Java Technology Details.ppt02-Java Technology Details.ppt
02-Java Technology Details.pptJyothiAmpally
 
Notes of java first unit
Notes of java first unitNotes of java first unit
Notes of java first unitgowher172236
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxMurugesh33
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxMurugesh33
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010JUG Lausanne
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept Prakash Poudel
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
JAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptxJAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptx20EUEE018DEEPAKM
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsQUONTRASOLUTIONS
 

Similar to Java Course 15: Ant, Scripting, Spring, Hibernate (20)

Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentation
 
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containers
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
 
02-Java Technology Details.ppt
02-Java Technology Details.ppt02-Java Technology Details.ppt
02-Java Technology Details.ppt
 
Notes of java first unit
Notes of java first unitNotes of java first unit
Notes of java first unit
 
Java introduction
Java introductionJava introduction
Java introduction
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
JAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptxJAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptx
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
 

More from Anton Keks

Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software testerAnton Keks
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyAnton Keks
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionAnton Keks
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsAnton Keks
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsAnton Keks
 
Choose a pattern for a problem
Choose a pattern for a problemChoose a pattern for a problem
Choose a pattern for a problemAnton Keks
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database RefactoringAnton Keks
 
Scrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerScrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerAnton Keks
 
Being a Professional Software Developer
Being a Professional Software DeveloperBeing a Professional Software Developer
Being a Professional Software DeveloperAnton Keks
 

More from Anton Keks (10)

Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software tester
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and Concurrency
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and Reflection
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, Assertions
 
Choose a pattern for a problem
Choose a pattern for a problemChoose a pattern for a problem
Choose a pattern for a problem
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database Refactoring
 
Scrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerScrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineer
 
Being a Professional Software Developer
Being a Professional Software DeveloperBeing a Professional Software Developer
Being a Professional Software Developer
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Java Course 15: Ant, Scripting, Spring, Hibernate

  • 1. Java course - IAG0040 Advanced stuff: Ant, Scripting, Spring, Hibernate Anton Keks 2011
  • 2. Ant ● Ant == Another Neat Tool, http://ant.apache.org/ ● In short, it is a cross-platform make for Java ● Is the de-facto standard build tool for Java projects ● You just have to write an XML file, describing the build process – usually named build.xml – Java IDEs provides auto-completion, running, and sometimes debugging of Ant build files ● It is also very good for automating of complex tasks Java course – IAG0040 Lecture 15 Anton Keks Slide 2
  • 3. Hello, Ant! ● <?xml version="1.0"?> <project name="HelloAnt" default="sayHello" basedir="."> <property name="text.hello" value="Hello, Ant!"/> <target name="sayHello"> <echo>${text.hello}</echo> </target> <target name=”compile” depends=”sayHello”> <javac srcdir=”src” destdir=”bin”/> </target> </project> Java course – IAG0040 Lecture 15 Anton Keks Slide 3
  • 4. Ant essentials ● The root tag is <project> that defines the name of the project ● <property> defines global properties for usage within the file – name and value are mandatory attributes – properties are further referenced as ${name} ● <target> specifies runnable build targets (sequences of actions) that can depend on each other – name specifies target's name – if and unless can check whether certain property is set – depends – comma-separated list of other targets – description can be used for documenting Java course – IAG0040 Lecture 15 Anton Keks Slide 4
  • 5. Ant essentials (cont) ● Within targets, Ant tasks can be used – There are many predefined tasks, e.g. echo – You can define tasks yourself or run other targets with <antcall> – You can use 3rd-party tasks from jar files ● Many tasks use FileSets – they are filters using patterns to select specific files – ? matches a character, * matches zero or more characters, ** matches zero or more directories (processed recursively) – <fileset dir=”${basedir}” includes=”**/*.java”/> ● <include> and <exclude> can be specified within Java course – IAG0040 Lecture 15 Anton Keks Slide 5
  • 6. Most common Ant tasks ● Filesystem tasks: – copy, delete, get, mkdir, move, rename, touch, chmod ● Remote tasks: – ftp, scp, sshexec, telnet, setproxy, mail, cvs, cvschangelog ● Compilation and Deployment: – javac, javadoc, rmic, depend, jar, tar, zip, war, gzip ● Testing – junit, junitreport ● Miscellaneous – echo, exec, fail, sleep, buildnumber, condition ● More info at http://ant.apache.org/manual/tasksoverview.html ● Tons of 3rd party tasks available Java course – IAG0040 Lecture 15 Anton Keks Slide 6
  • 7. Java Scripting ● Java 1.6 introduced embedded scripting – allows running of scripts inside of the JVM ● scripts can be written in many languages, e.g. JavaScript, Ruby, Groovy, Python, etc ● each language needs its engine to be available ● JavaScript is available by default (Mozilla Rhino) – Scripts and Java classes can interoperate ● Reasons – Java is a platform, not only a language – interoperability, faster development of non-critical code, specific domain usage, etc Java course – IAG0040 Lecture 15 Anton Keks Slide 7
  • 8. Java Scripting API ● Java Scripting API is in javax.script package ● ScriptEngine – interface for implementing of different scripting languages ● ScriptEngineFactory – interface for implementing ScriptEngine factories, provides detailed information about the language ● ScriptEngineManager – class for registering and obtaining of ScriptEngines ● ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine jsEngine = mgr.getEngineByName("JavaScript"); jsEngine.eval("print('Hello, world!')"); Java course – IAG0040 Lecture 15 Anton Keks Slide 8
  • 9. Evaluation / Invocation ● ScriptEngine's eval() method accepts both String and Reader – so the script can come from virtually any source – ScriptEngine engine = mgr.getEngineByExtension("js"); engine.eval(new InputStreamReader( this.getClass().getResourceAsStream(“runme.js”))); ● Engines implementing Invocable can invoke individual functions or methods – engine.eval( "function sayHello() {" + " println('Hello, world!');" + "}"); ((Invocable)engine).invokeFunction("sayHello"); ● Engines implementing Compilable can precompile scripts – ((Compilable)engine).compile("print('Hello')").eval(); Java course – IAG0040 Lecture 15 Anton Keks Slide 9
  • 10. Java Binding ● Java classes are available to scripts and can be used using the language's syntax, e.g. JavaScript: – importPackage(java.util) var javaDate = new Date() var dateString = javaDate.toString() ● ScriptEngine provides put() and get() methods for storing/retrieving bound variables – engine.put(“javaDate”, new Date()); engine.eval(“print(javaDate.toString())”); ● Objects can be returned from scripts to Java using the return from eval() or invokeXXX() methods as Objects – Rhino maps numbers to Double, strings to String Java course – IAG0040 Lecture 15 Anton Keks Slide 10
  • 11. Spring Framework ● http://www.springframework.org/ ● The leading full-stack Java/J2EE application framework ● Spring delivers significant benefits for many projects, reducing development effort and costs while improving test coverage and quality ● Was created as an alternative/companion to J2EE – J2EE should be easier to use – Reduces the complexity cost of using interfaces to zero – JavaBeans offer a great way of configuring applications – OO design is more important than any implementation technology – Checked exceptions are overused in Java – Testability is essential Java course – IAG0040 Lecture 15 Anton Keks Slide 11
  • 12. Spring Features ● Advertised features: – The most complete lightweight container – A common abstraction layer for transaction management – A JDBC abstraction layer – Integration with Hibernate, Toplink, JDO, and iBATIS – AOP functionality – A flexible MVC web application framework ● Most of these can be used in both Java SE and Java EE ● Spring allows for reusable business and data access objects that are not tied to specific services (POJO-based approach) Java course – IAG0040 Lecture 15 Anton Keks Slide 12
  • 13. Spring Overview Java course – IAG0040 Lecture 15 Anton Keks Slide 13
  • 14. AOP ● Aspect-Oriented Programming – a new approach to programming since OOP ● Solves the problem of cross-cutting concerns in the code, e.g. logging or database transactions spread in different places – Usually there is functionality that is spread in many places – AOP allows to write this code as an aspect – Aspects alter the behavior of base-code by applying advice (additional behavior) over a quantification of join points – Join points are points in the structure or execution of a program; they are specified using pointcuts (descriptions of sets of join points) Java course – IAG0040 Lecture 15 Anton Keks Slide 14
  • 15. Dependency Injection / IoC ● Dependency Injection == Inversion of Control (IoC) – is a design pattern upon which Spring's core is based ● Is a way to achieve loose coupling – it allows for complete separation of interfaces and implementations – concrete implementations of classes are injected on demand as configured – responsibility of object creation is removed from objects ● Spring defines BeanFactory for that purpose ● The container (BeanFactory) injects dependencies into beans hence the term IoC Java course – IAG0040 Lecture 15 Anton Keks Slide 15
  • 16. BeanFactories ● BeanFactory actually instantiates, configures, and manages state of beans ● There are several default implementations – XmlBeanFactory – bean definitions are in XML files – DefaultListableBeanFactory – bean definitions specified programmatically ● XmlBeanFactory loads XML bean definition file from a specified Resource, i.e. FileSystemResource, ClassPathResource, UrlResource, etc ● ApplicationContext is an extension to BeanFactory, providing additional more complex features ● The following basic methods are provided: getBean, getType, isSingleton, containsBean Java course – IAG0040 Lecture 15 Anton Keks Slide 16
  • 17. Bean definition XML ● Bean definition file: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"> <bean id="..." class="...">...</bean> <bean id="..." class="...">...</bean> ... </beans> ● Many beans can be defined and configured this way ● Beans define class names, properties, constructor arguments, collaborator beans (dependencies), etc ● Beans can be singletons (scope=”singleton”, default) or prototypes ● Autowiring means injection of dependencies automatically either byName or byType (autowire attribute, default is none) ● A bean can have FactoryBean specified that creates bean instances Java course – IAG0040 Lecture 15 Anton Keks Slide 17
  • 18. ORM ● Object-Relational Mapping – links relational databases to object-oriented language concepts, creating a “virtual object database” ● The goal is to be able to store and retrieve Java objects or their hierarchies using the database ● The most basic scenario: – Java class corresponds to a DB table – Class fields correspond to columns in the table – Java object (instance) corresponds to a row in the table ● Basic usage (storing and retrieving): – orm.save(myObject); – myObject = orm.load(MyObject.class, objectId); Java course – IAG0040 Lecture 15 Anton Keks Slide 18
  • 19. Hibernate ● http://www.hibernate.org/ ● Is the de-facto standard open-source ORM (Object-Relational Mapping) tool – Lets you develop persistent classes following OO idiom, including association, inheritance, polymorphism, composition, and collections – Provides its own portable object-oriented HQL language in addition to native SQL as well as Criteria and Example APIs ● Can be used for persisting of POJOs to database Java course – IAG0040 Lecture 15 Anton Keks Slide 19
  • 20. Hibernate Mapping ● Mappings are usually expressed as XML files ● Mapping of class Dog to table DOGS using mapping file Dog.hbm.xml: ● <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="net.azib.Dog" table="DOGS"> <id name="id" column="uid" type="long"> <generator class="increment"/> </id> <property name="name"/> <property name="dateOfBirth" type="date"/> <property name="weight" column="mass"/> </class> </hibernate-mapping> Java course – IAG0040 Lecture 15 Anton Keks Slide 20
  • 21. Hibernate Sessions ● Session is a conversation between the application and the persistent store (short-lived, single-threaded) – wraps and hides the real JDBC connection – is used for storing/retrieving of persistent objects ● SessionFactory is used for creation of Sessions. It caches compiled mappings (long-lived, thread-safe) ● Persistent objects are POJOs, they can be attached to a Session – Upon retrieval, objects are automatically attached to the session – Attached objects are automatically checked for changes and stored if needed ● Session provides methods like: get, load, save, update, find, etc Java course – IAG0040 Lecture 15 Anton Keks Slide 21
  • 22. Hibernate basic overview Java course – IAG0040 Lecture 15 Anton Keks Slide 22
  • 23. Hibernate complex example Java course – IAG0040 Lecture 15 Anton Keks Slide 23