This document provides an overview and outline of a lesson on variables and types in Java. The key points covered include:
- Variables are names for locations in memory that hold values. Primitive data types include numerical, character, and boolean values. Complex objects are instances of classes.
- Variables are declared with a data type, name, and optional initial value. Primitive values can be output and converted between types through casting or automatic promotion.
- Expressions combine operators and operands to compute results. Operators have precedence that determines the order of evaluation. Assignment operators store the result of an expression into a variable.
- The lesson covers primitive data types, variables, expressions, output, conversion, and creating objects
Classes allow users to bundle data and functions together. A class defines data members and member functions. Data members store data within each object, while member functions implement behaviors. Classes support access specifiers like public and private to control access to members. Objects are instances of classes that allocate memory for data members. Member functions can access object data members and are called on objects using dot notation. Friend functions allow non-member functions to access private members of classes.
Object-oriented programming uses abstraction and encapsulation through abstract data types (ADTs). An ADT defines a data type and its interface independently of its implementation. This allows information hiding and modular program design. Common languages like C++, Java, and Ruby support ADTs through classes or modules, which package data with methods, support inheritance and polymorphism, and provide visibility control through private/public access specifiers. Parameterized ADTs allow a data type to work with different element types. Namespaces and packages provide separate scopes to avoid naming conflicts.
Learn about how to define and invoke methods in Java, how to use parameters and return results. Watch the video lesson here:
https://softuni.org/code-lessons/java-foundations-certification-methods
The document discusses key concepts related to arrays in Java including:
1) Declaring and initializing arrays of primitive and object types.
2) Creating single and multi-dimensional arrays.
3) Copying elements between arrays using System.arrayCopy().
The document discusses various Java programming concepts including identifiers, keywords, primitive types, variables, operators, and flow control statements. It defines identifiers, keywords, the 8 primitive types including boolean, char, byte, short, int, long, float, and double. It covers variable declaration and initialization, literals, and reference types. The document also explains operators such as logical, bitwise, assignment, string concatenation, and casting operators. Finally, it provides an overview of branching and looping statements including if/else, switch, for, while, do/while and flow control statements.
The document discusses various object-oriented programming concepts in C#, including abstraction, encapsulation, inheritance, polymorphism, interfaces, abstract classes, virtual methods, classes, sealed classes, and provides code examples for foreach loops, switch statements, arrays, data types, boxing and unboxing, overloading and overriding, interfaces, classes vs. structures, access modifiers, abstract classes, and sealed classes.
Three key points about the document:
1. Java has several primitive data types including boolean, char, byte, short, int, long, float, and double. Arrays allow grouping of multiple variables of the same type.
2. Arrays are dynamically allocated objects in Java. To create an array, the type and size must be specified using new, such as int[] numbers = new int[100]. Individual elements can then be accessed by index like numbers[25].
3. Type conversions may occur automatically between compatible types like int and long. Incompatible types require casting, such as (double)value to convert an int to a double. Arrays can be used to store and average multiple
Classes allow users to bundle data and functions together. A class defines data members and member functions. Data members store data within each object, while member functions implement behaviors. Classes support access specifiers like public and private to control access to members. Objects are instances of classes that allocate memory for data members. Member functions can access object data members and are called on objects using dot notation. Friend functions allow non-member functions to access private members of classes.
Object-oriented programming uses abstraction and encapsulation through abstract data types (ADTs). An ADT defines a data type and its interface independently of its implementation. This allows information hiding and modular program design. Common languages like C++, Java, and Ruby support ADTs through classes or modules, which package data with methods, support inheritance and polymorphism, and provide visibility control through private/public access specifiers. Parameterized ADTs allow a data type to work with different element types. Namespaces and packages provide separate scopes to avoid naming conflicts.
Learn about how to define and invoke methods in Java, how to use parameters and return results. Watch the video lesson here:
https://softuni.org/code-lessons/java-foundations-certification-methods
The document discusses key concepts related to arrays in Java including:
1) Declaring and initializing arrays of primitive and object types.
2) Creating single and multi-dimensional arrays.
3) Copying elements between arrays using System.arrayCopy().
The document discusses various Java programming concepts including identifiers, keywords, primitive types, variables, operators, and flow control statements. It defines identifiers, keywords, the 8 primitive types including boolean, char, byte, short, int, long, float, and double. It covers variable declaration and initialization, literals, and reference types. The document also explains operators such as logical, bitwise, assignment, string concatenation, and casting operators. Finally, it provides an overview of branching and looping statements including if/else, switch, for, while, do/while and flow control statements.
The document discusses various object-oriented programming concepts in C#, including abstraction, encapsulation, inheritance, polymorphism, interfaces, abstract classes, virtual methods, classes, sealed classes, and provides code examples for foreach loops, switch statements, arrays, data types, boxing and unboxing, overloading and overriding, interfaces, classes vs. structures, access modifiers, abstract classes, and sealed classes.
Three key points about the document:
1. Java has several primitive data types including boolean, char, byte, short, int, long, float, and double. Arrays allow grouping of multiple variables of the same type.
2. Arrays are dynamically allocated objects in Java. To create an array, the type and size must be specified using new, such as int[] numbers = new int[100]. Individual elements can then be accessed by index like numbers[25].
3. Type conversions may occur automatically between compatible types like int and long. Incompatible types require casting, such as (double)value to convert an int to a double. Arrays can be used to store and average multiple
The document discusses key concepts in object-oriented programming including classes, objects, data encapsulation, inheritance, and polymorphism. It defines a class as a blueprint for objects that describes their properties and behaviors. An object is an instance of a class. Classes contain data members and member functions. Data hiding is achieved through declaring data members as private while member functions can be public or private. The document also discusses constructors, destructors, operator overloading, inheritance and polymorphism.
This document discusses objects as function arguments and static class members in C++. It explains that objects can be passed to functions by value or reference, and the differences between the two. It also describes how static class members, including variables and functions, work. Static members are shared across all objects of a class and can be accessed directly via the class name, unlike non-static members which require an object instance. An example class demonstrating static and non-static members and functions is provided.
In this lesson you will learn how to use basic syntax, conditions, if-else statements and loops (for-loop, while-loop and do-while-loop) in Java and how to use the debugger.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-basic-syntax-conditions-and-loops
Functions are the building blocks of C++ and are used to reduce program size by calling reusable code in different places. Functions can return values using the return statement. Function prototypes provide interface details like data types and arguments to the compiler. Parameters can be passed by reference, allowing the calling function to modify the original argument. Inline and recursive functions are also discussed. Classes are user-defined data types that contain data members and member functions. Member functions can be defined inside or outside the class.
The document discusses classes and objects in object-oriented programming. It defines a class as a blueprint for objects that bind data and functions together. A class defines data members and member functions. Objects are instances of a class that can access class data and functions. The document provides examples of defining a class called "test" with private and public members, and creating objects of the class to demonstrate accessing members.
The document discusses classes, methods, and objects in C#. It explains that classes define methods and properties, and methods perform actions and can take parameters and return values. It provides examples of commonly used methods in classes like Console, Math, and Random. It also discusses how to define classes with data members and methods, and how to create objects from classes which allows calling instance methods on those objects. Classes serve both as program modules containing static methods and data, and as blueprints for generating objects with their own state and behavior.
Java Foundations: Data Types and Type ConversionSvetlin Nakov
Learn how to use data types and variables in Java, how variables are stored in the memory and how to convert from one data type to another.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-data-types-and-variables
Java's eight primitive data types each have a corresponding wrapper class that allows them to be used as objects. The wrapper classes are in the java.lang package and include classes like Integer and Double. Wrapper classes "wrap" the primitive types in objects. For example, an Integer object holds an int value. Wrapper classes have methods to convert between the primitive type and its object representation.
Object-oriented programming groups related data and functions into packages called classes. Classes define the type of an object, and objects are instantiated from classes. There are three access specifiers in C++ that control access to class members: public, private, and protected. Member functions are usually declared as public to access the privately declared data members. Classes allow data encapsulation which hides implementation details and only exposes interfaces.
This document provides an overview of dictionaries, hash tables, and sets. It discusses the dictionary abstract data type and how it can be implemented using hash tables. It covers hashing, collision resolution strategies, and the .NET Dictionary<TKey, TValue> class. It also discusses sets and the HashSet<T> and SortedSet<T> classes, comparing their time complexities.
This document provides an overview of object-oriented programming concepts like classes, objects, encapsulation, inheritance, polymorphism, and data hiding. It explains key OOP concepts like classes define custom data types with attributes and methods, objects are instances of classes, encapsulation groups related data and code, inheritance creates specialized classes from general classes, polymorphism allows one interface for multiple forms. It also discusses concepts like abstract classes, interfaces, constructors, destructors, operator overloading and access modifiers for data hiding. Overall, the document serves as an introduction to fundamental OOP principles in C++.
In this chapter we will understand how to define custom classes and their elements. We will learn to declare fields, constructors and properties for the classes. We will revise what a method is and we will broaden our knowledge about access modifiers and methods.
C++ supports templates to implement generic programming. Templates allow generating a family of classes or functions to handle different data types. A class created from a class template is called a template class. The process of creating a template class is known as instantiation. Like other functions, template functions can be overloaded. Non-type parameters can also be used as arguments for templates.
The document provides an introduction to variables in C#, including value types like integers and reference types like objects. It discusses defining and assigning values to variables, and differences between static and non-static classes. Examples show creating a basic console application in C# and getting input from the user via arguments or keyboard. Exercises guide practicing variable usage, type conversion, and writing simple programs to calculate averages and swap values.
This document discusses Java data types, variables, and methods. It covers primitive data types like int, float, and boolean. It describes rules for identifiers and conventions for naming variables and classes. The document defines parameter types, implicit and explicit parameters, and how to call methods. It explains constructing objects with the new operator and accessor and mutator methods. The summary concludes with a discussion of static methods and how to call them without an object.
This document discusses constructors and destructors in C# classes. It explains that objects must be instantiated using the "new" keyword before their methods can be called. Static methods can be called directly on the class without creating an object instance. Instance variables are unique to each object, while static variables are shared among all objects of a class. The document uses several code examples to demonstrate how to properly create object instances and call both static and instance methods and variables.
The document defines classes and methods in Java.
It discusses:
1) The syntax for defining a class with modifiers, data declarations, and method definitions.
2) How a class can contain data declarations and method declarations to store information and perform behaviors.
3) The structure of a method including the header, parameters, and body.
4) How to define constructors, static methods, and overload methods in a class.
The document discusses methods in Java programming. It explains that methods can be used to divide large blocks of code into smaller, more manageable pieces by grouping related lines of code into reusable functions. This improves readability and maintainability of programs. The document provides examples of using methods without and with parameters and return values. It also covers defining your own methods and using methods from Java library classes.
This document outlines the agenda for a lesson on building forms in front-end web development. It discusses reviewing form elements, the remaining class schedule, updates on students' final projects including milestones and due dates, and proposed labs to develop a to-do list application through building forms or reviewing a tutorial. Time is allotted for working on final projects and walking through code reviews.
This document provides an overview of CSS (Cascading Style Sheets) for web development. It defines CSS as a simple design language that separates the structure of HTML elements from their presentation. The document then covers the advantages of CSS, CSS syntax using selectors, properties, and values, examples of inline, embedded, external, and imported CSS, and different types of CSS selectors. It aims to simplify the process of making web pages presentable using CSS.
The document discusses key concepts in object-oriented programming including classes, objects, data encapsulation, inheritance, and polymorphism. It defines a class as a blueprint for objects that describes their properties and behaviors. An object is an instance of a class. Classes contain data members and member functions. Data hiding is achieved through declaring data members as private while member functions can be public or private. The document also discusses constructors, destructors, operator overloading, inheritance and polymorphism.
This document discusses objects as function arguments and static class members in C++. It explains that objects can be passed to functions by value or reference, and the differences between the two. It also describes how static class members, including variables and functions, work. Static members are shared across all objects of a class and can be accessed directly via the class name, unlike non-static members which require an object instance. An example class demonstrating static and non-static members and functions is provided.
In this lesson you will learn how to use basic syntax, conditions, if-else statements and loops (for-loop, while-loop and do-while-loop) in Java and how to use the debugger.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-basic-syntax-conditions-and-loops
Functions are the building blocks of C++ and are used to reduce program size by calling reusable code in different places. Functions can return values using the return statement. Function prototypes provide interface details like data types and arguments to the compiler. Parameters can be passed by reference, allowing the calling function to modify the original argument. Inline and recursive functions are also discussed. Classes are user-defined data types that contain data members and member functions. Member functions can be defined inside or outside the class.
The document discusses classes and objects in object-oriented programming. It defines a class as a blueprint for objects that bind data and functions together. A class defines data members and member functions. Objects are instances of a class that can access class data and functions. The document provides examples of defining a class called "test" with private and public members, and creating objects of the class to demonstrate accessing members.
The document discusses classes, methods, and objects in C#. It explains that classes define methods and properties, and methods perform actions and can take parameters and return values. It provides examples of commonly used methods in classes like Console, Math, and Random. It also discusses how to define classes with data members and methods, and how to create objects from classes which allows calling instance methods on those objects. Classes serve both as program modules containing static methods and data, and as blueprints for generating objects with their own state and behavior.
Java Foundations: Data Types and Type ConversionSvetlin Nakov
Learn how to use data types and variables in Java, how variables are stored in the memory and how to convert from one data type to another.
Watch the video lesson and access the hands-on exercises here: https://softuni.org/code-lessons/java-foundations-certification-data-types-and-variables
Java's eight primitive data types each have a corresponding wrapper class that allows them to be used as objects. The wrapper classes are in the java.lang package and include classes like Integer and Double. Wrapper classes "wrap" the primitive types in objects. For example, an Integer object holds an int value. Wrapper classes have methods to convert between the primitive type and its object representation.
Object-oriented programming groups related data and functions into packages called classes. Classes define the type of an object, and objects are instantiated from classes. There are three access specifiers in C++ that control access to class members: public, private, and protected. Member functions are usually declared as public to access the privately declared data members. Classes allow data encapsulation which hides implementation details and only exposes interfaces.
This document provides an overview of dictionaries, hash tables, and sets. It discusses the dictionary abstract data type and how it can be implemented using hash tables. It covers hashing, collision resolution strategies, and the .NET Dictionary<TKey, TValue> class. It also discusses sets and the HashSet<T> and SortedSet<T> classes, comparing their time complexities.
This document provides an overview of object-oriented programming concepts like classes, objects, encapsulation, inheritance, polymorphism, and data hiding. It explains key OOP concepts like classes define custom data types with attributes and methods, objects are instances of classes, encapsulation groups related data and code, inheritance creates specialized classes from general classes, polymorphism allows one interface for multiple forms. It also discusses concepts like abstract classes, interfaces, constructors, destructors, operator overloading and access modifiers for data hiding. Overall, the document serves as an introduction to fundamental OOP principles in C++.
In this chapter we will understand how to define custom classes and their elements. We will learn to declare fields, constructors and properties for the classes. We will revise what a method is and we will broaden our knowledge about access modifiers and methods.
C++ supports templates to implement generic programming. Templates allow generating a family of classes or functions to handle different data types. A class created from a class template is called a template class. The process of creating a template class is known as instantiation. Like other functions, template functions can be overloaded. Non-type parameters can also be used as arguments for templates.
The document provides an introduction to variables in C#, including value types like integers and reference types like objects. It discusses defining and assigning values to variables, and differences between static and non-static classes. Examples show creating a basic console application in C# and getting input from the user via arguments or keyboard. Exercises guide practicing variable usage, type conversion, and writing simple programs to calculate averages and swap values.
This document discusses Java data types, variables, and methods. It covers primitive data types like int, float, and boolean. It describes rules for identifiers and conventions for naming variables and classes. The document defines parameter types, implicit and explicit parameters, and how to call methods. It explains constructing objects with the new operator and accessor and mutator methods. The summary concludes with a discussion of static methods and how to call them without an object.
This document discusses constructors and destructors in C# classes. It explains that objects must be instantiated using the "new" keyword before their methods can be called. Static methods can be called directly on the class without creating an object instance. Instance variables are unique to each object, while static variables are shared among all objects of a class. The document uses several code examples to demonstrate how to properly create object instances and call both static and instance methods and variables.
The document defines classes and methods in Java.
It discusses:
1) The syntax for defining a class with modifiers, data declarations, and method definitions.
2) How a class can contain data declarations and method declarations to store information and perform behaviors.
3) The structure of a method including the header, parameters, and body.
4) How to define constructors, static methods, and overload methods in a class.
The document discusses methods in Java programming. It explains that methods can be used to divide large blocks of code into smaller, more manageable pieces by grouping related lines of code into reusable functions. This improves readability and maintainability of programs. The document provides examples of using methods without and with parameters and return values. It also covers defining your own methods and using methods from Java library classes.
This document outlines the agenda for a lesson on building forms in front-end web development. It discusses reviewing form elements, the remaining class schedule, updates on students' final projects including milestones and due dates, and proposed labs to develop a to-do list application through building forms or reviewing a tutorial. Time is allotted for working on final projects and walking through code reviews.
This document provides an overview of CSS (Cascading Style Sheets) for web development. It defines CSS as a simple design language that separates the structure of HTML elements from their presentation. The document then covers the advantages of CSS, CSS syntax using selectors, properties, and values, examples of inline, embedded, external, and imported CSS, and different types of CSS selectors. It aims to simplify the process of making web pages presentable using CSS.
This document provides an introduction to HTML programming. It explains that HTML is the language used to create webpages and stands for Hypertext Markup Language. It describes how HTML uses tags to tell browsers how to display information and lists some common tags like <html>, <body>, <h1>, and <p>. The document guides students through creating their first webpage and encourages experimenting with different tags.
The document provides a 10 step guide for getting started with HTML by opening Notepad, typing the basic HTML tags (<html>, <head>, <title>, <body>, etc.), using tags to create paragraphs and other elements, and closing all tags properly. The goal is to teach HTML basics like making a title, body, paragraphs, and using tags correctly to create a simple functioning website. The document concludes by having the reader create their own basic website to assess their understanding of the material.
This document outlines the agenda and content for a lesson on front-end web development layout. The lesson will cover using classes, IDs and divs to target elements, HTML5 structural elements like header, nav, article, etc, floats for layout, and building a fashion blog project. Students will practice these skills by reworking pages to use the new elements, adding floats, and completing the fashion blog.
The document provides an overview of Cascading Style Sheets (CSS). CSS allows you to create rules that control the presentation of HTML elements. CSS syntax includes selectors that point to HTML elements and declaration blocks that contain properties and values to style those elements. There are different ways to insert CSS into HTML documents, including external style sheets, internal style sheets, and inline styles. CSS uses the box model to style elements, which includes properties for dimensions, padding, borders, and margins.
1) O documento discute como cultivar interações com confiança em sistemas interativos, analisando o conceito de confiança e propondo um modelo sociotécnico de confiança.
2) O modelo identifica indicadores como expectativas, percepção racional e emocional que influenciam a predisposição para confiar e cooperar.
3) Também aborda desafios no desenvolvimento de software interativo para cultivar confiança, propondo abordagens interdisciplinares que considerem tanto aspectos técnicos como sociais.
This HTML lesson document provides syntax tips and instructions for revising a file from Lesson 4. It recommends using lowercase tags and quotes around attribute values. It also lists changes to make such as adding font colors, multiple attributes per tag, and nested tags in a specific order, with instructions to take a screenshot of the final HTML file.
A design space for Trust-enabling Interaction DesignSónia
This document discusses trust-enabling interaction design from multiple perspectives. It examines trust from HCI, social, and technical views. Key points discussed include:
- Trust is a key element in human relationships and enables more decisive actions and smooth activities.
- A multidiciplinary approach is needed as trust has been studied in fields like sociology, political science, economics, and more.
- In human-computer interactions, trust is important and qualities like honesty, predictability, and benevolence can help enable trust.
- A proposed model examines factors that influence user trust predisposition and systems' trustworthiness. Designing for qualities like enabling honest behavior and facilitating prediction of others can help foster social engagement
This document outlines the agenda for a lesson on advanced CSS. It will cover the CSS box model, nested selectors, and templates. Students will then work on an assignment during lab time to build a fashion blog using these CSS concepts. They will be expected to complete the blog for homework. Key topics include the box model dimensions including padding and borders, applying CSS to HTML templates, and starting on the fashion blog assignment.
This document provides an overview of arrays in front-end web development. It discusses using arrays to store collections of data like images and manipulating those arrays. The key points covered are:
- Arrays can be used to store lists of related items and elements can be accessed by their index number.
- Common ways to declare an array include using the Array constructor or literal notation.
- The length property can be used to find out how many elements an array contains.
- Arrays can be iterated over using forEach and elements can be added or overwritten at any index.
- The document proposes a lab for students to create an image carousel using arrays and jQuery's each method to practice
The document provides an example of HTML markup for a biography on Thelonious Monk. Key elements include headings (H1-H3) to structure sections on Monk's life and discography. Paragraphs of text, images, and links are included. Lists (OL and UL) detail albums. Embedded media is added with iframe. Div elements are used to group related content. The HTML demonstrates common tags for adding structure and formatting to a web page.
This document provides an overview of form basics for front-end web development. It discusses the main form tags like <form>, <input>, <select>, <option>, <label>, and <textarea> as well as their attributes. It also covers other form elements like fieldsets, legends, and form validation. The document includes code examples and indicates that the goal is to build a form through code-along examples to demonstrate incorporating these form elements and techniques.
This document discusses human-computer trust from both an HCI and trust perspective. It examines trust as a crucial element in human relationships and represents value-centered interactions between humans and computers. The research aims to identify the social values and qualities that underlie people's trust beliefs and how those trustworthy qualities are represented with technology becoming more ubiquitous. Through literature reviews and participatory design sessions, the research models trust as a social phenomenon and validates how trust relates to users' activities. It identifies factors like honesty, reliability, and predictability that influence users' trust and willingness to cooperate. The resulting human-computer trust model shows how qualities, beliefs, intentions and attitudes contribute to relationships and commitments between humans and computers.
This document outlines the agenda for an advanced CSS lesson which includes a review, discussion of HTML templates, an in-depth look at the box model including how width and height are calculated, nested selectors, getting started, and a lab time with homework to complete a fashion blog. The lesson will spend 50 minutes exploring the box model in particular, covering what elements are, and how width and height are affected by padding, borders, and other properties.
JavaScript is an object-oriented scripting language used to make webpages interactive. It can access and modify the content, structure, and style of an HTML document. JavaScript code can be embedded directly in HTML, or linked from external .js files. The Document Object Model (DOM) represents an HTML document as nodes that JavaScript can manipulate by accessing properties and methods. Functions are blocks of JavaScript code that perform tasks when called.
This document outlines an agenda for a web development lab on building a memory game. It allocates 180 minutes to complete the lab and provides a detailed breakdown of tasks including developing HTML and CSS structure in 50 minutes, writing pseudocode in 10 minutes, and coding the JavaScript application in 120 minutes. It also lists optional bonus activities like adding shuffling, move counting, and a "cheat" mode. An alternate agenda is proposed focusing on jQuery plugins, but the document returns to describing the memory game lab in detail.
This document provides an overview of HTML form basics, including the main tags and attributes used to build forms. It discusses:
- The <form> tag and its attributes like action, method, and enctype for defining form properties and behavior.
- Common <input> field types like text, radio buttons, checkboxes, and submit buttons. Other attributes for inputs like name, value, placeholder are also covered.
- Other form tags like <select>, <option>, <label>, <textarea>, <fieldset>, and <legend> and how to use them.
- Attributes added in HTML5 for form validation and how to add validation using JavaScript libraries.
- Examples are provided and the
In this chapter we will get familiar with primitive types and variables in Java – what they are and how to work with them. First we will consider the data types – integer types, real types with floating-point, Boolean, character, string and object type. We will continue with the variables, with their characteristics, how to declare them, how they are assigned a value and what is variable initialization.
The document discusses typecasting in C#. It describes implicit and explicit typecasting. Implicit typecasting converts lower data types to higher types automatically, while explicit typecasting converts higher to lower types and requires a cast. It discusses built-in conversion methods like ToInt32() and Parse() for converting between types like string to integer. Examples are provided to demonstrate parsing strings to perform mathematical operations and converting between types.
The document discusses type conversion in C# programming. It describes two main types of type conversion: implicit and explicit. Implicit conversion involves converting lower data types to higher types, while explicit conversion involves converting higher types to lower types which requires casts. It provides examples of implicit conversion from int to long, and explicit conversion from long to int using casting. The document also discusses different methods for explicit type conversion, including C++-style casting, parsing, and using conversion class methods.
The document defines and describes the 8 primitive data types in Java - boolean, char, byte, short, int, long, float, and double. It covers their characteristics such as allowed values, literals, and default types. It also discusses reference types, object construction, memory allocation, passing arguments by value, and control flow statements like if/else, switch, and loops. Key topics are summarized in 3 sentences or less.
This document discusses Java primitive data types and operators. It describes the 8 primitive types in Java - boolean, byte, char, double, float, int, long, short - including their ranges and behaviors. It also covers literals, variables, scopes and lifetimes. For operators, it explains arithmetic, relational, logical, assignment, increment/decrement, shift, and ternary operators. It includes examples to demonstrate the usage of various data types and operators in Java programs.
Java is a cross-platform language originally developed by James Gosling at Sun Microsystems. It enables writing programs for many operating systems using a C/C++-like syntax but with a simpler object model and fewer low-level facilities. Java programs are compiled to bytecode that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Common Java development tools include Eclipse and NetBeans integrated development environments.
This document provides an overview of key concepts in the Java programming language, including:
- Java is an object-oriented language that is simpler than C++ and supports features like platform independence.
- The Java development environment includes tools for compiling, debugging, and running Java programs.
- Java programs work with basic data types like int and double, as well as user-defined classes, variables, and arrays.
- The document explains operators, control structures, formatting output, and the basics of classes and objects in Java.
Let's explore some other fundamental programming concepts
Chapter 2 focuses on:
character strings
primitive data
the declaration and use of variables
expressions and operator precedence
data conversions
C# is an object-oriented programming language where all program logic must be contained within classes. It has features like garbage collection, inheritance, interfaces, namespaces, and data types similar to Java. Key concepts include value types vs reference types, boxing and unboxing, arrays, enums, structs, and parameter passing modes like pass by value, reference, and output. The language has control structures like if/else, switch, while, for, and foreach loops to control program flow. Methods can be instance methods or static methods.
This document provides an overview of basic Java programming concepts including:
- Java programs require a main method inside a class and use print statements for output.
- Java has primitive data types like int and double as well as objects. Variables are declared with a type.
- Control structures like if/else and for loops work similarly to other languages. Methods can call themselves recursively.
- Basic input is done through dialog boxes and output through print statements. Formatting is available.
- Arrays are objects that store multiple values of a single type and know their own length. Strings are immutable character arrays.
This document discusses principles for writing clean code in functions. It recommends that functions should be small, do one thing, have descriptive names, and avoid side effects. Functions with many arguments or switch statements are harder to understand. Exceptions should be used instead of return codes to indicate errors. Overall, following best practices for functions helps produce code that is easy to read and maintain.
The document discusses templates in C++. It explains that templates allow functions and classes to work with different data types using a single code definition. Template functions are called function templates, and template classes are called class templates. The document provides examples of defining class and function templates, and overloading template functions. It demonstrates how templates can be used to create generic functions that operate on multiple types of data.
02 functions, variables, basic input and output of c++Manzoor ALam
This document discusses computer programming functions, variables, and basic input/output in C and C++. It covers:
- Defining and calling functions, function parameters and return values.
- Declaring and assigning values to variables of different data types like int, float, and double.
- Using basic input/output functions like cout and cin to display output and get user input.
- The scope of variables and how they work within and outside of functions.
The document discusses various topics in Objective-C including variables, data types, categories, protocols, and composite objects. It provides code examples to illustrate initializing objects, variable scope, enumerated data types, typedefs, data type conversion, categories, class extensions, protocols, delegates, and composite objects in Objective-C and compares some of these concepts to Java.
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
The document discusses Java syntax and concepts including:
1. It introduces primitive data types in Java like int, float, boolean and String.
2. It covers variables, operators, and expressions - how they are used to store and manipulate data in Java.
3. It explains console input and output using Scanner and System.out methods for reading user input and printing output.
4. It provides examples of using conditional statements like if and if-else to control program flow based on conditions.
The document discusses operators and casts in C#. It covers various types of operators like arithmetic, comparison, conditional, etc. It explains implicit and explicit type conversions between primitive and reference types. It also discusses overloading operators for custom types and implementing user-defined casts.
Presented By:
N.V.Raja Sekhar Reddy
www.technolamp.co.in
Want more interesting...
Watch and Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
This document provides an overview and agenda for a Java introduction presentation. It covers topics like the types of programming languages, what Java is and why it was developed, how to set up your environment to write Java programs, the basics of the Java language including variables, types, operators, methods, conditionals, loops, arrays, and object-oriented programming concepts. It also discusses how to write a first simple Java program and solve problems using Java.
Templates in C++ allow functions and classes to operate on different data types in a generic way. Function templates define generic functions that can work on different types, while class templates define generic classes. Templates promote code reuse by defining functions and classes independently of specific types. Function templates and class templates can be overloaded and classes can inherit from class templates.
C# is a component-oriented programming language that builds on the .NET framework. It has a familiar C-like syntax that is easy for developers familiar with C, C++, Java, and Visual Basic to adopt. C# is fully object-oriented and optimized for building .NET applications. Everything in C# belongs to a class, with basic data types including integers, floats, booleans, characters, and strings. C# supports common programming constructs like variables, conditional statements, loops, methods, and classes. C# can be easily combined with ASP.NET for building web applications in a powerful, fast, and high-level way.
This document discusses evaluating user experience. It explains that evaluation is important to understand the value of a product from the user's perspective, identify design issues, and better understand the user experience. Evaluation can happen at different stages of development with different types of participants and study methods. It is important to evaluate both before and during usage to understand snapshots of interaction as well as long-term experience. The document covers when, where, who, what, and how to evaluate user experience.
This document discusses user experience evaluation. It explains that evaluation is needed to understand user needs, identify design issues, and improve the user experience. Different evaluation methods are appropriate at different stages of development, including early concept testing, low-fidelity prototyping, and high-fidelity testing. A variety of methods can provide both qualitative and quantitative data, including usability testing, surveys, interviews, and analytical metrics. Properly selecting evaluation techniques and planning the procedure is important to obtain high-quality feedback for optimizing the user experience.
This document discusses Edward De Bono's 6 Thinking Hats method for group discussions. It provides examples of how each "hat" or perspective could be applied when considering opening a new restaurant: the White Hat focuses on objective facts, the Yellow Hat on optimism, the Green Hat on creative ideas, the Black Hat on criticism, the Red Hat on emotions, and the Blue Hat on process and agenda. The document encourages using a maximum of 2 hats per person during a discussion and avoiding overuse of the Black Hat. It also provides guidance on using this technique for a workshop on evaluating concepts.
This document discusses program development and outlines a lesson on object-oriented programming concepts. It covers the four basic activities of program development: establishing requirements, creating a design, implementing code, and testing. It then outlines topics to be covered in the lesson including method design, creating objects, loop statements, classes and objects, and more. Examples are provided of creating classes to represent dice and students. The use of for loops is demonstrated through examples printing weekdays, multiples of a number, and a triangle of asterisks.
This document provides an outline and examples for creating objects in Java. It discusses creating object instances from classes, using constructors to initialize objects, and defining instance variables and methods. The document uses a bank account example to demonstrate how to:
- Define an Account class with fields for account number, balance, and name
- Create Account objects by calling the constructor
- Add methods like deposit(), withdraw(), and transfer() that update the object's balance field
- Create multiple Account objects to represent different bank accounts
- Use input methods and output statements when calling object methods
1. The document discusses the anatomy of methods and classes in Java. It explains that a Java application consists of more than one class, with the starting class containing the main method. Other classes are used to encapsulate data and functionality.
2. It describes what a method declaration is and how method control flow works. When a method is invoked, the flow jumps to the method code and returns after completion. Methods can return values.
3. The document also covers instantiating classes to create objects. Instance methods require object creation using the new operator before being called. Instance variables store data in objects and are available throughout the class.
This document discusses comparing data types in Java, including:
1) Floating point values should not be compared directly for equality due to precision issues, instead compare that the absolute difference is less than a small tolerance value.
2) Strings and characters can be compared lexicographically based on their ordering in Unicode character sets, or using the equals() and compareTo() methods.
3) Shorter strings come before longer strings with the same prefix, and uppercase letters come before lowercase letters.
This document discusses responsive web design. It defines responsive design as designs that can adjust to different screen sizes and devices. It distinguishes between fixed, fluid, and responsive layout types. Fixed layouts have a set pixel width and do not adjust to different screens. Fluid layouts use percentages for widths to adjust to the browser window size. Responsive designs use both fixed and fluid elements along with media queries to dynamically adjust the layout. The document provides guidelines for implementing each type of layout and discusses using grids to create flexible and adaptive designs.
The document provides an overview of Lesson 3 which will address random and math classes, conditional statements including if, if-else, and switch statements. It discusses variables, data types, operators, and methods from classes like Random, Math, and Scanner. The document also covers formatting output, indentation, block statements, nested if statements, and the logic of if and if-else statements.
This document provides an overview of HTML (Hypertext Markup Language) including basic concepts, elements, and structure. It discusses HTML as a markup language interpreted by web browsers to define the structure of web pages and present content. The key elements covered include text formatting, lists, hyperlinks, images, tables, and forms. It also discusses HTML5 additions and differences between HTML and XHTML.
The document discusses building interactive systems using Xcode and Swift. It introduces key programming concepts like object-oriented programming, variables and types, functions, conditionals, and Xcode components like the interface builder, simulator, and assistant editor. It explains how to create a basic Xcode project with labels, connect the labels to code using outlets, and set label text in the viewDidLoad function. The document provides an overview of building blocks for programming interactive apps in Xcode.
Trust from a Human Computer Interaction perspective Sónia
Persuasion, Emotion and Trust (PET) is a design methodology that enables design more technologically engaging products. PET uses three main design values,
Persuasion – Triggers actions;
Emotion - Generate an emotional response; and
Trust – Leveraging credibility and cooperation.
This design methodology main aim is to incentives people to become more engaged and connected with a certain product or ecosystems.
Our main aim is to stress the role of trust on persuasive design.
In general, we will focus on the following aspects:
1) First we will start by creating a clear understanding on the challenges of transferring Human Computer Trust (HCT) values to influence user engagement and fostering trust-enabling interactions.
2) Then, in the second part we will learn to analyze interaction design sequences from digital products that changes human trust behaviors. As well as explore different methodologies for testing.
3) We will end by presenting and reflection on the result achieved.
For more information read my human computer trust blog https://humancomputertrust.wordpress.com
This document provides an introduction and overview of Java programming concepts including:
- Java can be used to create dynamic web applications, native applications, and is not the same as JavaScript.
- The basic structure of a Java program includes object-oriented concepts like classes, objects, inheritance. Development environments like Eclipse help facilitate Java development.
- Variables represent object state and methods represent object behavior. Classes are templates that define common attributes and behaviors of objects.
- Eclipse is an integrated development environment used for Java development which allows editing, compiling and running Java programs.
The goal of the course is to bring particular computer and programming skills to the level required by the studies. To create opportunities for the development of Java-based applications. To introduce programming basis and object-oriented principles using Java programming language.
This course is about evaluating the User Experience. It main goal is to highlight the experiential, affective, meaningful and valuable aspects of human-computer interaction as a complement to pragmatic attributes such as utility, ease of use and efficiency of the system.
This document discusses key concepts from the Diffusion of Innovation theory, including:
- There are different types of adopters (innovators, early adopters, early majority, late majority, laggards) who adopt innovations at different rates.
- Factors like relative advantage, compatibility, complexity, trialability, and observability influence how quickly an innovation is adopted.
- The innovation adoption process involves knowledge, persuasion, decision, implementation, and confirmation stages.
- Communication channels, time, and the social system all impact the spread of new ideas through a population.
This document presents an overview of a lesson on the technology acceptance model (TAM). The objective is to introduce key concepts of TAM, have student groups design concept maps of TAM, and summarize. TAM is presented as attempting to understand technology acceptance in organizations. It includes four versions and draws from other models like the theory of reasoned action. The core idea is that two key factors, perceived usefulness and perceived ease of use, influence users' decisions about adopting technologies.
This document provides an overview of the Human Centered Computing course IFI7172. The course aims to understand how computer technologies impact and are impacted by society. It takes a multidisciplinary approach and focuses on human, social, and cultural aspects of technology. The course covers topics like sociotechnical systems, technology acceptance, and innovation diffusion through lectures, activities, discussions, and case studies. Students are assessed based on participation, readings, discussions, case studies, and a final presentation. The goal is to study how technologies affect humans and society using human-centered methodologies.
4. Everything is an object
• In java as you design your applications
– You place your code inside of Class definitions
• Inside you add your Function
– Known as method
public class HelloWorld{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
4
Executable code
Function
Class definition
5. Everything is an object
public class HelloWorld{
public static void main(String[] args) {
sayHello();
}
public static void sayHello() {
String w = new String("hello");
System.out.println( w );
}
}
5
Executable code
Function
Class definition
Executable code
Instance variable
Class instance
6. Object oriented Language
State
Variables (fields)
behaviours
functions (methods)
that allow to change the state
Function to change the gear (bicycle has 3 gears)
@ Sonia Sousa 62015
System.out.println( w );
String w = "hello";
7. What Is a Class?
• A Class represent 1 object (Myfirstprogram)
Instance
Of
class of objects
@ Sonia Sousa 72015
object
public class HelloWorld{
public static void main(String[] args) {
sayHello();
}
public static void sayHello() {
String w = new String("hello");
System.out.println( w );
}
}
8. What Is a Inheritance?
• Class of objects that inherit characteristics
of another object
inherit
characteristics
class of objects known as
Superclass of objects known
as specific characteristic
public class HelloWorld {
public static void main(String[] args) {
sayHello();
}
public static void sayHello() {
String w = "hello";
System.out.println( w );
}
10. Variables
• A variable is a name for a location in memory that holds a value
• Primitive data
– Numerical
• Integers: byte, short, int,
long
• Floating point decimals:
float, double
– Characters:
• Not complete strings: char
– Boolean values:
• Boolean: True or false
• Complex object
– Declare as instance of a
data class
• String
• Date
• Everything else
10
11. Declare variables
• You need to specify
– 3 parts:
• Data type
• Variable name
– Lower case or Underscore _
– not numerical
• Initial value
– optional
11
Type
Byte, short, int, long
Float, double
data type variable name
int total;
12. Variable Initialization
12
int sum = 0;
int base = 32, max = 149;
data type variable name Initiate variable
@ Sonia Sousa2015
Multiple variables can be created in one declaration
int count, temp, result;
13. Complex object
• Declaration
– Instance of a class
– Primitives we declare 3 parts
• Data type
• Variable name
• Initial value: build from class constructor
13
data type variable name Initiate variable from constructor
String w = new String(c);
14. Declare variables
• Inside the function
– Finish execute -> the variable goes away
• Outside the function
14
public static void sayHello() {
String w = "hello”;
System.out.println( w );
}
public static void sayHello() {
String w = "hello”;
}
System.out.println( w );
15. Characters
• A char variable stores a single character
• Character literals are delimited by single quotes:
'a' 'X' '7' '$' ',' 'n'
• Example declarations:
char topGrade = 'A';
char terminator = ';', separator = ' ';
• Note the difference between
– a primitive character variable, which holds only one
character, and
– a String object, which can hold multiple characters
2015 @ Sonia Sousa 15
16. Output character
public class Character {
public static void main(String[] args) {
char[] c = {'h','e','l','l','o'};
char c1 = 'h';
char c2 = ‘e';
char c3 = ‘l';
char c4 = ‘l';
char c5 = ‘o’;
System.out.println( c );
}
}
16
17. Boolean
• A boolean value represents a true or false
condition
• The reserved words true and false are
the only valid values for a boolean type
boolean done = false;
• A boolean variable can also be used to
represent any two states, such as a light bulb
being on or off
2015 @ Sonia Sousa 17
18. Boolean
public class Charecter {
public static void main(String[] args) {
boolean done1 = true;
boolean done2 = false;
boolean done3 = !done1;
System.out.println( "Did you finish the exercise? " + done1);
System.out.println( "The exercise is done " + done2);
System.out.println( "Is it done now? " + done3);
}
}
18
!Is a logical complement operator;
inverts the value of a boolean
19. Output primitive values
• Any value can be outputted as a string
– Using the concatenation value +
19
public class PianoKeys
{
//----------------------------------------------------
-------------
// Prints the number of keys on a piano.
//----------------------------------------------------
-------------
public static void main (String[] args)
{
int keys = 88;
System.out.println ("A piano has " + keys + "
keys.");
}
}
Output
A piano has 88 keys.
20. Output values
public static void main(String[] args) {
char charVal = 'c';
boolean booleanVal =true;
short shortVal = 127;
int intVal = 32000;
long longVal = 2000000L;
float floatval = 10000000f;
double doubleVal= 112321231221.23d;
System.out.println( "character value is " + charVal);
System.out.println(booleanVal);
System.out.println( "short value is " + shortVal);
System.out.println( "Integer value is " + intVal);
System.out.println( "long value is " + longVal);
System.out.println(doubleVal);
System.out.println(floatval + " float value " );
System.out.println( "double value is " + doubleVal);
} 20
Output
character value is c
true
short value is 127
Integer value is 32000
long value is 2000000
1.1232123122123E11
1.0E7 float value
double value is
1.1232123122123E11
21. Output complex objects
import java.util.Date;
public class Complex{
public static void main(String[] args) {
Date myDate = new Date();
String myString = new String("Hello");
System.out.println(myString);
System.out.println( "My date is " + myDate);
}
}
21
23. Data Conversion
• Sometimes it is convenient to convert data
– from one type to another
• For example,
– to treat an integer as a floating point value
– Or a short to an int
• You can do two type of conversions
– Downwards
• You don’t loose data
– Upwards
• You loose data
– Promotion
23
25. Numeric Primitive Data
• The difference between the numeric
primitive types is their size and the values
they can store:
2015 @ Sonia Sousa 25
Type
byte
short
int
long
float
double
Storage
8 bits
16 bits
32 bits
64 bits
32 bits
64 bits
Min Value
-128
-32,768
-2,147,483,648
< -9 x 1018
- 3.4 x 1038 3.4 x 1038
- 1.7 x 10308 1.7 x 10308
Max Value
127
32,767
2,147,483,647
> 9 x 1018
26. Upward Conversion
• Or Assignment conversion occurs
– when a value is assigned to a variable of
another
• Example:
int dollars = 20;
double money = dollars;
• Only Upward conversions can happen via
assignment
– the value or type of dollars did not change
26
27. Convert primitive data type
• From a data type to another (upward)
27
Type
double
float
long
int
short
byte
public class Converting{
public static void main(String[] args) {
int intVal=120;
double convertIn= intVal;
System.out.println( "Integer value is " + intVal);
System.out.println( "Double value is " +
convertIn);
}
}
Output
Integer value is 120
Double value is 120.0
28. Downwards conversion
• Casting or downwards conversion
– is the most powerful, and dangerous, technique for
conversion
– This conversions happen if you explicitly cast a value
• To cast, you put in parentheses in front of the value being
converted
– Example
double doubleVal= 3.99;
int convertVal= (int)doubleVal;
– You might lose information
28
29. Convert primitive data type
• From a data type to another (downward)
29
Type
double
float
long
int
short
byte
public class Converting{
public static void main(String[] args) {
double doubleVal= 3.99;
int convertVal= (int)doubleVal;
System.out.println( "Double value is " + doubleVal);
System.out.println( "Integer value is " + convertVal);
}
}
Output
Double value is 3.99
Integer value is 3
30. Convert primitive data type
• From a data type to another (downward)
30
Type
Double
byte
public class Converting{
public static void main(String[] args) {
double doubleVal= 128;
byte convertVal= (byte)doubleVal;
System.out.println( "Double value is " + doubleVal);
System.out.println( ”Byte value is " + convertVal);
}
}
Output
Double value is 128.0
Byte value is -128
31. Promotion
• Promotion happens automatically
– When you use operators in expressions convert
their operands
– Example:
int count = 12;
double sum = 490.27;
result = sum / count;
• The value of count is converted to a floating
point value
– to perform the division calculation
31
33. Simple calculation applications
• Type of operators
– Simple assignment
• Assignment values
– Complex assignment
• Combine assignment and
math in a single
expression
– Equality and relation
• Compare values to each
other
– Mathematical
• Execute common
mathematical processes
– Conditional operators
• Define complex
conditional processes
33
int count = 12;
double sum = 490.27;
result = sum / count;
data type variable name Simple assign
Complex assign
34. Math operators
• An expression is a combination of one or
more operators and operands
• Arithmetic or math expressions compute
numeric results:
34
Addition
Subtraction
Multiplication
Division
Remainder
+
-
*
/
%
• If either or both operands are floating point values,
then the result is a floating point value
35. Promotion
• Promotion happens automatically
– When you use operators in expressions convert
their operands
– Example:
int count = 12;
double sum = 490.27;
result = sum / count;
• The value of count is converted to a floating
point value
– to perform the division calculation
35
36. Division and Remainder
• If both operands to the division operator (/) are
integers
– the result is an integer (the fractional part is discarded)
14 / 3 equals 4
8 / 12 equals 0
• The remainder operator (%) returns the remainder after
dividing the first operand by the second
14 % 3 equals 2
8 % 12 equals 8
36
37. Quick Check
What are the results of the following expressions?
12 / 2
12.0 / 2.0
10 / 4
10 / 4.0
4 / 10
4.0 / 10
12 % 3
10 % 3
3 % 10
37
38. Quick Check
What are the results of the following expressions?
public static void main(String[] args) {
int valueDiv = 12;
double result1 =valueDiv/2;
double result2 = 12.0 / 2.0;
…
double result7 = 12 % 3;
double result8 = 10 % 3;
double result9 = 3 % 10;
System.out.println(result1);
System.out.println(result2);
…
System.out.println(result7);
System.out.println(result8);
System.out.println(result9);
System.out.println("The end :)");
}
38
Output
= 6
= 6.0
= 2
= 2.5
= 0
= 0.4
= 0
= 1
= 0
39. Operator Precedence
• Operators can be combined into larger expressions
result = total + count / max - offset;
• Operators have precedence
– determines the order in which they are evaluated
• First:
– Multiplication, division, and remainder
• Second:
– addition, subtraction, and string concatenation
• Same precedence
– left to right,
• Exception
– Using parentheses
• force the evaluation order
39
40. Quick Check
40
a + b + c + d + e a + b * c - d / e
a / (b + c) - d % e
a / (b * (c + (d - e)))
In what order are the operators evaluated in the
following expressions?
Values a =1; b = 12; c = 10; d =4; e = 3;
41. Quick Check
a + b + c + d + e a + b * c - d / e
a / (b + c) - d % e
a / (b * (c + (d - e)))
1 432 3 241
2 341
4 123
In what order are the operators evaluated in the
following expressions?
41
42. Quick Check
What are the results of the following expressions?
int a =1;
int b = 12;
int c = 10;
int d =4;
int e = 3;
double result1 =a+b+c+d+e;
double result2 =a + b * c - d / e;
double result3 =a / (b + c) - d % e;
double result4 = a / (b * (c + (d - e)));
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
System.out.println(result4);
System.out.println("The end :)"); }
42
Output
= 30.0
= 120.0
= -1.0
0.0The end :)
43. Assignment Revisited
• The assignment operator has a lower
precedence than the arithmetic operators
First the expression on the right hand
side of the = operator is evaluated
Then the result is stored in the
variable on the left hand side
answer = sum / 4 + MAX * lowest;
14 3 2
43
44. Assignment Revisited
• The right and left hand sides of an assignment
statement can contain the same variable
First, one is added to the
original value of count
Then the result is stored back into count
(overwriting the original value)
count = count + 1;
44
45. Increment and Decrement
• The increment (++) operator
– The statement
count++;
count = count + 1;
• The decrement (--) operator
count--;
count = count - 1;
45
46. Increment and Decrement
• Postfix syntax:
– Evaluated value first then make the mathematical operation
count++
• Prefix syntax:
– mathematical operation first then evaluated value
++count
• ! When used as part of a larger expression !
– the two forms can have different effects
• The subtleties, of increment and decrement operators
– should be used with care
46
47. Assignment Operators
• Often we perform an operation on a variable, and
then store the result back into that variable
• Java provides assignment operators to simplify
that process
• For example, the statement
num += count;
is equivalent to
num = num + count;
47
48. Quick Check
What are the results of the following expressions?
Start with intValue =10
Calculate
++
--
+=5
-=5
/=5
++ intValue
-- intValue
48
49. Assignment Operators
• The right hand side of an assignment
operator can be a complex expression
• The entire right-hand expression is evaluated
first, then the result is combined with the
original variable
• Therefore
result /= (total-MIN) % num;
is equivalent to
result = result / ((total-MIN) % num);
49
50. Assignment Operators
• The behavior of some assignment operators
depends on the types of the operands
• If the operands to the += operator are strings,
the assignment operator performs string
concatenation
• The behavior of an assignment operator (+=)
is always consistent with the behavior of the
corresponding operator (+)
50
51. Assignment Operators
• There are many assignment operators in
Java, including the following:
Operator
+=
-=
*=
/=
%=
Example
x += y
x -= y
x *= y
x /= y
x %= y
Equivalent To
x = x + y
x = x - y
x = x * y
x = x / y
x = x % y
51
52. Quick Check
What are the results of the following expressions?
int intValue =10;
int newValue1 =++ intValue;
int newValue2 =-- intValue;
System.out.println(intValue ++);
System.out.println(intValue --);
System.out.println(intValue +=5);
System.out.println(intValue -=5);
System.out.println(intValue /=5);
System.out.println(newValue1);
System.out.println(newValue2);
System.out.println("The end :)"); }
52
Output
= 10
= 11
= 15
= 10
= 2
= 11
= 10
The end :)
53. Comparative values
53
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Conditional Operators
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for
if-then-else statement)
Be careful
When comparing strings
This will not work
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
55. Interactive Programs
• Programs generally need input on which to operate
• Scanner class
– provides the methods for
• reading input values of various types
• A Scanner object
– can be set up to read input from various sources,
• including the user typing values on the keyboard
• To read Keyboard input
– Use the System.in object
55
56. Reading Input
• Create a Scanner object that reads from the
keyboard:
Scanner scan = new Scanner (System.in);
• The new operator creates the Scanner
object
• Once created, the Scanner object can be
used to invoke various input methods, such
as:
answer = scan.nextLine();
56
57. Reading Input
• The Scanner class is part of the
– java.util class library
– Import class java.util library
• This class library must be imported into a program
to be used
• The nextLine method
– reads all of the input until the end of the line is
found
– See Echo.java
57
58. //********************************************************************
// Echo.java Author: Lewis/Loftus
//
// Demonstrates the use of the nextLine method of the Scanner class
// to read a string from the user.
//********************************************************************
import java.util.Scanner;
public class Echo
{
//-----------------------------------------------------------------
// Reads a character string from the user and prints it.
//-----------------------------------------------------------------
public static void main (String[] args)
{
String message;
Scanner scan = new Scanner (System.in);
System.out.println ("Enter a line of text:");
message = scan.nextLine();
System.out.println ("You entered: "" + message + """);
}
}
58
59. //********************************************************************
// Echo.java Author: Lewis/Loftus
//
// Demonstrates the use of the nextLine method of the Scanner class
// to read a string from the user.
//********************************************************************
import java.util.Scanner;
public class Echo
{
//-----------------------------------------------------------------
// Reads a character string from the user and prints it.
//-----------------------------------------------------------------
public static void main (String[] args)
{
String message;
Scanner scan = new Scanner (System.in);
System.out.println ("Enter a line of text:");
message = scan.nextLine();
System.out.println ("You entered: "" + message + """);
}
}
Sample Run
Enter a line of text:
You want fries with that?
You entered: "You want fries with that?"
59
60. Input Tokens
• Unless specified otherwise,
– white space is used to separate the elements
• (called tokens) of the input
• White space includes
– space characters, tabs, new line characters
• The next method of the Scanner class
– reads the next input token and returns it as a string
• Methods such as
– nextInt and nextDouble read data of particular types
• See GasMileage.java
60
61. //********************************************************************
// GasMileage.java Author: Lewis/Loftus
//
// Demonstrates the use of the Scanner class to read numeric data.
//********************************************************************
import java.util.Scanner;
public class GasMileage
{
//-----------------------------------------------------------------
// Calculates fuel efficiency based on values entered by the
// user.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int miles;
double gallons, mpg;
Scanner scan = new Scanner (System.in);
continue
61
62. continue
System.out.print ("Enter the number of miles: ");
miles = scan.nextInt();
System.out.print ("Enter the gallons of fuel used: ");
gallons = scan.nextDouble();
mpg = miles / gallons;
System.out.println ("Miles Per Gallon: " + mpg);
}
}
62
63. continue
System.out.print ("Enter the number of miles: ");
miles = scan.nextInt();
System.out.print ("Enter the gallons of fuel used: ");
gallons = scan.nextDouble();
mpg = miles / gallons;
System.out.println ("Miles Per Gallon: " + mpg);
}
}
Sample Run
Enter the number of miles: 328
Enter the gallons of fuel used: 11.2
Miles Per Gallon: 29.28571428571429
63
65. Creating Objects
• Primitive data type vs objects
– Objects can be used to represent real-world
entities (see the top slides)
• For instance, an object
– represent a particular employee in a company
» Each employee object
• handles specific information
• related to that employee
65
66. Creating Objects
• An object has:
– state (attributes)
• descriptive characteristics
– behaviors
• what it can do (or what can be done to it)
66
BankAcount
AccounNumber
Name
Balance
Deposit
Withrow
Transfer
State
behaviours
67. Creating Objects
• An object has:
– state (attributes) - bankAcount
– AccountNumber
– Name
– Balance
• descriptive characteristics
– behaviors (what he can do)
– Desposit
– Withrow
– Tranfer
• the ability to make deposits and withdrawals
• Note that the behavior of an object might change its
state 67
BankAcount
AccounNumber
Name
Balance
Deposit
Withrow
Transfer
68. Classes
• An object is defined by a class
– A class is the blueprint of an object
• The class uses methods
– to define the behaviors of the object
• The class contains the main method of a Java
program
– represents the entire program
• A class represents a concept
• An object represents the embodiment of that concept
• Multiple objects can be created from the same class
68
69. Class = Blueprint
• One blueprint to create several similar, but
different, houses:
69
70. Objects and Classes
Bank
Account
A class
(the concept)
John’s Bank Account
Balance: $5,257
An object
(the realization)
Bill’s Bank Account
Balance: $1,245,069
Mary’s Bank Account
Balance: $16,833
Multiple objects
from the same class
70
71. Creating Objects
• A variable holds either a primitive value or a
reference to an object
• A class name can be used as a type to
declare an object reference variable
String title;
• No object is created with this declaration
• An object reference variable holds the
address of an object
• The object itself must be created separately
71
72. Creating Objects
• Generally, we use the new operator to
create an object
• Creating an object is called instantiation
• An object is an instance of a particular
class
72
title = new String ("Java Software Solutions");
This calls the String constructor, which is
a special method that sets up the object
73. Invoking Methods
• We've seen that once an object has been
instantiated, we can use the dot operator
to invoke its methods
numChars = title.length()
• A method may return a value, which can
be used in an assignment or expression
• A method invocation can be thought of as
asking an object to perform a service
73
74. References
• Note that a primitive variable contains the
value itself, but an object variable contains
the address of the object
• An object reference can be thought of as a
pointer to the location of the object
• Rather than dealing with arbitrary addresses,
we often depict a reference graphically
74
"Steve Jobs"name1
num1 38
75. Assignment Revisited
• The act of assignment takes a copy of a
value and stores it in a variable
• For primitive types:
75
num1 38
num2 96
Before:
num2 = num1;
num1 38
num2 38
After:
77. Aliases
• Two or more references that refer to the
same object are called aliases of each other
• That creates an interesting situation: one
object can be accessed using multiple
reference variables
• Aliases can be useful, but should be
managed carefully
• Changing an object through one reference
changes it for all of its aliases, because there
is really only one object
77
78. Garbage Collection
• When an object no longer has any valid
references to it, it can no longer be accessed
by the program
• The object is useless, and therefore is called
garbage
• Java performs automatic garbage collection
periodically, returning an object's memory to
the system for future use
• In other languages, the programmer is
responsible for performing garbage collection
78
79. Outline
Review Object-oriented concepts
Variables and Types
Variables and Assignment
Primitive Data Types
Data Conversion
Expressions
Interactive Programs
Creating Objects
String class
79@ Sonia Sousa2015
80. The String Class
• Because strings are so common, we don't
have to use the new operator to create a
String object
title = "Java Software Solutions";
• This is special syntax that works only for
strings
• Each string literal (enclosed in double quotes)
represents a String object
80
81. String Methods
• Once a String object has been created,
neither its value nor its length can be
changed
• Therefore we say that an object of the
String class is immutable
• However, several methods of the String
class return new String objects that are
modified versions of the original
81
82. String Indexes
• It is occasionally helpful to refer to a
particular character within a string
• This can be done by specifying the
character's numeric index
• The indexes begin at zero in each string
• In the string "Hello", the character 'H' is
at index 0 and the 'o' is at index 4
• See StringMutation.java
82
83. //********************************************************************
// StringMutation.java Author: Lewis/Loftus
//
// Demonstrates the use of the String class and its methods.
//********************************************************************
public class StringMutation
{
//-----------------------------------------------------------------
// Prints a string and various mutations of it.
//-----------------------------------------------------------------
public static void main (String[] args)
{
String phrase = "Change is inevitable";
String mutation1, mutation2, mutation3, mutation4;
System.out.println ("Original string: "" + phrase + """);
System.out.println ("Length of string: " + phrase.length());
mutation1 = phrase.concat (", except from vending machines.");
mutation2 = mutation1.toUpperCase();
mutation3 = mutation2.replace ('E', 'X');
mutation4 = mutation3.substring (3, 30);
continued
83
85. continued
// Print each mutated string
System.out.println ("Mutation #1: " + mutation1);
System.out.println ("Mutation #2: " + mutation2);
System.out.println ("Mutation #3: " + mutation3);
System.out.println ("Mutation #4: " + mutation4);
System.out.println ("Mutated length: " + mutation4.length());
}
}
Output
Original string: "Change is inevitable"
Length of string: 20
Mutation #1: Change is inevitable, except from vending machines.
Mutation #2: CHANGE IS INEVITABLE, EXCEPT FROM VENDING MACHINES.
Mutation #3: CHANGX IS INXVITABLX, XXCXPT FROM VXNDING MACHINXS.
Mutation #4: NGX IS INXVITABLX, XXCXPT F
Mutated length: 27
85
86. Quick Check
What output is produced by the following?
String str = "Space, the final frontier.";
System.out.println (str.length());
System.out.println (str.substring(7));
System.out.println (str.toUpperCase());
System.out.println (str.length());
86
87. Quick Check
What output is produced by the following?
String str = "Space, the final frontier.";
System.out.println (str.length());
System.out.println (str.substring(7));
System.out.println (str.toUpperCase());
System.out.println (str.length());
26
the final frontier.
SPACE, THE FINAL FRONTIER.
26
87
88. Comparative values
88
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Conditional Operators
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for
if-then-else statement)
Be careful
When comparing strings
This will not work
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
89. Example
String sting1 = new String("hello");
String sting2 = new String("hello");
int int1 = 1, int2 = 1;
if (int1 == int2){
System.out.println("true");
}
else{ System.out.println("not true”); }
if (sting1.equals(sting2)){
System.out.println("true");
}
else{ System.out.println("not true"); }
89