The document provides information about Java, including:
- Java is an object-oriented programming language that is platform independent and can be used to create applications for web, desktops, mobile devices, and more.
- Java was originally developed in the early 1990s by James Gosling at Sun Microsystems for use in set-top boxes, but became popular for building web applications and is now widely used.
- The Java Development Kit (JDK) includes tools like javac, java, javadoc and others needed to develop, compile, run and document Java programs, as well as class libraries and documentation. The JVM executes compiled Java code.
The document provides an introduction and history of Java, outlining how it was developed in the 1990s as a platform-independent language by James Gosling at Sun Microsystems, and discusses some key advantages of Java like being object-oriented, portable, robust, and having built-in support for security and multithreading. It also describes the Java Development Kit (JDK) which contains tools for developing Java programs and the Java Runtime Environment (JRE) which allows running of Java applications and includes the Java Virtual Machine.
This document provides an overview of a presentation on Java fundamentals by Kunal V. Gadhi. It covers topics such as the history and features of Java, object-oriented programming concepts, Java applications and applets, multithreading, input/output and networking, MySQL, and JDBC. The document includes sections on each topic with descriptions of key concepts and code examples.
This document provides an introduction and overview of the Java programming language, including its history, features, and components. It discusses how Java was developed in 1995 at Sun Microsystems and introduced as a platform-independent language for general business applications and web-based internet applications. It also summarizes Java's key features like being object-oriented, compiled and interpreted, and portable, as well as its core architecture components like the Java programming language, Java Virtual Machine, and Java API.
Java Training | Java Tutorial for Beginners | Java Programming | Java Certifi...Edureka!
This Edureka Java Training tutorial will help you in understanding the core fundamentals of Java. It helps you to learn following topics:
1) Introduction to Java
2) Java Timeline
3) Features of Java
4) How does Java work?
5) Data Types in Java
6) Operators in Java
7) Functions in Java
8) Object Oriented Concepts in Java
In this core java training session, you will learn Elements of Java programming. Topics covered in this session are:
• Quick review of some important concepts from last class
• History of Java
• JDK and JRE
• Byte Code and JVM (Java Virtual Machine)
• Platform Independence
• Principles of Object Oriented Programming
• Writing your first Java Application
• Elements of Java programming language
• Built in Data Types
• Conditional Statements
• Loops
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
The document provides an introduction to Java programming concepts including object-oriented programming, Java features, program structure, tokens, control statements, arrays, classes and objects. It discusses key Java concepts such as encapsulation, inheritance and polymorphism. The document also compares Java to C++ and covers data types, operators, selection statements, iteration statements and type conversion in Java.
JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code.
The document provides an introduction to the Java programming language. It discusses that Java was originally called Oak and developed by Sun Microsystems in 1991. It can be used to create both applications and applets. The source code is compiled into bytecode, which is then interpreted by the Java Virtual Machine (JVM) to execute programs. Key features of Java include being simple, secure, portable, object-oriented, robust, and multi-threaded. The document also covers concepts such as packages, interfaces, inheritance, method overloading/overriding, and multithreading.
This document provides an introduction and overview of the Java programming language. It discusses that Java was developed by Sun Microsystems in the 1990s as a general-purpose, object-oriented language designed for easy web and internet applications. The key principles of object-oriented programming like encapsulation, inheritance, and polymorphism are explained. Characteristics of Java like being simple, secure, portable, and having good performance are highlighted. A brief history of Java's development is also presented.
Introduction to Java Programming Languagejaimefrozr
The document provides an introduction and history of the Java programming language. It discusses that Java was originally developed in 1991 by Sun Microsystems to be portable for consumer electronic devices. The document then summarizes the key capabilities of Java including being a general purpose language that can develop robust applications for desktops, servers, and mobile devices. It also outlines the Java language specifications, application programming interface containing predefined classes, and development tools available. Finally, it explains how Java's use of byte code and the Java Virtual Machine allows it to be highly portable across different operating systems.
Introduction to Java Programming, Basic Structure, variables Data type, input...Mr. Akaash
This is First Lecture of java Programming which cover all basic points (ie. History and feature of java, Introduction to java, about variables data type and compilation....
This document provides an outline for teaching Java programming concepts. It begins with introductions to object-oriented programming, Java's working process, and programming language hierarchy. Subsequent sections cover Java topics like variables, data types, statements, arrays, loops, methods, threads, classes, inheritance, polymorphism, abstract classes, interfaces, and GUI programming using Swing. The document aims to guide students through Java concepts with examples and projects at each stage.
Training on Core java | PPT Presentation | Shravan SanidhyaShravan Sanidhya
This document provides an overview of Java training. It defines Java as an object-oriented programming language and platform, describes where Java is used including desktop applications, web applications, and mobile applications. The document also outlines features of Java like being simple, object-oriented, distributed, robust, and secure. It further explains the Java Virtual Machine, includes a basic "Hello World" Java program example, and discusses advantages and disadvantages of Java.
This document provides an introduction and overview of Java applications, including:
- A brief history of Java's development starting in 1990s.
- The objectives and topics covered include introductions, history, architecture, security and a sample program.
- Java was designed to be a platform-independent language that can create applications running on a single computer or distributed network.
Java is an object-oriented programming language initially developed by Sun Microsystems. It was released in 1995. Key points:
- Java can be used to develop client-side standalone applications, applets for webpages, and server-side applications.
- It introduced the Java Virtual Machine (JVM) which allows Java programs to run on any platform that supports the JVM.
- Java's use of bytecode makes it portable and able to run on any device with a JVM, earning it the label of "Write Once, Run Anywhere".
The document discusses Java collections and lists. It explains that collections include sets, lists, and maps. Lists are ordered collections that allow duplicates. The document covers using collections and iterators, bulk operations on collections, mixing collection types, and list-specific operations like positional access, searching, and iteration both forward and backward.
The document summarizes some of the key new features in Java 17 including:
1. Long-term support for Java 17 which will be available in September 2021 and include features like records, text blocks, and enhanced null pointer exceptions.
2. Records, text blocks, helpful null pointer exceptions, pattern matching for switches, and sealed classes as some of the top new features in Java 17.
3. Enhancements to pseudo-random number generators with a new RandomGenerator interface and refactoring of legacy random classes.
This Edureka Java Tutorial will help you in understanding the various fundamentals of Java in detail with examples. Below are the topics covered in this tutorial:
1) Introduction to Java
2) Why learn Java?
3) Features of Java
4) How does Java work?
5) Data types in Java
6) Operators in Java
7) Control Statements in Java
8) Arrays in Java
9) Object Oriented Concepts in Java
In this core java training session, you will learn get introduction to Java. Topics covered in this session are:
• History of Java – A Programmer’s Perspective
• Salient Features of Java
• Major Java Editions
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
This is a seminar given by P. Nikhil (me) of Government Arts College, Rajahmundry.
This document contains Java and its features.
There is a wide range in usage of Java around the World .
Hope this document helps anyone who's interested in it.
Thank You
Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented,[15] and specifically designed to have as few implementation dependencies as possible
Java is a popular High-level language. This ppt contains all the fundamentals of the Java programming language- Why one should learn Java, its history, features, applications and what type of career does Java developer have
Java is a programming language that allows software to run on many platforms without recompilation. It has a long history beginning in 1991 at Sun Microsystems and is now open source. Key features include being platform independent, object oriented, secure, providing automatic memory management, and being robust. Java programs use a Java Virtual Machine to run on different operating systems. The Java Development Kit includes tools for developing Java programs. Java is widely used for both desktop and mobile applications as well as enterprise software.
This document discusses various Java concepts like object-oriented programming, compilation, the main method signature, command line arguments, byte code checking, type casting, and input/output in Java using classes like DataInputStream and Scanner. It provides code examples for accepting user input using these classes and parsing the input into different data types like integer and float. It also compares DataInputStream and Scanner, noting that Scanner avoids the need to manually convert input types.
Payday Advance Loans Canada offers payday loans to help cover expenses in the days before payday. Their quick and easy application process allows borrowers to get the funds they need from a trusted lender with no collateral required. Payday advance loans are an unsecured option specially designed for Canadians to meet their short-term financial needs until their next payday.
Food is an important part of culture that people become fond of. Food serves as prime recognition to represent any culture. Kamal Kant Dewan ensures India's variety of foods meet competitive standards through his company V.I.R Foods Ltd, which imports India's finest quality rice and has been successfully credited to Kamal Kant Dewan's efforts.
JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code.
The document provides an introduction to the Java programming language. It discusses that Java was originally called Oak and developed by Sun Microsystems in 1991. It can be used to create both applications and applets. The source code is compiled into bytecode, which is then interpreted by the Java Virtual Machine (JVM) to execute programs. Key features of Java include being simple, secure, portable, object-oriented, robust, and multi-threaded. The document also covers concepts such as packages, interfaces, inheritance, method overloading/overriding, and multithreading.
This document provides an introduction and overview of the Java programming language. It discusses that Java was developed by Sun Microsystems in the 1990s as a general-purpose, object-oriented language designed for easy web and internet applications. The key principles of object-oriented programming like encapsulation, inheritance, and polymorphism are explained. Characteristics of Java like being simple, secure, portable, and having good performance are highlighted. A brief history of Java's development is also presented.
Introduction to Java Programming Languagejaimefrozr
The document provides an introduction and history of the Java programming language. It discusses that Java was originally developed in 1991 by Sun Microsystems to be portable for consumer electronic devices. The document then summarizes the key capabilities of Java including being a general purpose language that can develop robust applications for desktops, servers, and mobile devices. It also outlines the Java language specifications, application programming interface containing predefined classes, and development tools available. Finally, it explains how Java's use of byte code and the Java Virtual Machine allows it to be highly portable across different operating systems.
Introduction to Java Programming, Basic Structure, variables Data type, input...Mr. Akaash
This is First Lecture of java Programming which cover all basic points (ie. History and feature of java, Introduction to java, about variables data type and compilation....
This document provides an outline for teaching Java programming concepts. It begins with introductions to object-oriented programming, Java's working process, and programming language hierarchy. Subsequent sections cover Java topics like variables, data types, statements, arrays, loops, methods, threads, classes, inheritance, polymorphism, abstract classes, interfaces, and GUI programming using Swing. The document aims to guide students through Java concepts with examples and projects at each stage.
Training on Core java | PPT Presentation | Shravan SanidhyaShravan Sanidhya
This document provides an overview of Java training. It defines Java as an object-oriented programming language and platform, describes where Java is used including desktop applications, web applications, and mobile applications. The document also outlines features of Java like being simple, object-oriented, distributed, robust, and secure. It further explains the Java Virtual Machine, includes a basic "Hello World" Java program example, and discusses advantages and disadvantages of Java.
This document provides an introduction and overview of Java applications, including:
- A brief history of Java's development starting in 1990s.
- The objectives and topics covered include introductions, history, architecture, security and a sample program.
- Java was designed to be a platform-independent language that can create applications running on a single computer or distributed network.
Java is an object-oriented programming language initially developed by Sun Microsystems. It was released in 1995. Key points:
- Java can be used to develop client-side standalone applications, applets for webpages, and server-side applications.
- It introduced the Java Virtual Machine (JVM) which allows Java programs to run on any platform that supports the JVM.
- Java's use of bytecode makes it portable and able to run on any device with a JVM, earning it the label of "Write Once, Run Anywhere".
The document discusses Java collections and lists. It explains that collections include sets, lists, and maps. Lists are ordered collections that allow duplicates. The document covers using collections and iterators, bulk operations on collections, mixing collection types, and list-specific operations like positional access, searching, and iteration both forward and backward.
The document summarizes some of the key new features in Java 17 including:
1. Long-term support for Java 17 which will be available in September 2021 and include features like records, text blocks, and enhanced null pointer exceptions.
2. Records, text blocks, helpful null pointer exceptions, pattern matching for switches, and sealed classes as some of the top new features in Java 17.
3. Enhancements to pseudo-random number generators with a new RandomGenerator interface and refactoring of legacy random classes.
This Edureka Java Tutorial will help you in understanding the various fundamentals of Java in detail with examples. Below are the topics covered in this tutorial:
1) Introduction to Java
2) Why learn Java?
3) Features of Java
4) How does Java work?
5) Data types in Java
6) Operators in Java
7) Control Statements in Java
8) Arrays in Java
9) Object Oriented Concepts in Java
In this core java training session, you will learn get introduction to Java. Topics covered in this session are:
• History of Java – A Programmer’s Perspective
• Salient Features of Java
• Major Java Editions
For more information about this course visit on this link: https://www.mindsmapped.com/courses/software-development/learn-java-fundamentals-hands-on-training-on-core-java-concepts/
This is a seminar given by P. Nikhil (me) of Government Arts College, Rajahmundry.
This document contains Java and its features.
There is a wide range in usage of Java around the World .
Hope this document helps anyone who's interested in it.
Thank You
Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented,[15] and specifically designed to have as few implementation dependencies as possible
Java is a popular High-level language. This ppt contains all the fundamentals of the Java programming language- Why one should learn Java, its history, features, applications and what type of career does Java developer have
Java is a programming language that allows software to run on many platforms without recompilation. It has a long history beginning in 1991 at Sun Microsystems and is now open source. Key features include being platform independent, object oriented, secure, providing automatic memory management, and being robust. Java programs use a Java Virtual Machine to run on different operating systems. The Java Development Kit includes tools for developing Java programs. Java is widely used for both desktop and mobile applications as well as enterprise software.
This document discusses various Java concepts like object-oriented programming, compilation, the main method signature, command line arguments, byte code checking, type casting, and input/output in Java using classes like DataInputStream and Scanner. It provides code examples for accepting user input using these classes and parsing the input into different data types like integer and float. It also compares DataInputStream and Scanner, noting that Scanner avoids the need to manually convert input types.
Payday Advance Loans Canada offers payday loans to help cover expenses in the days before payday. Their quick and easy application process allows borrowers to get the funds they need from a trusted lender with no collateral required. Payday advance loans are an unsecured option specially designed for Canadians to meet their short-term financial needs until their next payday.
Food is an important part of culture that people become fond of. Food serves as prime recognition to represent any culture. Kamal Kant Dewan ensures India's variety of foods meet competitive standards through his company V.I.R Foods Ltd, which imports India's finest quality rice and has been successfully credited to Kamal Kant Dewan's efforts.
Esriuk_track3_bruce mc-daniel - highways englandEsri UK
The document discusses Highways England's methods for prioritizing locations for improved cycling facilities on the Strategic Road Network. ArcGIS was used to analyze connectivity, economic, and safety data to score and rank potential scheme locations. This included analyzing population within 2.5km, deprivation levels, distance from public transport, accident rates, and traffic levels. The prioritization process has led to £100 million being allocated over 5 years to implement 200 new cycling facilities and crossings to help cyclists.
This document lists 11 runway shows as part of a dress trend report and provides a link to more dress shows on Pinterest. It briefly outlines runway shows 1 through 10 without providing any other context or details about the specific shows. The document directs the reader to click a link for additional dress show information on Pinterest.
Este documento describe las diferencias entre datos y señales, así como conceptos clave relacionados con las redes locales como la señalización, la clasificación de la transmisión de datos y las características de las señales analógicas y digitales. Explica que los datos son hechos e instrucciones representados en formato binario, mientras que las señales son la representación eléctrica de los datos para su transmisión. También describe los diferentes tipos de medios de transmisión guiados como el cable de cobre y la fibra óptica, e
Make your atomizer more better look with eGo beauty ring to add stability to larger tanks with great and complete looks.http://www.rprimevapes.com/collections/misc/products/ego-beauty-ring
This document discusses key concepts related to time value of money calculations including future value, present value, annuities, rates of return, and amortization. It provides examples of how to draw time lines to illustrate cash flows occurring at different points in time. It also demonstrates how to calculate future and present value using the step-by-step, financial calculator, and Excel methods. Additional topics covered include ordinary versus annuity due calculations, perpetuities, the power of compound interest, and classification of interest rates such as nominal, periodic, and effective annual rates.
Goals to strive for in automating infrastructure deployment and monitoring. This focuses on all aspects of automation, from the development cycle, to deployment, to maintaining live services, all the way through data analysis.
Crisis digital, cuando el problema surge desde adentroPacific Latam
Presentación de Mónica Maldonado, comunicadora especializada en Marketing Digital, desarrollada en la cuarta edición de Café y Tendencias que trató el tema Crisis Digital.
Esta es una guía para las marcas de cómo deben orientar a sus colaboradores en el uso de redes sociales para cuidar la reputación personal y de la marca.
Jocelyn was planning her Sweet 15 birthday party. She wanted it to be perfect and had been working hard from the beginning to make all the arrangements. While there were no other details provided in the document, it appears to be about Jocelyn preparing for her quinceañera celebration.
This 3 credit graduate course focuses on reflective diagnostic literacy teaching and includes a fieldwork practicum. The course objectives are for students to learn how to administer and interpret literacy assessments, develop instruction based on assessment results, tutor struggling readers while reflecting on their teaching, and present their work to inform future instruction. Major assignments include participating in online discussions, completing a case study involving assessing a student, developing instruction, tutoring the student, and presenting the work. The course addresses state teaching standards and the university's focus on preparing educational leaders who promote equity and excellence.
The document discusses a face-to-face meeting that took place in Tokyo on April 21, 2011. It provides two detailed views related to the Tokyo meeting on that date. The document gives an overview of a meeting that was held in Tokyo, Japan on April 21, 2011 and contains two sections of details related to that meeting.
This short document promotes creating presentations using Haiku Deck, a tool for making slideshows. It encourages the reader to get started making their own Haiku Deck presentation and sharing it on SlideShare. In just one sentence, it pitches the idea of using Haiku Deck to easily create engaging slideshows.
This document provides an overview of chemical reactions including:
- The difference between physical and chemical changes
- Types of chemical reactions such as combustion, hydration, displacement, neutralization, synthesis, and decomposition
- How to write and balance chemical equations
- How to identify evidence of chemical reactions through color change, energy release, gas evolution, and precipitation
- Examples of specific chemical reactions are also provided
Introduction to java programming tutorialjackschitze
This document provides an introduction to Java programming including:
- A brief history of Java and overview of its key characteristics like being platform independent and using automatic memory management.
- Explanations of core Java concepts like classes, objects, inheritance and interfaces.
- A guide to installing Java and writing, compiling and running a simple "Hello World" program as an example.
- Descriptions of common Java terms and language features like packages, variables, methods and loops.
Java is an object-oriented programming language introduced in 1995. It is platform independent and allows programs to run on any device with a Java Virtual Machine. The key features of Java include being simple, object-oriented, platform independent, robust, secure, distributed, multithreaded, and dynamic. Java programs are compiled into bytecode that can run on any platform supporting the Java Virtual Machine.
Java is a programming language and platform that is commonly used to develop desktop applications, web applications, mobile apps, and more. The document introduces Java by explaining what it is, where it is used, the types of Java applications that can be created, and how the Java compilation and execution process works at a high level. It also provides an example "Hello World" Java program to demonstrate the basic anatomy of a Java file, including classes, methods, and how the main method acts as the program entry point.
Java is a compiled and interpreted, platform-independent, secure, robust, and object-oriented programming language. It is compiled into bytecode that can run on any Java Virtual Machine (JVM), making programs portable across platforms. The JVM is available on many operating systems, so Java code can run on Windows, Linux, Solaris, or Mac OS. Java uses automatic memory management, exceptions, and avoids many common programming bugs found in other languages like C/C++.
Introduction to Java : Feature to Java, Java Virtual Machine, Differences between C++ and Java,
Part of Java, API Document, Starting a Java Program. Important Classes, Formatting the Output
- Java was created at Sun Microsystems in 1991 to provide a platform-independent programming language. It is an object-oriented language similar to C++ but simpler and more robust.
- Java code is compiled into bytecode that can run on any Java Virtual Machine (JVM), allowing "write once, run anywhere" capability. The JVM handles running the bytecode.
- Java supports object-oriented programming features like abstraction, encapsulation, inheritance, and polymorphism. It also supports features like being distributed, multithreaded, secure, and using automatic memory management.
This document discusses the evolution of Java programming language. It begins with an introduction to Java, describing it as an object-oriented language suited for internet programming. The document then covers Java's history, key features, environment including development tools and runtime components. It describes Java's portability, security, object-oriented nature and use in a variety of platforms from mobile to servers.
This document provides an introduction to the Java programming language. It discusses that Java was created at Sun Microsystems in 1991 to provide a platform-independent language. Java code is compiled to bytecode that can run on any Java Virtual Machine. The document outlines key Java concepts like object-oriented programming, platform independence, bytecode, the Java Virtual Machine, and garbage collection. It also provides examples of Hello World programs in Java and discusses compiling and running Java code.
B.Sc. Sem-5
History of Java
Features of Java
Difference Between C++ and Java
Branching Statements in Java
Looping Statements in Java
Arrays in Java
Command Line Arguments in Java
The document provides an overview of key Java concepts:
1. Java is an object-oriented, platform-independent language that is compiled to bytecode and interpreted by the Java Virtual Machine (JVM).
2. The JVM handles security, memory management through garbage collection, and allows multithreaded programming.
3. Developers use the Java Development Kit (JDK) for coding Java applications, which includes the compiler, JVM, and other tools. The Java Runtime Environment (JRE) provides minimum requirements to run Java applications.
Java was initially developed by Sun Microsystems in 1991 under the name Oak by James Gosling. It was renamed to Java in 1995 due to legal issues. Java is an object-oriented programming language that is platform independent, meaning Java programs can run on any system with a Java virtual machine. Key features of Java include being simple, secure, robust, portable, and having automatic memory management. Java is commonly used to build mobile and web applications.
Here are the key differences:
Reserved words: These are words that have special meaning in Java like class, public, etc. They cannot be used as regular identifiers.
Modifiers: Modifiers like public, private, static etc. specify attributes of classes, methods and variables.
Package: A package is a namespace that organizes related classes and interfaces. It provides access protection.
Libraries: Libraries are pre-compiled classes that provide useful functionality that can be included in programs using import statements.
JVM version: The Java Virtual Machine version specifies the Java runtime environment. Programs need to be compatible with the JVM version.
JVM: The Java Virtual Machine is an abstract computing machine that
Learning Java Beginning programming with java for dummies First Edition John ...dionegorra0l
Learning Java Beginning programming with java for dummies First Edition John Bach
Learning Java Beginning programming with java for dummies First Edition John Bach
Learning Java Beginning programming with java for dummies First Edition John Bach
This document provides an introduction to Java programming, including setting up a development environment. It discusses downloading and installing the Java Development Kit (JDK) and Eclipse integrated development environment. It then provides an overview of key concepts in the Java language and platform, such as object-oriented programming, the Java compiler, Java virtual machine, garbage collection, and Java Development Kit. The document is intended to help new Java developers get started with building Java applications.
Java is a widely used programming language that is mainly used for application programming. It is platform-independent and supports features like multi-threading and documentation comments. The key aspects of a simple Java program are that it must contain a class with a main method that can be the starting point of execution. The main method has a specific signature of public static void main(String[] args). When a Java program is run, the JVM (Java Virtual Machine) loads and executes the program by performing operations like loading code, verifying code, and providing a runtime environment.
Java is a high-level programming language and platform developed by James Gosling at Sun Microsystems in 1991. It is designed to be platform independent, meaning that code written in Java can run on any device where a suitable runtime environment exists without modification. The key components that enable platform independence are the Java Virtual Machine (JVM) and the Java Runtime Environment (JRE). The JVM converts Java bytecode into machine code that can be executed by specific CPUs or hardware platforms. The JRE provides the minimum requirements for executing Java applications and includes the JVM, class libraries, and other supporting files.
The document provides a tutorial on using the Java Native Interface (JNI) to call C/C++ code from Java programs and call Java code from C/C++ programs. It outlines the six main steps to call C/C++ code from Java: 1) write the Java code, 2) compile the Java code, 3) create a C/C++ header file, 4) write the C/C++ code, 5) create a shared library file, and 6) run the Java program. The document also discusses tools needed, advanced JNI topics, and considerations for different Java versions.
The ever evoilving world of science /7th class science curiosity /samyans aca...Sandeep Swamy
The Ever-Evolving World of
Science
Welcome to Grade 7 Science4not just a textbook with facts, but an invitation to
question, experiment, and explore the beautiful world we live in. From tiny cells
inside a leaf to the movement of celestial bodies, from household materials to
underground water flows, this journey will challenge your thinking and expand
your knowledge.
Notice something special about this book? The page numbers follow the playful
flight of a butterfly and a soaring paper plane! Just as these objects take flight,
learning soars when curiosity leads the way. Simple observations, like paper
planes, have inspired scientific explorations throughout history.
As of Mid to April Ending, I am building a new Reiki-Yoga Series. No worries, they are free workshops. So far, I have 3 presentations so its a gradual process. If interested visit: https://www.slideshare.net/YogaPrincess
https://ldmchapels.weebly.com
Blessings and Happy Spring. We are hitting Mid Season.
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessMark Soia
Boost your chances of passing the 2V0-11.25 exam with CertsExpert reliable exam dumps. Prepare effectively and ace the VMware certification on your first try
Quality dumps. Trusted results. — Visit CertsExpert Now: https://www.certsexpert.com/2V0-11.25-pdf-questions.html
The *nervous system of insects* is a complex network of nerve cells (neurons) and supporting cells that process and transmit information. Here's an overview:
Structure
1. *Brain*: The insect brain is a complex structure that processes sensory information, controls behavior, and integrates information.
2. *Ventral nerve cord*: A chain of ganglia (nerve clusters) that runs along the insect's body, controlling movement and sensory processing.
3. *Peripheral nervous system*: Nerves that connect the central nervous system to sensory organs and muscles.
Functions
1. *Sensory processing*: Insects can detect and respond to various stimuli, such as light, sound, touch, taste, and smell.
2. *Motor control*: The nervous system controls movement, including walking, flying, and feeding.
3. *Behavioral responThe *nervous system of insects* is a complex network of nerve cells (neurons) and supporting cells that process and transmit information. Here's an overview:
Structure
1. *Brain*: The insect brain is a complex structure that processes sensory information, controls behavior, and integrates information.
2. *Ventral nerve cord*: A chain of ganglia (nerve clusters) that runs along the insect's body, controlling movement and sensory processing.
3. *Peripheral nervous system*: Nerves that connect the central nervous system to sensory organs and muscles.
Functions
1. *Sensory processing*: Insects can detect and respond to various stimuli, such as light, sound, touch, taste, and smell.
2. *Motor control*: The nervous system controls movement, including walking, flying, and feeding.
3. *Behavioral responses*: Insects can exhibit complex behaviors, such as mating, foraging, and social interactions.
Characteristics
1. *Decentralized*: Insect nervous systems have some autonomy in different body parts.
2. *Specialized*: Different parts of the nervous system are specialized for specific functions.
3. *Efficient*: Insect nervous systems are highly efficient, allowing for rapid processing and response to stimuli.
The insect nervous system is a remarkable example of evolutionary adaptation, enabling insects to thrive in diverse environments.
The insect nervous system is a remarkable example of evolutionary adaptation, enabling insects to thrive
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsesushreesangita003
what is pulse ?
Purpose
physiology and Regulation of pulse
Characteristics of pulse
factors affecting pulse
Sites of pulse
Alteration of pulse
for BSC Nursing 1st semester
for Gnm Nursing 1st year
Students .
vitalsign
Exploring Substances:
Acidic, Basic, and
Neutral
Welcome to the fascinating world of acids and bases! Join siblings Ashwin and
Keerthi as they explore the colorful world of substances at their school's
National Science Day fair. Their adventure begins with a mysterious white paper
that reveals hidden messages when sprayed with a special liquid.
In this presentation, we'll discover how different substances can be classified as
acidic, basic, or neutral. We'll explore natural indicators like litmus, red rose
extract, and turmeric that help us identify these substances through color
changes. We'll also learn about neutralization reactions and their applications in
our daily lives.
by sandeep swamy
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schoolsdogden2
Algebra 1 is often described as a “gateway” class, a pivotal moment that can shape the rest of a student’s K–12 education. Early access is key: successfully completing Algebra 1 in middle school allows students to complete advanced math and science coursework in high school, which research shows lead to higher wages and lower rates of unemployment in adulthood.
Learn how The Atlanta Public Schools is using their data to create a more equitable enrollment in middle school Algebra classes.
INTRO TO STATISTICS
INTRO TO SPSS INTERFACE
CLEANING MULTIPLE CHOICE RESPONSE DATA WITH EXCEL
ANALYZING MULTIPLE CHOICE RESPONSE DATA
INTERPRETATION
Q & A SESSION
PRACTICAL HANDS-ON ACTIVITY
This chapter provides an in-depth overview of the viscosity of macromolecules, an essential concept in biophysics and medical sciences, especially in understanding fluid behavior like blood flow in the human body.
Key concepts covered include:
✅ Definition and Types of Viscosity: Dynamic vs. Kinematic viscosity, cohesion, and adhesion.
⚙️ Methods of Measuring Viscosity:
Rotary Viscometer
Vibrational Viscometer
Falling Object Method
Capillary Viscometer
🌡️ Factors Affecting Viscosity: Temperature, composition, flow rate.
🩺 Clinical Relevance: Impact of blood viscosity in cardiovascular health.
🌊 Fluid Dynamics: Laminar vs. turbulent flow, Reynolds number.
🔬 Extension Techniques:
Chromatography (adsorption, partition, TLC, etc.)
Electrophoresis (protein/DNA separation)
Sedimentation and Centrifugation methods.
Title: A Quick and Illustrated Guide to APA Style Referencing (7th Edition)
This visual and beginner-friendly guide simplifies the APA referencing style (7th edition) for academic writing. Designed especially for commerce students and research beginners, it includes:
✅ Real examples from original research papers
✅ Color-coded diagrams for clarity
✅ Key rules for in-text citation and reference list formatting
✅ Free citation tools like Mendeley & Zotero explained
Whether you're writing a college assignment, dissertation, or academic article, this guide will help you cite your sources correctly, confidently, and consistent.
Created by: Prof. Ishika Ghosh,
Faculty.
📩 For queries or feedback: [email protected]
A measles outbreak originating in West Texas has been linked to confirmed cases in New Mexico, with additional cases reported in Oklahoma and Kansas. The current case count is 795 from Texas, New Mexico, Oklahoma, and Kansas. 95 individuals have required hospitalization, and 3 deaths, 2 children in Texas and one adult in New Mexico. These fatalities mark the first measles-related deaths in the United States since 2015 and the first pediatric measles death since 2003.
The YSPH Virtual Medical Operations Center Briefs (VMOC) were created as a service-learning project by faculty and graduate students at the Yale School of Public Health in response to the 2010 Haiti Earthquake. Each year, the VMOC Briefs are produced by students enrolled in Environmental Health Science Course 581 - Public Health Emergencies: Disaster Planning and Response. These briefs compile diverse information sources – including status reports, maps, news articles, and web content– into a single, easily digestible document that can be widely shared and used interactively. Key features of this report include:
- Comprehensive Overview: Provides situation updates, maps, relevant news, and web resources.
- Accessibility: Designed for easy reading, wide distribution, and interactive use.
- Collaboration: The “unlocked" format enables other responders to share, copy, and adapt seamlessly. The students learn by doing, quickly discovering how and where to find critical information and presenting it in an easily understood manner.
1. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Introduction to Java programming -Complate Tutorial
ShreeDhoon InfoTech in Gandhinagar
Java training in gandhinagar
Introduction to Java programming
This tutorial explains the installation and usage of the Java programming language. It also
contains examples for standard programming tasks.
Table of Contents
1. Introduction to Java
1.1. History
1.2. Java and Open Source
1.3. Java virtual machine
1.4. Java Runtime Environment vs. Java Development Kit
1.5. Characteristics of Java
1.6. Development Process with Java
1.7. Garbage collector
1.8. Classpath
2. Installation of Java
2.1. Check installation
2.2. Install Java on Ubuntu
2.3. Install Java on MS Windows
2.4. Installation problems and other operating systems
2.5. Validate installation
2.6. How can you tell you are using a 32 bit or 64 bit version of Java?
3. Exercise: Write, compile and run a Java program
2. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
3.1. Write source code
3.2. Compile and run your Java program
3.3. Using the class path
4. Java language structure
4.1. Basics: Package, Class and Object
4.2. Package
4.3. Class
4.4. Object
4.5. Inheritance
4.6. Object as superclass
5. Java interfaces
5.1. What is an interface in Java?
5.2. Abstract, default and static methods in Interfaces
5.3. Implementing Interfaces
5.4. Evolving interfaces
5.5. Multiple inheritance of methods
5.6. Functional interfaces
6. Java basic terms
6.1. Override methods and the @Override annotation
7. The type system of Java
7.1. Primitives and references
7.2. Primitives
7.3. Reference types
7.4. Auto boxing and wrapper types
8. Variables and methods
3. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
8.1. Variable
8.2. Instance variable
8.3. Local variable
8.4. Methods
8.5. Main method
8.6. Constructor
9. Modifiers
9.1. Access modifiers
9.2. Other modifiers
10. Import statements
10.1. Usage of import statements
10.2. Static imports
11. More Java language constructs
11.1. Class methods and class variables
11.2. Abstract class and methods
12. Cheat Sheets
12.1. Working with classes
12.2. Working with local variable
13. Integrated Development Environment
14. Exercises - Creating Java objects and methods
14.1. Create a Person class and instantiate it
14.2. Use constructor
14.3. Define getter and setter methods
14.4. Create an Address object
15. Solution - Creating Java objects and methods
4. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
15.1. Create a Person class and instantiate it
15.2. Use constructor
15.3. Define getter and setter methods
15.4. Solution - Create an Address object
16. Java statements
16.1. if-then and if-then-else
16.2. Switch
16.3. Boolean Operations
17. Loops in Java
17.1. The for loop
17.2. The while loop
17.3. The do while loop
18. Arrays
18.1. Arrays in Java
18.2. Enhanced for loop for Arrays and Collections
19. Strings
19.1. Strings in Java
19.2. String pool in Java
19.3. Compare Strings in Java
19.4. Working with Strings
20. Lambdas
20.1. What are lambdas?
20.2. Difference between a lambda expression and a closure
20.3. Purpose of lambda expressions
20.4. Using method references
6. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
1. Introduction to Java
1.1. History
Java is a programming language created by James Gosling from Sun Microsystems (Sun) in
1991. The first publicly available version of Java (Java 1.0) was released in 1995.
Sun Microsystems was acquired by the Oracle Corporation in 2010. Oracle has now the
steermanship for Java.
Over time new enhanced versions of Java have been released. The current version of Java is
Java 1.7 which is also known as Java 7.
From the Java programming language the Java platform evolved. The Java platform allows
software developers to write program code in other languages than the Java programming
language which still runs on the Java virtual machine. The Java platform is usually associated
with the Java virtual machine and the Java core libraries.
1.2. Java and Open Source
In 2006 Sun started to make Java available under the GNU General Public License (GPL).
Oracle continues this project called OpenJDK.
1.3. Java virtual machine
The Java virtual machine (JVM) is a software implementation of a computer that executes
programs like a real machine.
The Java virtual machine is written specifically for a specific operating system, e.g., for
Linux a special implementation is required as well as for Windows.
7. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Java programs are compiled by the Java compiler into bytecode. The Java virtual machine
interprets this bytecode and executes the Java program.
1.4. Java Runtime Environment vs. Java Development Kit
A Java distribution typically comes in two flavors, the Java Runtime Environment (JRE) and
the Java Development Kit (JDK).
The Java runtime environment (JRE) consists of the JVM and the Java class libraries. Those
contain the necessary functionality to start Java programs.
The JDK additionally contains the development tools necessary to create Java programs. The
JDK therefore consists of a Java compiler, the Java virtual machine and the Java class
libraries.
1.5. Characteristics of Java
The target of Java is to write a program once and then run this program on multiple operating
systems.
Java has the following properties:
Platform independent: Java programs use the Java virtual machine as abstraction and
do not access the operating system directly. This makes Java programs highly
portable. A Java program (which is standard-compliant and follows certain rules) can
run unmodified on all supported platforms, e.g., Windows or Linux.
Object-orientated programming language: Except the primitive data types, all
elements in Java are objects.
8. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Strongly-typed programming language: Java is strongly-typed, e.g., the types of the
used variables must be pre-defined and conversion to other objects is relatively strict,
e.g., must be done in most cases by the programmer.
Interpreted and compiled language: Java source code is transferred into the bytecode
format which does not depend on the target platform. These bytecode instructions will
be interpreted by the Java Virtual machine (JVM). The JVM contains a so called
Hotspot-Compiler which translates performance critical bytecode instructions into
native code instructions.
Automatic memory management: Java manages the memory allocation and de-
allocation for creating new objects. The program does not have direct access to the
memory. The so-called garbage collector automatically deletes objects to which no
active pointer exists.
The Java syntax is similar to C++. Java is case-sensitive, e.g., variables called myValue and
myvalue are treated as different variables.
1.6. Development Process with Java
Java source files are written as plain text documents. The programmer typically writes Java
source code in an Integrated Development Environment (IDE) for programming. An IDE
supports the programmer in the task of writing code, e.g., it provides auto-formating of the
source code, highlighting of the important keywords, etc.
At some point the programmer (or the IDE) calls the Java compiler (javac). The Java
compiler creates the bytecode instructions. These instructions are stored in .class files and
can be executed by the Java Virtual Machine.
1.7. Garbage collector
The JVM automatically re-collects the memory which is not referred to by other objects. The
Java garbage collector checks all object references and finds the objects which can be
automatically released.
While the garbage collector relieves the programmer from the need to explicitly manage
memory, the programmer still need to ensure that he does not keep unneeded object
references, otherwise the garbage collector cannot release the associated memory. Keeping
unneeded object references are typically called memory leaks.
1.8. Classpath
The classpath defines where the Java compiler and Java runtime look for .class files to
load. These instructions can be used in the Java program.
For example, if you want to use an external Java library you have to add this library to your
classpath to use it in your program.
9. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
2. Installation of Java
2.1. Check installation
To run Java programs on your computer you must at least have the Java runtime environment
(JRE) installed. This might already be the case on your machine. You can test is the JRE is
installed and in your current path by opening a console (if you are using Windows: Win+R,
enter cmd and press Enter) and by typing in the following command:
java -version
If the JRE is installed and within your path, this commands print information about your Java
installation. If the command line returns the information that the program could not be found,
you have to install Java.
2.2. Install Java on Ubuntu
On Ubuntu you can install Java 7 via the following command on the command line.
sudo apt-get install openjdk-7-jdk
2.3. Install Java on MS Windows
For Microsofts Windows, Oracle provides a native installer which can be found on the Oracle
website. The central website for installing Java is located under the following URL and also
contains instructions how to install Java for other platforms.
java.com
2.4. Installation problems and other operating systems
If you have problems installing Java on your system, search via Google for How to install
JDK on YOUR_OS . This should result in helpful links. Replace YOUR_OS with your operating
system, e.g., Windows, Ubuntu, Mac OS X, etc.
2.5. Validate installation
Switch again to the command line and run the following command.
java -version
The output should be similar to the following output.
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
2.6. How can you tell you are using a 32 bit or 64 bit version of Java?
10. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
You can run a 32 bit or a 64 bit version of Java on a 64 bit system. If you use java -version
and the output contains the "64-Bit" string you are using the 64 bit version of Java otherwise
your are using the 32 bit version. The following is the output of a 64-bit version.
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
3. Exercise: Write, compile and run a Java program
3.1. Write source code
The following Java program is developed under Linux using a text editor and the command
line. The process on other operating system should be similar, but is not covered in this
description.
Select or create a new directory which will be used for your Java development. In this
description the path homevogellajavastarter is used. On Microsoft Windows you
might want to use c:tempjavastarter. This path is called javadir in the following
description.
Open a text editor which supports plain text, e.g., gedit under Linux or Notepad under
Windows and write the following source code.
// a small Java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Warning
Do not use a rich editor like Microsoft Word or LibreOffice for writing Java code. If in
doubt, google for "Plain text editor for [your_OS]".
11. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Save the source code in your javadir directory with the HelloWorld.java filename. The
name of a Java source file must always equal the class name (within the source code) and end
with the .java extension. In this example the filename must be HelloWorld.java, because
the class is called HelloWorld.
3.2. Compile and run your Java program
Open a shell for command line access.
Tip
If you don't know how to do this, google for "How to open a shell under [your_OS]".
Switch to the javadir directory with the command cd javadir, for example, in the above
example via the cd homevogellajavastarter command. Use the ls command (dir
under Microsoft Windows) to verify that the source file is in the directory.
Compile your Java source file into a class file with the following command.
javac HelloWorld.java
Afterwards list again the content of the directory with the ls or dir command. The directory
contains now a file HelloWorld.class. If you see this file, you have successfully compiled
your first Java source code into bytecode.
Tip
By default, the compiler puts each class file in the same directory as its source file. You can
specify a separate destination directory with the -d compiler flag.
You can now start your compiled Java program. Ensure that you are still in the jardir
directory and enter the following command to start your Java program.
12. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
java HelloWorld
The system should write "Hello World" on the command line.
3.3. Using the classpath
You can use the classpath to run the program from another place in your directory.
Switch to the command line, e.g., under Windows Start → Run cmd. Switch to any directory
you want. Type:
java HelloWorld
If you are not in the directory in which the compiled class is stored, then the system will
show an error message: Exception in thread "main" java.lang.NoClassDefFoundError:
test/TestClass
To use the class, type the following command. Replace "mydirectory" with the directory
which contains the test directory. You should again see the "HelloWorld" output.
java -classpath "mydirectory" HelloWorld
4. Java language structure
4.1. Basics: Package, Class and Object
It is important to understand the base terminology of Java in terms of packages, classes and
objects. This section gives an overview of these terms.
4.2. Package
Java groups classes into functional packages.
Packages are typically used to group classes into logical units. For example, all graphical
views of an application might be placed in the same package called
com.vogella.webapplication.views.
13. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
It is common practice to use the reverse domain name of the company as top level package.
For example, the company might own the domain, vogella.com and in this example the Java
packages of this company starts with com.vogella.
Other main reason for the usage of packages is to avoid name collisions of classes. A name
collision occurs if two programmers give the same fully qualified name to a class. The fully
qualified name of a class in Java consists of the package name followed by a dot (.) and the
class name.
Without packages, a programmer may create a Java class called Test. Another programmer
may create a class with the same name. With the usage of packages you can tell the system
which class to call. For example, if the first programmer puts the Test class into package
report and the second programmer puts his class into package xmlreader you can
distinguish between these classes by using the fully qualified name, e.g, xmlreader.Test or
report.Test.
4.3. Class
Def.: Template that describes the data and behavior associated with an instance of that class.
Note
The class can be seen as the blueprint of an object. It describes how an object is created.
In Java source code a class is defined by the class keyword and must start with a capital
letter. The body of a class is surrounded by {}.
package test;
class MyClass {
}
The data associated with a class is stored in variables; the behavior associated to a class or
object is implemented with methods.
A class is contained in a Java source file with the same name as the class plus the .java
extension.
4.4. Object
Def.: An object is an instance of a class.
The object is the real element which has data and can perform actions. Each object is created
based on the class definition.
4.5. Inheritance
A class can be derived from another class. In this case this class is called a subclass. Another
common phrase is that a class extends another class.
14. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
The class from which the subclass is derived is called a superclass.
Inheritance allows a class to inherit the behavior and data definitions of another class.
The following codes demonstrates how a class can extend another class. In Java a class can
only extend a maximum of one class.
package com.vogella.javaintro.base;
class MyBaseClass {
@Override
public void hello() {
System.out.println("Hello from MyBaseClass");
}
}
package com.vogella.javaintro.base;
class MyExtensionClass extends MyBaseClass {
}
4.6. Object as superclass
Every object in Java implicitly extends the Object class. The class defines the following
methods for every Java object:
equals(o1) allows checking if the current object is equal to o1
getClass() returns the class of the object
hashCode() returns an identifier of the current object
toString() gives a string representation of the current object
5. Java interfaces
5.1. What is an interface in Java?
An interfaces is a type similar to a class and is defined via the interface keyword. Like a
class an interface defines methods. Classes can implement the interfaces and by this they
must obey the contract defined in the interface, e.g., the clast provide implementation for all
abstract methods defined in the interface.
5.2. Abstract, default and static methods in Interfaces
An interface can have abstract methods and default methods. A default method is defined via
the default keyword at the beginning of the method signature. All other methods defined in
an interfaces are public and abstract – explicit declaration of these modifiers is optional.
Interfaces can have constants which are always implicitly public, static and final.
The following code shows an example implementation of an interface.
package testing;
15. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
public interface MyInterface {
// constant definition
String URL = "http://www.vogella.com";
// public abstract methods
void test();
void write(String s);
// default method
default String reserveString(String s){
return new StringBuilder(s).reverse().toString();
}
}
The following class implements this interface, its must implement the abstract method and
can use the default methods.
5.3. Implementing Interfaces
A class can implement an interface. In this case it must provide concrete implementations of
the abstract interface methods. If you implement a method defined by an interface, you can
use @Override annotation to indicate to the Java compiler that you actually want to
implement a method defined by this interface. This way the compiler can give you an error in
you mis-typed the name of the method or in the number of arguments.
package com.vogella.javaintro.base;
public class MyClassImpl implements MyInterface {
@Override
public void test() {
}
@Override
public void write(String s) {
}
public static void main(String[] args) {
MyClassImpl impl = new MyClassImpl();
System.out.println(impl.reserveString("Lars Vogel"));
}
}
5.4. Evolving interfaces
Before Java 8 evolving interfaces, e.g., adding new methods to an interface, was not possible
because such a change would break existing implementations. Java 8 introduced default
methods, now you can extend an interface without breaking clients by simply suppling a
default implementation with it. Adding such a default method is a source an binary
compatible change.
A class can always override a default method so supply a better behavior.
16. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
5.5. Multiple inheritance of methods
If a class implements two interfaces and if these interfaces provide the same default method,
Java resolves the correct method for the class by the following rules:
1. Superclass wins always against the superinterface - If a class can inherit a method
from a superclass and a superinterface, the class inherts the superclass method. This is
true for concrete and abstract superclass methods. This rule implies that default
methods are not used if this method is also declared in the superclass chain.
2. Subtypes win over Supertypes - If a class can inherit a method from two interfaces,
and one is a subtype of the other, the class inherts the method from the subtype
3. In all other cases the class needs to implement the default method
The following listing demonstrates listing number 3.
public interface A {
default void m() {}
}
public interface B {
default void m() {}
}
public class C implements A, B {
@Override
public void m() {}
}
In your implementation you can also call the super method you prefer.
public class C implements A, B {
@Override
public void m() {A.super.m();}
}
5.6. Functional interfaces
All interfaces that have only one method are called functional interfaces. Functional
interfaces have the advantage that they can be used together with lambda expressions. See
Section 20.1, “What are lambdas?” to learn more about lambdas, e.g., the type of lambdas is a
functional interface.
The Java compiler automatically identifies functional interfaces. The only requirement is that
they have only one abstract method. However, is possible to capture the design intent with a
@FunctionalInterface annotation.
Several default Java interfaces are functional interfaces:
java.lang.Runnable
java.util.concurrent.Callable
java.io.FileFilter
java.util.Comparator
java.beans.PropertyChangeListener
17. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Java also contains the java.util.function package which contains functional interfaces
which are frequently used such as:
Predicate<T> - a boolean-valued property of an object
Consumer<T> - an action to be performed on an object
Function<T , R> - a function transforming a T to a R
Supplier<T> - provides an instance of T (such as a factory)
UnaryOperator<T> - a function from T to T
BinaryOperator<T> - a function from (T, T) to T
6. Java basic terms
6.1. Override methods and the @Override annotation
If a class extends another class, it inherits the methods from its superclass. If it wants to
change these methods, it can override these methods. To override a method, you use the same
method signature in the source code of the subclass.
To indicate to the reader of the source code and the Java compiler that you have the intention
to override a method, you can use the @Override annotation.
The following code demonstrates how you can override a method from a superclass.
package com.vogella.javaintro.base;
class MyBaseClass {
@Override
public void hello() {
System.out.println("Hello from MyBaseClass");
}
}
package com.vogella.javaintro.base;
class MyExtensionClass2 extends MyBaseClass {
public void hello() {
System.out.println("Hello from MyExtensionClass2");
}
}
Tip
It is good practice to always use the @Override annotation. This way the Java compiler
validates if you did override all methods as intended and prevents errors.
7. The type system of Java
7.1. Primitives and references
Java distinguishes between primitive types (such as boolean, short, int, double, float, char and
byte) and reference types (such as Object and String).
18. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
7.2. Primitives
Primitive types variables represents the number, true/false or character. You cannot call
methods on variables which have a primitive types.
Operators such as *, -, + or / are only supported for primitive types. Only + can also used for
the reference type String to concatenate strings.
7.3. Reference types
Reference types variables represents a reference to an object, e.g., a variable is a pointer to
the real object. If you change the value of a reference type variable, the variable points to a
different object or to null which represents the non-existing object reference. Changing the
value of a reference type variable does not change the attributes of the object is was pointing
to. Also changing the contents of an object does not affect the value of a variable referring to
that object.
7.4. Autoboxing and wrapper types
Every primitive type has in Java a fitting reference type. This reference type allows to store
the value of the primitive type in an object. For example you have java.lang.Integer for
int.
Converting a primitive value into an instance of a wrapper type and vice versa is called
boxing / unboxing. Java performs these operations automatically of necessary. This allows
you to use a primitive as parameter in a method which expects an object of the wrapper type.
This automatic boxing and unboxing is known as autoboxing.
8. Variables and methods
8.1. Variable
Variables allow the Java program to store values during the runtime of the program.
A variable can either be a primitive variable or a reference variable. A primitive variable
contains the value while the reference variable contains a reference (pointer) to the object.
Hence, if you compare two reference variables, you compare if both point to the same object.
To compare objects, use the object1.equals(object2) method call.
8.2. Instance variable
Instance variable is associated with an instance of the class (also called object). Access works
over these objects.
Instance variables can have any access control and can be marked final or transient.
Instance variables marked as final cannot be changed after a value has been assigned to them.
8.3. Local variable
19. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Local (stack) variable declarations cannot have access modifiers.
final is the only modifier available to local variables. This modifier defines that the variable
cannot be changed after the first assignment.
Local variables do not get default values, so they must be initialized before use.
8.4. Methods
A method is a block of code with parameters and a return value. It can be called on the
object.
package com.vogella.javaintro.base;
public class MyMethodExample {
void tester(String s) {
System.out.println("Hello World");
}
}
Methods can be declared with var-args. In this case the method declares a parameter which
accepts everything from zero to many arguments (syntax: type ... name;) A method can only
have one var-args parameter and this must be the last parameter in the method.
Overwrite of a superclass method: A method must be of the exact same return parameter and
the same arguments. Also the return parameter must be the same. Overload methods: An
overloaded method is a method with the same name, but different arguments. The return type
can not be used to overload a method.
8.5. Main method
A public static method with the following signature can be used to start a Java application.
Such a method is typically called main method.
public static void main(String[] args) {
}
8.6. Constructor
A class contains constructors that are invoked to create objects based on the class definition.
Constructor declarations look like method declarations except that they use the name of the
class and have no return type.
A class can have several constructors with different parameters. Each class must define at
least one constructor.
In the following example the constructor of the class expects a parameter.
package com.vogella.javaintro.base;
20. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
public class MyConstructorExample2 {
String s;
public MyConstructorExample2(String s) {
this.s = s;
}
}
If no explicit constructor is defined, the compiler implicitly adds a constructor. If the class is
sub-classed, then the constructor of the super class is always called implicitly in this case.
In the following example the definition of the constructor without parameters (also known as
the empty constructor) is unnecessary. If not specified, the compiler would create one.
package com.vogella.javaintro.base;
public class MyConstructorExample {
// unnecessary: would be created by the compiler if left out
public MyConstructorExample() {
}
}
The naming convention for creating a constructor is the following: classname (Parameter
p1, ...) { } .
Every object is created based on a constructor. This constructor method is the first statement
called before anything else can be done with the object.
9. Modifiers
9.1. Access modifiers
There are three access modifiers keywords available in Java: public, protected and private.
There are four access levels: public, protected, default and private. They define how the
corresponding element is visible to other components.
If something is declared public, e.g., classes or methods can be freely created or called by
other Java objects. If something is declared private, e.g., a method, it can only be accessed
within the class in which it is declared.
The access levels protected and default are similar. A protected class can be accessed from
the package and sub-classes outside the package, while a default class can get accessed only
via the same package.
The following table describes the visibility:
Table 1. Access Level
Modifier Class Package Subclass World
21. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N
9.2. Other modifiers
final methods: cannot be overwritten in a subclass
abstract method: no method body
synchronized method: thread safe, can be final and have any access control
native methods: platform dependent code, apply only to methods
strictfp: class or method
10. Import statements
10.1. Usage of import statements
In Java you have to access a class always via its full-qualified name, i.e., the package name
and the class name.
You can add import statements for classes or packages into your class file, which allow you
to use the related classes in your code without the package qualifier.
10.2. Static imports
Static import is a feature that allows members (fields and methods) which are defined in a
class with the public static access modifier to be used in Java code without specifying the
class in which the member is defined.
The feature provides a typesafe mechanism to include constants into code without having to
reference the class that originally defined the field.
11. More Java language constructs
11.1. Class methods and class variables
Class methods and class variables are associated with the class and not an instance of the
class, i.e., objects. To refer to these elements, you can use the classname and a dot (".")
followed by the class method or class variable name.
22. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Class methods and class variables are declared with the static keyword. Class methods are
also called static methods and class variables are also called static variables or static fields.
An example for the usage of a static field is println of the following statement:
System.out.println("Hello World"). Hereby out is a static field, an object of type
PrintStream and you call the println() method on this object.
If you define a static variable, the Java runtime environment associates one class variable for
a class no matter how many instances (objects) exist. The static variable can therefore be seen
as a global variable.
The following code demonstrates the usage of static fields.
package com.vogella.javaintro.base;
public class MyStaticExample {
static String PLACEHOLDER = "TEST";
static void test() {
System.out.println("Hello");
}
}
package com.vogella.javaintro.base;
public class Tester {
public static void main(String[] args) {
System.out.println(MyStaticExample.PLACEHOLDER);
MyStaticExample.test();
}
}
If a variable should be defined as constant, you declare it with the static and the final
keyword.
The static method runs without any instance of the class, it cannot directly access non-static
variables or methods.
11.2. Abstract class and methods
A class and method can be declared as abstract. An abstract class can not be directly
instantiated.
If a class has at least one method, which only contains the declaration of the method, but not
the implementation, then this class is abstract and can not be instantiated. Sub-classes need
then to define the methods except if they are also declared as abstract.
If a class contains an abstract method, it also needs to get defined with the keyword
abstract.
The following example shows an abstract class.
23. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
package com.vogella.javaintro.base;
public abstract class MyAbstractClass {
abstract double returnDouble();
}
12. Cheat Sheets
The following can be used as a reference for certain task which you have to do.
12.1. Working with classes
While programming Java you have to create several classes, methods, instance variables. The
following uses the package test.
Table 2.
What to do How to do it
Create a new class called MyNewClass.
package test;
public class MyNewClass {
}
Create a new attribute (instance variable) called var1
of type String in the MyNewClass class
package test;
public class MyNewClass {
private String var1;
}
Create a Constructor for your MyNewClass class
which has a String parameter and assigns the value
of it to the var1 instance variable.
package test;
public class MyNewClass {
private String var1;
public MyNewClass(String
para1) {
var1 = para1;
// or this.var1= para1;
}
}
Create a new method called doSomeThing in your
class which does not return a value and has no
parameters.
package test;
public class MyNewClass {
private String var1;
public MyNewClass(String
para1) {
var1 = para1;
// or this.var1= para1;
}
public void doSomeThing() {
}
}
24. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
What to do How to do it
Create a new method called doSomeThing2 in your
class which does not return a value and has two
parameters, an int and a Person
package test;
public class MyNewClass {
private String var1;
public MyNewClass(String
para1) {
var1 = para1;
// or this.var1= para1;
}
public void doSomeThing() {
}
public void doSomeThing2(int
a, Person person) {
}
}
Create a new method called doSomeThing2 in your
class which returns an int value and has three
parameters, two Strings and a Person.
package test;
public class MyNewClass {
private String var1;
public MyNewClass(String
para1) {
var1 = para1;
// or this.var1= para1;
}
public void doSomeThing() {
}
public void doSomeThing2(int
a, Person person) {
}
public int
doSomeThing3(String a, String
b, Person person) {
return 5; // any value
will do for this example
}
}
Create a class called MyOtherClass with two instance
variables. One will store a String, the other will store
a Dog. Create getter and setter for these variables.
package test;
public class MyOtherClass {
String myvalue;
Dog dog;
public String getMyvalue() {
return myvalue;
}
25. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
What to do How to do it
public void
setMyvalue(String myvalue) {
this.myvalue = myvalue;
}
public Dog getDog() {
return dog;
}
public void setDog(Dog dog)
{
this.dog = dog;
}
}
12.2. Working with local variable
A local variable must always be declared in a method.
Table 3.
What to do How to do it
Declare a (local) variable of type String. String variable1;
Declare a (local) variable of type String and assign
"Test" to it.
String variable2 = "Test";
Declare a (local) variable of type Person Person person;
Declare a (local) variable of type Person, create a
new Object and assign the variable to this object.
Person person = new Person();
Declare an array of type String String array[];
Declare an array of type Person and create an array
for this variable which can hold 5 persons.
Person array[]= new Person[5];
Assign 5 to the int variable var1 (which was already
declared);
var1 = 5;
Assign the existing variable pers2 to the exiting
variable pers1;
pers1 = pers2;
Declare an ArrayList variable which can hold
objects of type Person
ArrayList<Person> persons;
Create a new ArrayList with objects of type Person
and assign it to the existing variable persons.
persons = new ArrayList<Person>();
Declare an ArrayList variable which can hold
objects of type Person and create a new Object for it.
ArrayList<Person> persons = new
ArrayList<Person>();
26. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
13. Integrated Development Environment
The previous chapter explained how to create and compile a Java program on the command
line. A Java Integrated Development Environment (IDE) provides lots of ease of use
functionality for creating Java programs. There are other very powerful IDEs available, for
example, the Eclipse IDE.
For an introduction on how to use the Eclipse IDE please see Eclipse IDE Tutorial.
The remaining description uses the phrase: "Create a Java project called...". This refers to
creating a Java project in Eclipse. If you are using a different IDE, please follow the required
steps in that IDE.
14. Exercises - Creating Java objects and methods
14.1. Create a Person class and instantiate it
Create a new Java project called com.vogella.javastarter.exercises1 and a package
with the same name.
Create a class called Person.
Add three instance variables to it, one for storing the first name of the person, one for storing
the last name and one for storing the age of the Person.
Use the constructor of the Person object to set the values to some default value.
Write a public method called writeName() which uses the System.out.println() method to
print the first name of the person to the console.
Create a new class called Main with a public static void main(String[] args). In this
method create an instance of the Person class.
14.2. Use constructor
Add a constructor to your Person class which takes first name, last name and age as
parameter. Assign the values to your instance variables.
In your main method create two objects of type Person and call the writeName method on it.
14.3. Define getter and setter methods
Define methods which allow you to read the values of the instance variables and to set them.
These methods are called setter and getter.
Getters should start with get followed by the variable name whereby the first letter of the
variable is capitalized.
27. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Setter should start with set followed by the variable name whereby the first letter of the
variable is capitalized.
For example, the variable called firstName would have the getFirstName() getter method
and the setFirstName(String s) setter method.
Change your main method so that you create one Person object and use the setter method to
change the last name.
14.4. Create an Address object
Create a new object called Address. The Address should allow you to store the address of a
person.
Add a new instance variable of this type in the Person object. Also, create a getter and setter
for the Address object in the Person object.
15. Solution - Creating Java objects and methods
15.1. Create a Person class and instantiate it
The following is a potential solution for Section 14.1, “Create a Person class and instantiate
it”.
package exercises.exercise04;
class Person {
String firstname = "Jim";
String lastname = "Knopf";
int age = 12;
void writeName() {
// writes the firstname
System.out.println(firstname);
// alternatively, you can combine strings with +
System.out.println(firstname + " " + lastname + "" + age);
}
}
package exercises.exercise04;
public class Main {
public static void main(String[] args) {
Person person = new Person();
person.writeName();
}
}
15.2. Use constructor
package com.vogella.javastarter.exercises1;
28. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
class Person {
String firstName;
String lastName;
int age;
public Person(String a, String b, int value) {
firstName = a;
lastName = b;
age=value;
}
void writeName() {
// Writes the firstname
System.out.println(firstName);
// Alternatively you can combine strings with +
System.out.println(firstName + " " + lastName + "" + age);
}
}
package com.vogella.javastarter.exercises1;
public class Main {
public static void main(String[] args) {
Person person = new Person("Jim", "Knopf" , 12);
person.writeName();
// reuse the same variable and assign a new object to it
person = new Person("Henry", "Ford", 104);
person.writeName();
}
}
15.3. Define getter and setter methods
package com.vogella.javastarter.exercises1;
class Person {
String firstName;
String lastName;
int age;
public Person(String a, String b, int value) {
firstName = a;
lastName = b;
age = value;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
29. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
void writeName() {
// writes the firstname
System.out.println(firstName);
// alternatively, you can combine strings with +
System.out.println(firstName + " " + lastName + "" + age);
}
}
package com.vogella.javastarter.exercises1;
public class Main {
public static void main(String[] args) {
Person person = new Person("Jim", "Knopf", 21);
Person person2 = new Person("Jill", "Sanders", 20);
// Jill gets married to Jim
// and takes his name
person2.setLastName("Knopf");
person2.writeName();
}
}
15.4. Solution - Create an Address object
package com.vogella.javastarter.exercises1;
public class Address {
private String street;
private String number;
private String postalCode;
private String city;
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getNumber() {
return number;
}
30. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
public void setNumber(String number) {
this.number = number;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String toString() {
return street + " " + number + " " + postalCode + " " + city + " "
+ country;
}
}
package com.vogella.javastarter.exercises1;
class Person {
String firstName;
String lastName;
int age;
private Address address;
public Person(String a, String b, int value) {
firstName = a;
lastName = b;
age=value;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
31. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
void writeName() {
// Writes the firstname
System.out.println(firstName);
// Alternatively you can combine strings with +
System.out.println(firstName + " " + lastName + "" + age);
}
}
package com.vogella.javastarter.exercises1;
public class Main {
public static void main(String[] args) {
// I create a person
Person pers = new Person("Jim", "Knopf", 31);
// I set the age of the person to 32
pers.setAge(32);
// just for testing I write this to the console
System.out.println(pers.toString());
/*
* actually System.out.println always calls toString, if you do not
* specify it so you could also have written System.out.println(pers);
*/
// I create an address
Address address = new Address();
// I set the values for the address
address.setCity("Heidelberg");
address.setCountry("Germany");
address.setNumber("104");
address.setPostalCode("69214");
address.setStreet("Musterstr.");
// I assign the address to the person
pers.setAddress(address);
// I do not need address any more
address = null;
32. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
// person is moving to the next house in the same street
pers.getAddress().setNumber("105");
}
}
16. Java statements
The Java language defines certain statements with a predefined meaning. The following
description lists some of them.
16.1. if-then and if-then-else
The if-then statement is a control flow statement. A block of code is only executed when
the test specified by the if part evaluates to true. The optional else block is executed when
the if part evaluates to false.
The following example code shows a class with two methods. The first method demonstrates
the usage of if-then and the second method demonstrates the usage of if-then-else.
16.2. Switch
The switch statement can be used to handle several alternatives if they are based on the same
constant value.
switch (expression) {
case constant1:
command;
break; // will prevent that the other cases or also executed
case constant2:
command;
break;
...
default:
}
// Example:
switch (cat.getLevel()) {
case 0:
return true;
case 1:
if (cat.getLevel() == 1) {
if (cat.getName().equalsIgnoreCase(req.getCategory())) {
return true;
}
}
case 2:
if (cat.getName().equalsIgnoreCase(req.getSubCategory())) {
return true;
}
}
16.3. Boolean Operations
33. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Use == to compare two primitives or to see if two references refer to the same object. Use the
equals() method to see if two different objects are equal.
&& and || are both Short Circuit Methods which means that they terminate once the result of
an evaluation is already clear. Example (true || ...) is always true while (false &&
...) always is always interpreted as false. Usage:
(var !=null && var.method1() ...) ensures that var is not null before doing the real
check.
Table 4. Boolean
Operations Description
==
Is equal, in case of objects the system checks if the reference
variable point to the same object. It will not compare the
content of the objects!
&& And
!= is not equal, similar to ==.
a.equals(b) Checks if string a equals b.
a.equalsIgnoreCase(b) Checks if string a equals b while ignoring lower cases.
If (value ? false :
true) {} Negotiation: return true if value is not true.
17. Loops in Java
17.1. The for loop
A for loop is a repetition control structure that allows you to write a block of code which is
executed a specific number of times. The syntax is the following.
for(initialization; expression; update_statement)
{
//block of code to run
}
The following shows an example for a for loop.
public class ForTest {
public static void main(String args[]) {
for(int i = 1; i < 10; i = i+1) {
System.out.println("value of i : " + i);
}
}
}
34. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Tip
For arrays and collections there is also an enhanced for loop available. This loop is covered in
the Array description.
17.2. The while loop
A while loop is a repetition control structure that allows you to write a block of code which is
executed until a specific condition evaluates to false. The syntax is the following.
while(expression)
{
// block of code to run
}
The following shows an example for a while loop.
public class WhileTest {
public static void main(String args[]) {
int x = 1;
while (x < 10) {
System.out.println("value of x : " + x);
x++;
}
}
}
17.3. The do while loop
The do-while loop is similar to the while loop, with the exception that the condition is
checked after the execution. The syntax is the following.
do
{
// block of code to run
} while(expression);
The following shows an example for a do-while loop.
public class DoTest {
public static void main(String args[]) {
int x = 1;
do {
System.out.println("value of x : " + x);
x++;
} while (x < 10);
}
}
18. Arrays
35. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
18.1. Arrays in Java
An array is a container object that holds a fixed number of values of a single type. An item in
an array is called an element. Every element can be accessed via an index. The first element
in an array is addressed via the 0 index, the second via 1, etc.
package com.vogella.javaintro.array;
public class TestMain {
public static void main(String[] args) {
// declares an array of integers
int[] array;
// allocates memory for 10 integers
array = new int[10];
// initialize values
array[0] = 10;
// initialize second element
array[1] = 20;
array[2] = 30;
array[3] = 40;
array[4] = 50;
array[5] = 60;
array[6] = 70;
array[7] = 80;
array[8] = 90;
array[9] = 100;
}
}
18.2. Enhanced for loop for Arrays and Collections
Arrays and collections can be processed with a simpler for loop.
for(declaration : expression)
{
// body of code to be executed
}
The following code demonstrates its usage.
package com.vogella.javaintro.array;
public class TestMain {
public static void main(String[] args) {
// declares an array of integers
int[] array;
// allocates memory for 10 integers
array = new int[10];
// initialize values
array[0] = 10;
// initialize second element
array[1] = 20;
array[2] = 30;
36. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
array[3] = 40;
array[4] = 50;
array[5] = 60;
array[6] = 70;
array[7] = 80;
array[8] = 90;
array[9] = 100;
for (int i : array) {
System.out.println("Element at index " + i + " :" + array[i]);
}
}
}
19. Strings
19.1. Strings in Java
The String class represents character strings. All string literals, for example, "hello", are
implemented as instances of this class. An instance of this class is an object. Strings are
immutable, e.g., an assignment of a new value to a String object creates a new object.
19.2. String pool in Java
For memory efficiency Java uses a String pool. The string pool allows string literals to be
reused. This is possible because strings in Java are immutable.
If the same string literal is used in several places in the Java code, only one copy of that string
is created.
Whenever a String object is created and gets a string literal assigned, e.g., as in String s =
"constant", the string pool is used. However, the new operator forces a new String copy to
be allocated, for example, in String s = new String("constant"); .
19.3. Compare Strings in Java
To compare the String objects s1 and s2, use the s1.equals(s2) method.
A String comparison with == is incorrect, as == checks for object reference equality. ==
sometimes gives the correct result, as Java uses a String pool. The following example would
work with ==.
This would work as expected.
String a = "Hello";
String b = "Hello";
if (a==b) {
// if statement is true
// because String pool is used and
// a and b point to the same constant
}
37. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
This comparison would fail.
String a = "Hello";
String b = new String("Hello");
if (a==b) {
} else {
// if statement is false
// because String pool is used and
// a and b point to the same constant
}
Warning
Therefore, you should always use the equals() method when you compare strings.
19.4. Working with Strings
The following lists the most common string operations.
Table 5.
Command Description
"Testing".equals(text1);
Return true if text1 is equal to
"Testing". The check is case-sensitive.
"Testing".equalsIgnoreCase(text1);
Return true if text1 is equal to
"Testing". The check is not case-sensitive.
For example, it would also be true for
"testing".
StringBuffer str1 = new
StringBuffer();
Define a new String with a variable length.
str.charat(1);
Return the character at position 1. (Note:
strings are arrays of chars starting with 0)
str.substring(1); Removes the first characters.
str.substring(1, 5);
Gets the substring from the second to the
fifth character.
str.indexOf("Test")
Look for the String "Test" in String str.
Returns the index of the first occurrence of
the specified string.
str.lastIndexOf("ing")
Returns the index of the last occurrence of
the specified String "ing" in the String
str. StringBuffer does not support this
method. Hence first convert the
StringBuffer to String via method
toString.
str.endsWith("ing")
Returns true if str ends with String
"ing"
str.startsWith("Test") Returns true if String str starts with
38. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
Command Description
String "Test".
str.trim() Removes leading and trailing spaces.
str.replace(str1, str2) Replaces all occurrences of str1 by str2
str2.concat(str1); Concatenates str1 at the end of str2.
str.toLowerCase() / str.toUpperCase() Converts the string to lower- or uppercase
str1 + str2 Concatenate str1 and str2
String[] array = myString.split("-");
String[] array2 =
myString.split(".");
Splits the character separated myString into
an array of strings. Attention: the split string
is a regular expression, so if you using
special characters which have a meaning in
regular expressions, you need to quote
them. In the second example the . is used
and must be quoted by two backslashes.
20. Lambdas
20.1. What are lambdas?
The Java programming language supports lambdas as of Java 8. A lambda expression is a
block of code with parameters. Lambdas allows to specify a block of code which should be
executed later. If a method expects a functional interface as parameter it is possible to pass in
the lambda expression instead.
The type of a lambda expression in Java is a functional interface.
20.2. Difference between a lambda expression and a closure
A lambda is an anonymous function, e.g., it can be defined as parameter. A closure is any
function which closes over the environment in which it was defined. This means that it can
access variables not in its parameter list and assigned to a variable.
Java supports lambdas but not closures.
20.3. Purpose of lambda expressions
Using lambdas allows to use a condensed syntax compared to other Java programming
constructs. For example the Collections in Java 8 have a forEach method which accepts a
lambda expression.
List<String> list = new ArrayList<>();
list.add("vogella.com");
list.add("google.com");
list.add("heise.de");
list.forEach(System.out::println);
39. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
20.4. Using method references
You can use method references in a lambda expression. Method reference define the method
to be called via CalledFrom::method. CalledFrom can be
instance::instanceMethod
SomeClass::staticMethod
SomeClass::instanceMethod
List<String> list = new ArrayList<>();
list.add("vogella.com");
list.add("google.com");
list.add("heise.de");
list.forEach(s-> System.out.println(s));
21. Streams
21.1. What are Streams in Java 8?
A stream from the java.util.stream package is is a sequence of elements from a source
that supports aggregate operations.
21.2. IntStream
Allow to create a stream of sequence of primitive int-valued elements supporting sequential
and parallel aggregate operations.
package com.vogella.java.streams;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
public class IntStreamExample {
public static void main(String[] args) {
// printout the numbers from 1 to 100
IntStream.range(1, 101).forEach(s -> System.out.println(s));
// create a list of integers for 1 to 100
List<Integer> list = new ArrayList<>();
IntStream.range(1, 101).forEach(it -> list.add(it));
System.out.println("Size " + list.size());
}
}
21.3. Reduction operations with streams and lambdas
Allow to create a stream of sequence of primitive int-valued elements supporting sequential
and parallel aggregate operations.
package com.vogella.java.streams;
40. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
public class Task {
private String summary;
private int duration;
public Task(String summary, int duration) {
this.summary = summary;
this.duration = duration;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
}
package com.vogella.java.streams;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class StreamTester {
public static void main(String[] args) {
Random random = new Random();
// Generate a list of random task
List<Task> values = new ArrayList<>();
IntStream.range(1, 20).forEach(i -> values.add(new Task("Task" +
random.nextInt(10), random.nextInt(10))));
// get a list of the distinct task summary field
List<String> resultList = values.stream().filter(t -> t.getDuration() >
5).map(t -> t.getSummary()).distinct().collect(Collectors.toList());
System.out.println(resultList);
// get a concatenated string of Task with a duration longer than 5
hours
String collect = values.stream().filter(t -> t.getDuration() > 5).map(t
-> t.getSummary()).distinct().collect(Collectors.joining("-"));
System.out.println(collect);
}
}
22. Type Conversion
41. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
If you use variables of different types Java requires for certain types an explicit conversion.
The following gives examples for this conversion.
22.1. Conversion to String
Use the following to convert from other types to Strings
// Convert from int to String
String s1 = String.valueOf (10); // "10"
// Convert from double to String
String s2 = String.valueOf (Math.PI); // "3.141592653589793"
// Convert from boolean to String
String s3 = String.valueOf (1 < 2); // "true"
// Convert from date to String
String s4 = String.valueOf (new Date()); // "Tue Jun 03 14:40:38 CEST 2003"
22.2. Conversion from String to Number
// Conversion from String to int
int i = Integer.parseInt(String);
// Conversion from float to int
float f = Float.parseFloat(String);
// Conversion from double to int
double d = Double.parseDouble(String);
The conversion from string to number is independent from the locale settings, e.g., it is
always using the English notification for number. In this notification a correct number format
is "8.20". Thed German number "8,20" would result in an error.
To convert from a German number, you have to use the NumberFormat class. The challenge
is that when the value is, for example, 98.00 then the NumberFormat class would create a
Long which cannot be casted to Double. Hence the following complex conversion class.
private Double convertStringToDouble(String s) {
Locale l = new Locale("de", "DE");
Locale.setDefault(l);
NumberFormat nf = NumberFormat.getInstance();
Double result = 0.0;
try {
if (Class.forName("java.lang.Long").isInstance(nf.parse(s))) {
result = Double.parseDouble(String.valueOf(nf.parse(s)));
} else {
result = (Double) nf.parse(new String(s));
}
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (ParseException e1) {
e1.printStackTrace();
}
return result;
}
22.3. Double to int
42. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
int i = (int) double;
22.4. SQL Date conversions
Use the following to convert a Date to a SQL date
package test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class ConvertDateToSQLDate {
private void convertDateToSQL(){
SimpleDateFormat template =
new SimpleDateFormat("yyyy-MM-dd");
java.util.Date enddate =
new java.util.Date("10/31/99");
java.sql.Date sqlDate =
java.sql.Date.valueOf(template.format(enddate));
}
public static void main(String[] args) {
ConvertDateToSQLDate date = new ConvertDateToSQLDate();
date.convertDateToSQL();
}
}
23. Schedule tasks
Java allows you to schedule tasks. A scheduled tasks can perform once or several times.
java.util.Timer and java.util.TimerTask can be used to schedule tasks. The object
which implements TimeTask will then be performed by the Timer based on the given
interval.
package schedule;
import java.util.TimerTask;
public class MyTask extends TimerTask {
private final String string;
private int count = 0;
public MyTask(String string) {
this.string = string;
}
@Override
public void run() {
count++;
System.out.println(string + " called " + count);
}
}
43. Fore more visit:http://shreedhoon.com/training/index.php
http://shreedhoon.com
package schedule;
import java.util.Timer;
public class ScheduleTest {
public static void main(String[] args) {
Timer timer = new Timer();
// wait 2 seconds (2000 milli-secs) and then start
timer.schedule(new MyTask("Task1"), 2000);
for (int i = 0; i < 100; i++) {
// wait 1 seconds and then again every 5 seconds
timer.schedule(new MyTask("Task " + i), 1000, 5000);
}
}
}
Tip
Improved job scheduling is available via the open source framework quartz. See
http://www.onjava.com/lpt/a/4637 or http://www.quartz-scheduler.org/ for an explanation.
24. Support this website
This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this
tutorial is distributed under the Eclipse Public License. See the vogella License page for
details on the terms of reuse.
Writing and updating these tutorials is a lot of work. If this free community service was
helpful, you can support the cause by giving a tip as well as reporting typos and factual
errors.
Please consider a contribution if this article helped you. It will help to maintain our content
and our Open Source activities.
24.2. Questions and Discussion
If you find errors in this tutorial, please notify me (see the top of the page). Please note that
due to the high volume of feedback I receive, I cannot answer questions to your
implementation. Ensure you have read the vogella FAQ as I don't respond to questions
already answered there.
25. Links and Literature