Java Tutorial

Total Page:16

File Type:pdf, Size:1020Kb

Java Tutorial Java Tutorial JAVA TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com ABOUT THE TUTORIAL Java Tutorial Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding ofJava. This reference will take you through simple and practical approach while learning Java Programming language. Audience This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to Java Programming language. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program and what is a computer programming language? Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] TUTORIALS POINT Simply Easy Learning Table of Content Java Tutorial ............................................................................ 2 Audience .................................................................................. 2 Prerequisites ............................................................................ 2 Copyright & Disclaimer Notice .................................................. 2 Java Overview ....................................................................... 15 History of Java: ........................................................................................ 16 Tools you will need: ................................................................................. 16 What is Next? .......................................................................................... 16 Java Environment Setup ........................................................ 17 Setting up the path for windows 2000/XP: ............................................... 17 Setting up the path for windows 95/98/ME: ............................................. 17 Setting up the path for Linux, UNIX, Solaris, FreeBSD: ........................... 17 Popular Java Editors: .............................................................................. 18 What is Next? .......................................................................................... 18 Java Basic Syntax .................................................................. 19 First Java Program: ................................................................................. 19 Basic Syntax: ........................................................................................... 20 Java Identifiers: ....................................................................................... 20 Java Modifiers: ........................................................................................ 21 Java Variables: ........................................................................................ 21 Java Arrays:............................................................................................. 21 Java Enums: ............................................................................................ 21 Example: ................................................................................................. 21 Java Keywords: ....................................................................................... 22 Comments in Java ................................................................................... 22 Using Blank Lines: ................................................................................... 22 Inheritance: .............................................................................................. 22 Interfaces: ................................................................................................ 23 What is Next? .......................................................................................... 23 Java Object & Classes ........................................................... 24 Objects in Java: ....................................................................................... 24 Classes in Java: ...................................................................................... 25 Constructors: ........................................................................................... 25 Singleton Classes .................................................................................... 26 Implementing Singletons: ........................................................................ 26 Example 1:............................................................................................... 26 Example 2:............................................................................................... 26 TUTORIALS POINT Simply Easy Learning Creating an Object: .................................................................................. 27 Accessing Instance Variables and Methods: ........................................... 27 Example: ................................................................................................. 28 Source file declaration rules: ................................................................... 28 Java Package: ......................................................................................... 29 Import statements: ................................................................................... 29 A Simple Case Study: .............................................................................. 29 What is Next? .......................................................................................... 31 Java Basic Data Types .......................................................... 32 Primitive Data Types: .............................................................................. 32 byte: ......................................................................................................... 32 short: ....................................................................................................... 32 int: ............................................................................................................ 33 long: ......................................................................................................... 33 float: ......................................................................................................... 33 double: ..................................................................................................... 34 boolean: ................................................................................................... 34 char: ........................................................................................................ 34 Reference Data Types: ............................................................................ 34 Java Literals: ........................................................................................... 35 What is Next? .......................................................................................... 36 Java Variable Types ............................................................... 37 Local variables: ........................................................................................ 37 Example: ................................................................................................. 38 Example: ................................................................................................. 38 Instance variables: ................................................................................... 38 Example: ................................................................................................. 39 Class/static variables: .............................................................................. 40 Example: ................................................................................................. 40 What is Next? .......................................................................................... 41 Java Modifier Types ............................................................... 42 1. Java Access Modifiers ......................................................................... 42 Default Access Modifier - No keyword: .................................................... 42 Example: ................................................................................................. 42 Private Access Modifier - private: ............................................................ 43 Example: ................................................................................................. 43 Public Access Modifier - public: ............................................................... 43 Example: ................................................................................................. 43 Protected Access Modifier - protected: .................................................... 43 TUTORIALS POINT Simply Easy Learning Example: ................................................................................................
Recommended publications
  • Hibernate ORM Query Simplication Using Hibernate
    2016 3rd National Foundation for Science and Technology Development Conference on Information and Computer Science Hibernate ORM Query Simplication Using Hibernate Criteria Extension (HCE) Kisman Sani M. Isa Master of Information Technology Master in Computer Science Bina Nusantara University Bina Nusantara University Jl. Kebon Jeruk Raya No. 27, Jakarta Barat, DKI Jl. Kebon Jeruk Raya No. 27, Jakarta Barat, DKI Jakarta, Indonesia 11530 Jakarta, Indonesia 11530 [email protected] [email protected] Abstract— Software development time is a critical issue interfaced by a query. The software engineer will make in software development process, hibernate has been the query specified to database used. Each database widely used to increase development speed. It is used in vendor has their Structured Query Language (SQL). As database manipulation layer. This research develops a the development of software technology and most of library to simplify hibernate criteria. The library that is programming languages are object oriented, some called as Hibernate Criteria Extension (HCE) provides API functions to simplify code and easily to be used. Query engineer or software institutions try to simplify the associations can be defined by using dot. The library will query process. They try to bind object in application to automatically detect the join association(s) based on database. This approach is called as Object Relational mapping in entity class. It can also be used in restriction Mapping (ORM). ORM is a translation mechanism from and order. HCE is a hibernate wrapper library. The object to relational data, vice versa. ORM has “dialect” configuration is based on hibernate configuration.
    [Show full text]
  • Cloud-TM Companion Document For
    Cloud-TM Specific Targeted Research Project (STReP) Contract no. 257784 Companion document for deliverable D2.2: Preliminary Prototype of the RDSTM and RSS Date of preparation: 10 June 2010 Start date of project: 1 June 2010 Duration: 36 Months Contributors Emmanuel Bernard, Red Hat Joao Cachopo, INESC-ID Mark Little, Red Hat Francesco Quaglia, CINI Paolo Romano, INESC-ID Vittorio A. Ziparo, ALGORITHMICA Manik Surtani, Red Hat Sanne Grinovero, Red Hat Fabio Cottefoglie, ALGORITHMICA —————————————————— (C) 2010 Cloud-TM Consortium. Some rights reserved. This work is licensed under the Attribution-NonCommercial-NoDerivs 3.0 Creative Commons License. See http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode for details. Table of Contents 1 Introduction 4 1.1 Relationship with other deliverables . .4 2 Architectural Overview of the Cloud-TM Preliminary Prototype 6 2.1 TorqueBox . .6 2.2 Object Grid Mapper . .7 2.3 Reconfigurable Distributed STM and Storage System . .8 3 Setting up the prototype 10 3.1 Structure and Content of the Package . 10 3.2 Installing and running the prototype . 10 3.2.1 Hibernate OGM . 11 3.2.2 Fenix Framework . 12 4 Conclusions 13 3 1 Introduction This document accompanies Deliverable D2.2, Preliminary Prototype of the Cloud- TM platform. Its aim is to overview the current architecture of the prototype and to document how to set it up in order to develop applications running on top of it. As planned in the DoW this preliminary prototype does not include neither dy- namic reconfiguration mechanisms, nor the Autonomic Manager which are going to be developed later on during the project.
    [Show full text]
  • APACHE LUCENE for JAVA EE DEVELOPERS JAVAONE:2015 by @Sannegrinovero
    APACHE LUCENE FOR JAVA EE DEVELOPERS JAVAONE:2015 by @SanneGrinovero WHO AM I? WHO AM I? RED HAT Principal Software Engineer, middleware R&D Dutch, Italian, living now in London HIBERNATE TEAM Hibernate Search project lead Hibernate ORM Hibernate OGM CONTRIBUTING TO INFINISPAN the Lucene guy: Infinispan Query, Infinispan Lucene Directory, clustering extensions for Hibernate Search OTHER PROJECTS I HELP WITH... WildFly, JGroups, Apache Lucene, ... AGENDA What is Apache Lucene and how can it help you Integrations with a JPA application via Hibernate Search How does this all relate with Infinispan and WildFly Lucene index management & clouds Plans and wishlist for the future THE SEARCH PROBLEM THE SEARCH PROBLEM Hey JavaOne, remind me where the talk having primary key #2342 is? SQL CAN HANDLE TEXT SQL CAN HANDLE TEXT The LIKE operator? LET'S REFRESH SOME LESSONS ON LET'S REFRESH SOME LESSONS ON THE WIKIPEDIA Select * from WikipediaPages p where p.content LIKE ?; Select * from WikipediaPages p where p.title LIKE ?; Select * from WikipediaPages p where (lowercase(p.content) LIKE %:1% OR lowercase(p.content) LIKE %:2% OR lowercase(p.content) LIKE %:3% OR ...); HOW BAD IS IT? HOW BAD IS IT? I'm quoting successfull web companies. How many can you list which do not provide an effective search engine? Human interaction REQUIREMENTS FOR A SEARCH REQUIREMENTS FOR A SEARCH ENGINE Need to guess what you want w/o you typing all of the content Humans hate complex forms: can't you just guess what I need? We want the results in the blink of an eye We want the right result on top: Relevance We want the right result on top: Relevance SOME MORE THINGS TO CONSIDER: SOME MORE THINGS TO CONSIDER: Approximate word matches Stemming / Language specific analysis Typos Synonyms, Abbreviations, Technical Language specializations BASICS: KEYWORD EXTRACTION On how to improve running by Scott 1.
    [Show full text]
  • Spring Framework Cookbook I
    Spring Framework Cookbook i Spring Framework Cookbook Spring Framework Cookbook ii Contents 1 Spring Framework Best Practices 1 1.1 Define singleton beans with names same as their class or interface names.....................1 1.2 Place Spring bean configuration files under a folder instead of root folder.....................1 1.3 Give common prefixes or suffixes to Spring bean configuration files........................2 1.4 Avoid using import elements within Spring XML configuration files as much as possible.............2 1.5 Stay away from auto wiring in XML based bean configurations...........................2 1.6 Always externalize bean property values with property placeholders........................3 1.7 Select default version-less XSD when importing namespace definitions.......................3 1.8 Always place classpath prefix in resource paths...................................4 1.9 Create a setter method even though you use field level auto wiring.........................4 1.10 Create a separate service layer even though service methods barely delegate their responsibilities to correspond- ing DAO methods...................................................4 1.11 Use stereotype annotations as much as possible when employing annotation driven bean configuration......5 1.12 Group handler methods according to related scenarios in different Controller beans................6 1.13 Place annotations over concrete classes and their methods instead of their interfaces................6 1.14 Prefer throwing runtime exceptions instead of checked exceptions
    [Show full text]
  • Develop a Simple Web Application with Apache Wicket and Apache
    Develop a simple Web application with Apache Wicket and Apache Geronimo Combine Wicket, Geronimo, and Apache Derby to form an open source Java Web development platform Skill Level: Intermediate Robi Sen ([email protected]) Vice President Department 13 LLC 10 Jul 2007 Apache Wicket is an innovative Java™ Web application framework that was introduced a couple of years ago. It helps simplify Web application development by clearly separating the roles of developers and designers. It lets you remove logical code from the view layer, eliminating the need for JavaServer Pages (JSP), providing a simple plain old Java object (POJO)-centric mode of development, and removing much of the need for XML and other configuration file formats. In this tutorial, learn how to set up your system to develop a simple Web application with Wicket, using Apache Geronimo as your application server and Apache Derby as the embedded database. Section 1. Before you start This tutorial is designed for developers who have found Java frameworks, such as Struts, lacking in needed functionality. If you're interested in developing Web applications in a more object-oriented manner, where the view is clearly separated from logic and there's minimal configuration and mapping, then Wicket is for you! This tutorial walks you through the basics of how Wicket works, while using Apache Geronimo to set up a Java Platform, Enterprise Edition (Java EE) server, Web server, and embedded database in just minutes. Combining Wicket with Geronimo lets you develop data-driven, scalable Web applications using software that's all open source. Develop a simple Web application with Apache Wicket and Apache Geronimo © Copyright IBM Corporation 1994, 2008.
    [Show full text]
  • Comparative Studies of 10 Programming Languages Within 10 Diverse Criteria
    Department of Computer Science and Software Engineering Comparative Studies of 10 Programming Languages within 10 Diverse Criteria Jiang Li Sleiman Rabah Concordia University Concordia University Montreal, Quebec, Concordia Montreal, Quebec, Concordia [email protected] [email protected] Mingzhi Liu Yuanwei Lai Concordia University Concordia University Montreal, Quebec, Concordia Montreal, Quebec, Concordia [email protected] [email protected] COMP 6411 - A Comparative studies of programming languages 1/139 Sleiman Rabah, Jiang Li, Mingzhi Liu, Yuanwei Lai This page was intentionally left blank COMP 6411 - A Comparative studies of programming languages 2/139 Sleiman Rabah, Jiang Li, Mingzhi Liu, Yuanwei Lai Abstract There are many programming languages in the world today.Each language has their advantage and disavantage. In this paper, we will discuss ten programming languages: C++, C#, Java, Groovy, JavaScript, PHP, Schalar, Scheme, Haskell and AspectJ. We summarize and compare these ten languages on ten different criterion. For example, Default more secure programming practices, Web applications development, OO-based abstraction and etc. At the end, we will give our conclusion that which languages are suitable and which are not for using in some cases. We will also provide evidence and our analysis on why some language are better than other or have advantages over the other on some criterion. 1 Introduction Since there are hundreds of programming languages existing nowadays, it is impossible and inefficient
    [Show full text]
  • Oracle Glassfish Server Release Notes Release 3.1.2 and 3.1.2.2 E24939-04
    Oracle GlassFish Server Release Notes Release 3.1.2 and 3.1.2.2 E24939-04 October 2012 These Release Notes provide late-breaking information about GlassFish Server 3.1.2 and 3.1.2.2 software and documentation. These Release Notes include summaries of supported hardware, operating environments, and JDK and JDBC/RDBMS requirements. Also included are a summary of new product features in the 3.1.2 and 3.1.2.2 releases, and descriptions and workarounds for known issues and limitations. Oracle GlassFish Server Release Notes, Release 3.1.2 and 3.1.2.2 E24939-04 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S.
    [Show full text]
  • Ebean Java Persistence (Dominik Dorn)
    Meeting #44 EBean Java Persistence (Dominik Dorn) CoffeeScript & SASS (Clemens Helm) Brunch (w/ backbone.js) (Nik Graf – lightning talk) 2011-12-05 Dominik Dorn EBean Java Persistence just simple & powerful 2011-12-05 Dominik Dorn Overview ● What is EBean / Java Persistence + JPA? ● Architecture – where does it fit? ● Partial Objects + Fetch Graphs ● EBean Features ● Code... (maybe :) ) 2011-12-05 Dominik Dorn What is Ebean? ● open source Object Relational Mapping tool ● simple alternative to JPA (not like hibernate, eclipselink, etc.) ● “sessionless” API and simple query language (explained later) ● Fetch graphs + Partial Objects ● Lazy loading that just works. 2011-12-05 Dominik Dorn Architecture – Where does it fit? 2011-12-05 Dominik Dorn Differences to Hibernate/JPA ● Sessionless ● No EntityManager / Session / UnitOfWork – No merge(), persist(), attach() or detach() – Only save() and delete() ● Query Language ● Slightly different ● Optimized for fetch graphs and partial objects ● No hacks ● For wide tables / blobs & clobs etc. 2011-12-05 Dominik Dorn Partial Objects & Fetch Graphs ● TASK: Print an Invoice → get Order(date, items, total) + customer (name, email) + items ( name, price ) 2011-12-05 Dominik Dorn Partial Objects & Fetch Graphs ● Hibernate createQuery(“SELECT o FROM Order o WHERE o.id = ?”) → Lazy/eager loading Customer + Items → “Huge” traffic and memory requirements (blobs etc.) 2011-12-05 Dominik Dorn Partial Objects & Fetch Graphs ● EBean Order o = Ebean.find(Order.class) .select("date, total") .fetch("customer", "name,
    [Show full text]
  • Functional Programming Patterns in Scala and Clojure Write Lean Programs for the JVM
    Early Praise for Functional Programming Patterns This book is an absolute gem and should be required reading for anybody looking to transition from OO to FP. It is an extremely well-built safety rope for those crossing the bridge between two very different worlds. Consider this mandatory reading. ➤ Colin Yates, technical team leader at QFI Consulting, LLP This book sticks to the meat and potatoes of what functional programming can do for the object-oriented JVM programmer. The functional patterns are sectioned in the back of the book separate from the functional replacements of the object-oriented patterns, making the book handy reference material. As a Scala programmer, I even picked up some new tricks along the read. ➤ Justin James, developer with Full Stack Apps This book is good for those who have dabbled a bit in Clojure or Scala but are not really comfortable with it; the ideal audience is seasoned OO programmers looking to adopt a functional style, as it gives those programmers a guide for transitioning away from the patterns they are comfortable with. ➤ Rod Hilton, Java developer and PhD candidate at the University of Colorado Functional Programming Patterns in Scala and Clojure Write Lean Programs for the JVM Michael Bevilacqua-Linn The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals.
    [Show full text]
  • Object-Relational Mapping Tools and Hibernate
    Universite´ libre de Bruxelles Advanced Databases Winter Semester 2017-2018 Object-relational mapping tools and Hibernate Authors: Bruno Baldez Correa Supervisor: Matricule ULB: 000456738 Prof. Esteban Zimanyi Yue Wang Matricule ULB: 00000000 December 20, 2017 Contents 1 Object-relational database2 1.1 Necessity of object relational database...............2 1.2 Evaluation of object relational database..............3 1.2.1 Extensibility.........................3 1.2.2 Reusability..........................3 1.2.3 Productivity.........................3 1.2.4 Performance.........................4 1.3 Comparison with object database and relational database....4 2 Object-relational mapping5 2.1 ORM Paradigm Mismatch Problems................5 2.2 Entity Mapping............................6 2.3 Java Persistence API (JPA)....................7 2.3.1 JPA advantages........................8 3 Object-relational mapping tools 10 3.1 Open JPA............................... 10 3.1.1 Data remote transmission / offline processing....... 10 3.1.2 Database / object view unified tool............. 10 3.1.3 Use cache to improve efficiency............... 11 3.2 EclipseLink.............................. 11 3.3 Hibernate............................... 12 3.3.1 Hibernate Mappings..................... 13 4 Use Case 15 4.1 Scenario Diagrams.......................... 15 4.2 Implementation............................ 17 5 Conclusion 21 1 1 Object-relational database The idea of object-relational database was raised in early 1990s. A research team add object-oriented concepts to relational database. Early commercial products appeared in mid-1990s. IBM, Oracle and some other companies developed early products like Illustra and UniSQL and so on. [8] The object-relational database (ORD) is a combination of object database and relational database (RDB). It inherits advantages from both database mod- els like a middle man.
    [Show full text]
  • Integrations
    Integrations Version 2.9 October 2014 This document applies to Ehcache Version 2.9 and to all subsequent releases. Specifications contained herein are subject to change and these changes will be reported in subsequent release notes or new editions. Copyright © 2014 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. The name Software AG and all Software AG product names are either trademarks or registered trademarks of Software AG and/or Software AG USA Inc. and/or its subsidiaries and/or its affiliates and/or their licensors. Other company and product names mentioned herein may be trademarks of their respective owners. Detailed information on trademarks and patents owned by Software AG and/or its subsidiaries is located at hp://documentation.softwareag.com/legal/. Use of this software is subject to adherence to Software AG's licensing conditions and terms. These terms are part of the product documentation, located at hp://documentation.softwareag.com/legal/ and/or in the root installation directory of the licensed product(s). This software may include portions of third-party products. For third-party copyright notices and license terms, please refer to "License Texts, Copyright Notices and Disclaimers of Third Party Products”. This document is part of the product documentation, located at hp://documentation.softwareag.com/legal/ and/or in the root installation directory of the licensed product(s). Document ID: EHC-INT-29-20141015 M Table of Contents Table of Contents Using Ehcache with Hibernate.......................................................................................................5 About Using Ehcache with Hibernate.........................................................................................6 Downloading and Installing Ehcache for Hibernate..................................................................
    [Show full text]
  • Spring MVC with Hibernate and Postgresql
    Table of Contents Introduction 1.1 Architecture 1.1.1 Graph 1.1.1.1 Dependencies 1.2 PostgreSQL Database Setup 1.3 Structure in Eclipse 1.4 Entity Class 1.5 DAO Layer 1.6 Service Layer 1.7 Presentation Layer 1.8 PhoneContoller 1.9 JSP 1.10 Web Configuration 1.11 servlet-context.xml 1.12 Results 1.13 1 Introduction Objectives 1) How to integrate Spring MVC with Hibernate using Maven 2) The dependencies which are required to integrate 3) How to perform CRUD operations on a Spring MVC project with Hibernate. 4) How to configure SessionFactory and Spring configurations. 2 Architecture Architecture This architecture clearly explains our demo application. The database will be accessed by a Data Access layer popularly called as DAO Layer. This layer will use Hibernate API to interact with database. The DAO layer will be invoked by a service layer. 3 Graph The % of Framework in use 4 Dependencies Dependencies Let us start by creating a simple web project with maven in Eclipse IDE, now let me tell how to setup the project in pom.xml, follow are the dependencies required for our program: Important dependencies below are spring-context, spring-webmvc, spring-tx, hibernate-core, hibernate-entitymanager, spring-orm and postgresql driver. <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht tp://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:/ /maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.spring.demo</groupId> <artifactId>SpringMVC</artifactId>
    [Show full text]