This document provides an overview of data types, variables, and constants in Java. It discusses the primitive data types like int, float, boolean and char. It describes how to declare variables, assign values, and the rules for compatible data types. The document also covers strings, literals, escape sequences and constants. It explains implicit and explicit type casting, operator precedence and mixed-type arithmetic expressions. Finally, it provides an introduction to arrays, including how to declare, assign values to, and access array elements.
This document provides an overview of Java programming basics, including application structure, data types, variables, expressions, operators, and comments. Key points include: all Java programs must contain at least one class; variables are used to store and name data; the basic data types are byte, short, int, long, float, double, char, and boolean; expressions use operators to manipulate data; and comments are used to explain code to others.
The document discusses key concepts in C# programming including data types, operators, control flow statements, methods, classes, arrays, and more. It provides definitions and examples of common terms like namespaces, classes, methods, operators, loops, and exceptions. Type conversion methods in C# are also summarized in a table listing common conversion functions.
The document discusses variables, constants, data types, calculations, and formatting values in Visual Basic. It defines variables and constants, lists common data types, and explains how to perform calculations using variables and constants of different data types. It also covers declaring variables, naming conventions, implicit and explicit conversions, and formatting values for display.
Lexical analyzer, tokenizer, scanner, or lexer is a function that is invoked by the syntax analyzer. This function returns the nxt lexicon or word in the source file.
C++ provides several fundamental and derived data types to store and represent different types of data. Fundamental data types include integers, characters, floats, doubles, and void. Integers can be further classified as short, int, long and modified with signed or unsigned. Characters can also be signed or unsigned. Floats and doubles represent real numbers with different levels of precision. Derived data types include arrays to store multiple values of the same type, structures to group different data types, unions to access memory in different types, enumerations to define named integer constants, classes to define user-defined types with methods and pointers to reference memory locations.
This document discusses key concepts in Java programming including classes, methods, parameters, and invoking methods. It explains that a program consists of classes, a class contains methods, and a method contains statements. Methods can take parameters, which are initialized when the method is called and allow passing in values. Parameters act similarly to local variables but are declared in the method signature.
Generic classes and interfaces allow type parameters that act as placeholders for type arguments. This allows a single class implementation to work for multiple types, catching errors at compile time. Wildcard types like ? extends Number and ? super Integer allow more flexible usage of generics by supporting subtyping.
This document provides an overview of key concepts related to writing classes in Java, including:
- Defining classes to create custom objects with state (data) and behaviors (methods)
- Encapsulation and using access modifiers like public and private to control visibility
- Declaring methods, parameters, and return types
- Overloading methods by having multiple methods with the same name but different parameters
- Constructors for initializing new objects
This document provides an overview of Java programming basics, including application structure, data types, variables, expressions, operators, and comments. Key points include: all Java programs must contain at least one class; variables are used to store and name data; the basic data types are byte, short, int, long, float, double, char, and boolean; expressions use operators to manipulate data; and comments are used to explain code to others.
The document discusses key concepts in C# programming including data types, operators, control flow statements, methods, classes, arrays, and more. It provides definitions and examples of common terms like namespaces, classes, methods, operators, loops, and exceptions. Type conversion methods in C# are also summarized in a table listing common conversion functions.
The document discusses variables, constants, data types, calculations, and formatting values in Visual Basic. It defines variables and constants, lists common data types, and explains how to perform calculations using variables and constants of different data types. It also covers declaring variables, naming conventions, implicit and explicit conversions, and formatting values for display.
Lexical analyzer, tokenizer, scanner, or lexer is a function that is invoked by the syntax analyzer. This function returns the nxt lexicon or word in the source file.
C++ provides several fundamental and derived data types to store and represent different types of data. Fundamental data types include integers, characters, floats, doubles, and void. Integers can be further classified as short, int, long and modified with signed or unsigned. Characters can also be signed or unsigned. Floats and doubles represent real numbers with different levels of precision. Derived data types include arrays to store multiple values of the same type, structures to group different data types, unions to access memory in different types, enumerations to define named integer constants, classes to define user-defined types with methods and pointers to reference memory locations.
This document discusses key concepts in Java programming including classes, methods, parameters, and invoking methods. It explains that a program consists of classes, a class contains methods, and a method contains statements. Methods can take parameters, which are initialized when the method is called and allow passing in values. Parameters act similarly to local variables but are declared in the method signature.
Generic classes and interfaces allow type parameters that act as placeholders for type arguments. This allows a single class implementation to work for multiple types, catching errors at compile time. Wildcard types like ? extends Number and ? super Integer allow more flexible usage of generics by supporting subtyping.
This document provides an overview of key concepts related to writing classes in Java, including:
- Defining classes to create custom objects with state (data) and behaviors (methods)
- Encapsulation and using access modifiers like public and private to control visibility
- Declaring methods, parameters, and return types
- Overloading methods by having multiple methods with the same name but different parameters
- Constructors for initializing new objects
The document discusses the eight primitive data types in Java - boolean, char, byte, short, int, long, float, and double. It explains what each type is used for, their possible value ranges, and when to use each type. Key points covered include int being the preferred integer type, double the preferred real number type, and the importance of declaring variables before use and giving them initial values.
C is a general-purpose programming language developed in the 1970s at Bell Labs. It was designed and written by Dennis Ritchie as a replacement for B programming language. C is a procedural language but features object-oriented programming. Major parts of popular operating systems like Windows and Linux are written in C. It is also commonly used to program devices like microwaves, washing machines, and digital cameras. Key aspects of C include variables, constants, keywords, data types, operators, and control flow statements.
The document provides an overview of key Python concepts including variables, data types, operators, formatting numbers, and taking user input. It explains that variables store values in memory and have naming rules. The main data types are int, float, and string, and numbers can be formatted using specifiers like .2f. Operators allow mathematical operations and comparisons, while input() reads user keyboard input as a string.
The document provides an overview of Strings and StringBuilders in Java. It discusses Strings as immutable objects and how StringBuilders can be more efficient for modifying strings. It also covers common String and StringBuilder methods, when to use each, and exceptions in Java using try/catch blocks.
The document discusses greedy algorithms and matroids. It provides examples of problems that can be solved using greedy approaches, including sorting an array, the coin change problem, and activity selection. It defines key aspects of greedy algorithms like the greedy choice property and optimal substructure. Huffman coding is presented as an application that constructs optimal prefix codes. Finally, it introduces matroids as an abstract structure related to problems solvable by greedy methods.
This document discusses data types and type conversion in Java. It describes primitive and non-primitive data types, including their storage sizes and value ranges. It explains widening and narrowing type conversion, and how coercion can occur in expressions. Relational and boolean expressions are also summarized, including logical operators that can combine boolean expressions.
1) Variables are used in programming to store and manipulate data values. They must be declared with a name and data type.
2) Variables can be initialized during or after declaration by assigning them a value. User input can be obtained and assigned to variables using functions like Console.ReadLine().
3) Constants are variables whose values cannot change once declared, while the scope of a variable determines where it can be accessed within a program.
This document provides an overview of JavaScript, including:
- JavaScript is a lightweight, interpreted programming language that is complementary to and integrated with HTML and Java.
- JavaScript code is placed within <script> tags and can go in the <head> or <body> section of an HTML page.
- JavaScript supports various data types, variables, operators, and comments. It is case sensitive.
- Key JavaScript concepts covered include data types, variables, scope, reserved words, arithmetic operators, comparison operators, logical operators, and bitwise operators.
This document provides an overview of JavaScript including:
- JavaScript is a lightweight, interpreted programming language designed for creating network-centric applications. It is complementary to and integrated with HTML.
- JavaScript code is placed within <script> tags in an HTML document and can be placed in the <head> or <body> sections.
- JavaScript is case sensitive, ignores whitespace, and semicolons are optional. It supports various data types, variables, operators, control structures like if/else statements, loops and functions.
- Functions are defined using the function keyword and parameters can be passed to functions. Exceptions can be handled using try/catch blocks.
- Common JavaScript statements include if/else, switch, while,
Lexical Analysis, Tokens, Patterns, Lexemes, Example pattern, Stages of a Lexical Analyzer, Regular expressions to the lexical analysis, Implementation of Lexical Analyzer, Lexical analyzer: use as generator.
Data types in java | What is Datatypes in Java | Learning with RD | Created b...rahuldaredia21
ย
In this presentation , i will present a what are the datatypes in java? in brief and use easy world to understand easily about datatype but more important think in this presentation is diagram because any types of topic like In Byte understand in theory but easily understand in only diagrams and all about details of byte and also in case all datatypes in java give understand in diagrams then also watch video on youtube to understand more about datatypes link in this description .
https://youtu.be/pOBS9wBXVjY
click on link and watch this video understand datatypes easily.
THANK YOU
This slide begins your formal investigation of the C# programming language by presenting a number
of bite-sized, stand-alone topics you must be comfortable with as you explore the .NET Framework.
Type specifiers in Common Lisp allow specifying the type of data. Standard type specifiers include symbols for types like number, string, array. Type specifiers can also be lists to further specify element types, dimensions, etc. New type specifiers can be defined using deftype. Functions like coerce and upgraded-array-element-type handle type conversions.
Every value in Java has a data type. Java supports two kinds of data types: primitive data types and reference data types. Primitive data types represent atomic, indivisible values. Java has eight Numeric data types: byte, short, int,
An operator is a symbol that is used to perform some type of computation on its operands. Java contains a rich set of
operators. Operators are categorized as unary, binary, or ternary based on the number of operands they take. They are categorized as arithmetic, relational, logical, etc. based on the operation they perform on their operands.
long, float, double, char, and boolean. Literals of primitive data types are constants. Reference data types represent
references of objects in memory. Java is a statically typed programming language. That is, it checks the data types of all values at compile time.
Predicates in Common Lisp are functions that test conditions and return true or false. There are different types of predicates including data type predicates to check types, equality predicates like eq and equal to compare objects, and logical operators like and, or, and not. Specific predicates test for individual data types like numberp, listp, symbolp. Subtypep checks if one type is a subtype of another.
The document discusses various data types in VB.net including Boolean, integer, floating point numbers, strings, chars, and dates. It provides examples of declaring and using variables of each data type. It also briefly discusses operators in VB.net, listing arithmetic, comparison, logical/bitwise, and assignment operators and providing examples of each.
This document provides an overview of basic Java programming concepts including:
- Variable types such as primitives (int, double, char etc.), identifiers, and constants.
- Declaring and assigning values to variables including literals, compatible data types, and type casting.
- Operators for arithmetic, assignment, increment/decrement, and precedence. Errors from division by zero or incompatible types are discussed.
- Strings, escape sequences, and concatenation.
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.
This document provides an overview of C# data types, operators, expressions, and statements. It describes primitive data types like integers, floats, booleans, characters, and strings. It also covers literals for representing values of these types. Additionally, it discusses various categories of operators in C# like arithmetic, logical, comparison, assignment, and bitwise operators. Examples are provided to demonstrate how to use each data type and operator.
The document discusses the eight primitive data types in Java - boolean, char, byte, short, int, long, float, and double. It explains what each type is used for, their possible value ranges, and when to use each type. Key points covered include int being the preferred integer type, double the preferred real number type, and the importance of declaring variables before use and giving them initial values.
C is a general-purpose programming language developed in the 1970s at Bell Labs. It was designed and written by Dennis Ritchie as a replacement for B programming language. C is a procedural language but features object-oriented programming. Major parts of popular operating systems like Windows and Linux are written in C. It is also commonly used to program devices like microwaves, washing machines, and digital cameras. Key aspects of C include variables, constants, keywords, data types, operators, and control flow statements.
The document provides an overview of key Python concepts including variables, data types, operators, formatting numbers, and taking user input. It explains that variables store values in memory and have naming rules. The main data types are int, float, and string, and numbers can be formatted using specifiers like .2f. Operators allow mathematical operations and comparisons, while input() reads user keyboard input as a string.
The document provides an overview of Strings and StringBuilders in Java. It discusses Strings as immutable objects and how StringBuilders can be more efficient for modifying strings. It also covers common String and StringBuilder methods, when to use each, and exceptions in Java using try/catch blocks.
The document discusses greedy algorithms and matroids. It provides examples of problems that can be solved using greedy approaches, including sorting an array, the coin change problem, and activity selection. It defines key aspects of greedy algorithms like the greedy choice property and optimal substructure. Huffman coding is presented as an application that constructs optimal prefix codes. Finally, it introduces matroids as an abstract structure related to problems solvable by greedy methods.
This document discusses data types and type conversion in Java. It describes primitive and non-primitive data types, including their storage sizes and value ranges. It explains widening and narrowing type conversion, and how coercion can occur in expressions. Relational and boolean expressions are also summarized, including logical operators that can combine boolean expressions.
1) Variables are used in programming to store and manipulate data values. They must be declared with a name and data type.
2) Variables can be initialized during or after declaration by assigning them a value. User input can be obtained and assigned to variables using functions like Console.ReadLine().
3) Constants are variables whose values cannot change once declared, while the scope of a variable determines where it can be accessed within a program.
This document provides an overview of JavaScript, including:
- JavaScript is a lightweight, interpreted programming language that is complementary to and integrated with HTML and Java.
- JavaScript code is placed within <script> tags and can go in the <head> or <body> section of an HTML page.
- JavaScript supports various data types, variables, operators, and comments. It is case sensitive.
- Key JavaScript concepts covered include data types, variables, scope, reserved words, arithmetic operators, comparison operators, logical operators, and bitwise operators.
This document provides an overview of JavaScript including:
- JavaScript is a lightweight, interpreted programming language designed for creating network-centric applications. It is complementary to and integrated with HTML.
- JavaScript code is placed within <script> tags in an HTML document and can be placed in the <head> or <body> sections.
- JavaScript is case sensitive, ignores whitespace, and semicolons are optional. It supports various data types, variables, operators, control structures like if/else statements, loops and functions.
- Functions are defined using the function keyword and parameters can be passed to functions. Exceptions can be handled using try/catch blocks.
- Common JavaScript statements include if/else, switch, while,
Lexical Analysis, Tokens, Patterns, Lexemes, Example pattern, Stages of a Lexical Analyzer, Regular expressions to the lexical analysis, Implementation of Lexical Analyzer, Lexical analyzer: use as generator.
Data types in java | What is Datatypes in Java | Learning with RD | Created b...rahuldaredia21
ย
In this presentation , i will present a what are the datatypes in java? in brief and use easy world to understand easily about datatype but more important think in this presentation is diagram because any types of topic like In Byte understand in theory but easily understand in only diagrams and all about details of byte and also in case all datatypes in java give understand in diagrams then also watch video on youtube to understand more about datatypes link in this description .
https://youtu.be/pOBS9wBXVjY
click on link and watch this video understand datatypes easily.
THANK YOU
This slide begins your formal investigation of the C# programming language by presenting a number
of bite-sized, stand-alone topics you must be comfortable with as you explore the .NET Framework.
Type specifiers in Common Lisp allow specifying the type of data. Standard type specifiers include symbols for types like number, string, array. Type specifiers can also be lists to further specify element types, dimensions, etc. New type specifiers can be defined using deftype. Functions like coerce and upgraded-array-element-type handle type conversions.
Every value in Java has a data type. Java supports two kinds of data types: primitive data types and reference data types. Primitive data types represent atomic, indivisible values. Java has eight Numeric data types: byte, short, int,
An operator is a symbol that is used to perform some type of computation on its operands. Java contains a rich set of
operators. Operators are categorized as unary, binary, or ternary based on the number of operands they take. They are categorized as arithmetic, relational, logical, etc. based on the operation they perform on their operands.
long, float, double, char, and boolean. Literals of primitive data types are constants. Reference data types represent
references of objects in memory. Java is a statically typed programming language. That is, it checks the data types of all values at compile time.
Predicates in Common Lisp are functions that test conditions and return true or false. There are different types of predicates including data type predicates to check types, equality predicates like eq and equal to compare objects, and logical operators like and, or, and not. Specific predicates test for individual data types like numberp, listp, symbolp. Subtypep checks if one type is a subtype of another.
The document discusses various data types in VB.net including Boolean, integer, floating point numbers, strings, chars, and dates. It provides examples of declaring and using variables of each data type. It also briefly discusses operators in VB.net, listing arithmetic, comparison, logical/bitwise, and assignment operators and providing examples of each.
This document provides an overview of basic Java programming concepts including:
- Variable types such as primitives (int, double, char etc.), identifiers, and constants.
- Declaring and assigning values to variables including literals, compatible data types, and type casting.
- Operators for arithmetic, assignment, increment/decrement, and precedence. Errors from division by zero or incompatible types are discussed.
- Strings, escape sequences, and concatenation.
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.
This document provides an overview of C# data types, operators, expressions, and statements. It describes primitive data types like integers, floats, booleans, characters, and strings. It also covers literals for representing values of these types. Additionally, it discusses various categories of operators in C# like arithmetic, logical, comparison, assignment, and bitwise operators. Examples are provided to demonstrate how to use each data type and operator.
The document discusses key concepts in C# programming including data types, operators, control flow statements, methods, classes, and arrays. It provides examples and descriptions of common language elements like namespaces, classes, methods, variables, operators, loops, and conditional statements. Type conversion methods and how to accept user input and initialize arrays are also summarized.
This document provides an overview of basic concepts in VB.NET, including variables, data types, constants, arrays, operators, flow control statements, and more. It defines variables as storage locations for values, and describes how to declare different data types like numeric, string, boolean, and object. Constants and enums are introduced as fixed values that cannot change. Arrays are defined as lists that allow storing multiple values of the same type. Common operators for arithmetic, comparison, logical operations and assignments are outlined. Decision making statements like If/Then and Select Case as well as looping constructs such as For, For Each, and Do loops are briefly explained.
The document discusses Java's primitive data types including their ranges and literal constants. It covers char, boolean, byte, short, int, long, float, and double data types. It also discusses variables, symbolic constants, and arithmetic operators.
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfComputer Programmer
ย
This document provides an overview of various fundamental concepts in problem solving and computer programming, including data types, operators, control flow statements, arrays, and functions. It describes the different types of data types like integer, floating point, character, boolean, derived, and user-defined types. It also explains various categories of operators like unary, binary, arithmetic, relational, logical, and bitwise operators. Additionally, it covers decision making statements, loops, jumping statements, and escape sequences to control program flow. The document also discusses arrays, pointers, functions, and classes.
The document discusses PHP concepts including:
- PHP is a server-side scripting language used for web development and can be used as an alternative to Microsoft ASP.
- XAMPP is an open-source cross-platform web server bundle that can be used to test PHP scripts locally.
- PHP has different data types including strings, integers, floats, booleans, and arrays.
- PHP includes various operators, conditional statements like if/else, and loops like while and foreach to control program flow.
- Functions allow code reusability and modularity in PHP programs. Built-in and user-defined functions are discussed.
- Arrays are a special variable type that can hold multiple values,
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
ย
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
Variables are used to store information in programs and must have unique names. There are different data types that specify what type of value a variable can store, such as integer, float, double, character, and string. Variables are assigned values using the assignment operator (=), and variable names can be most anything but are typically descriptive. Comments are included in code to help explain it to other programmers.
The document defines various tokens in the C programming language including keywords, identifiers, constants, string literals, operators, data types, and variables. It discusses the basic data types like integers, floating point numbers, and characters. It also covers topics like declarations, global and local variables, type conversions, precedence and order of evaluation, and various operators used in C.
This document provides an overview and introduction to learning Python. It discusses Python programming concepts like data science, machine learning, data visualizations, and web development. It also outlines benefits of Python like job opportunities, large community, being cross-platform, and free. The document then describes the Anaconda distribution tool for scientific computing projects. It introduces the Spyder IDE and its features like source code area, IPython console, and variable/file explorers. Basic Python syntax is covered such as printing, strings, variables, and conditionals. Finally, it discusses lists, loops, and common list methods.
The document discusses pointers in C++. It defines a pointer as a variable that stores the memory address of another variable of the same data type. Pointers allow a program to indirectly access the memory location of another variable. The key points covered include:
- Declaring pointer variables using a data type followed by an asterisk (*)
- Initializing pointers using the address-of (&) operator to store the address of another variable
- Accessing the value at a pointer's address using the dereference (*) operator
- Pointer arithmetic, where pointers can be incremented or decremented to access subsequent memory addresses
- Dynamic memory allocation using new/delete to allocate memory at runtime through a pointer.
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...GANESHBABUVelu
ย
1. The document discusses various concepts in Java programming including data types, variables, operators, and decision making statements. It describes integer, floating point, character, and boolean data types.
2. It also covers variable declaration and scope, constants, arithmetic, relational, and logical operators. Decision making statements like if and switch statements are used for conditional branching in a program.
3. The document provides examples of declaring and assigning values to variables, using different types of operators to perform calculations and comparisons, and the syntax of if and switch statements.
This document provides an overview of C# data types, operators, expressions, statements, and other fundamental concepts. It discusses the different primitive data types in C#, including integer, floating-point, boolean, character, and string types. It also covers literals, variables, operators such as arithmetic, logical, comparison, and assignment, and shows examples of using each concept. The document is intended to teach basic C# syntax and semantics.
Implicit conversions and parameters allow interoperability between types in Scala. Implicit conversions define how one type can be converted to another type, and are governed by rules around marking, scope, ambiguity, and precedence. The compiler tries to insert implicit conversions in three places: to match an expected type, to convert a receiver before a method selection, and to provide missing implicit parameters. Debugging implicits involves explicitly writing out conversions to see where errors occur.
The document provides an overview of key concepts in the Java programming language including:
1. Java language fundamentals including building blocks like identifiers, literals, variables, and wrapper classes. Different types of literals like integral, floating point, character, string and boolean are described.
2. Control structures in Java including selection statements like if-else and switch statements, and iterative statements like while, do-while and for loops. Jump statements like break, continue and return are also covered.
3. Other concepts discussed include arrays, declaring and initializing array variables, and creating arrays using the new operator in Java.
The document provides an outline of topics for a C/C++ tutorial, including a "Hello World" program, data types, variables, operators, conditionals, loops, arrays, strings, functions, pointers, command-line arguments, data structures, and memory allocation. It gives examples and explanations of key concepts in C/C++ programming.
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
Similar to Dr. Rajeshree Khande : Java Basics (20)
This document discusses inheritance, operator overloading, and overriding in F#. It provides an example of defining a Person base class and Student and Teacher subclasses that inherit from Person. It also defines a Complex class that overloads the + and - operators. Finally, it shows how to override a base class method in a subclass by declaring it as abstract and overriding.
The document discusses exception handling in .NET F# including try/with, try/finally, raising exceptions, and common exception types. It provides examples of handling different exceptions using try/with blocks and raising custom exceptions. The key constructs for exception handling in F# are covered including basic syntax, matching exception patterns, and ensuring cleanup code executes.
The document discusses events, creating custom events, and processing event streams in F#. It provides an overview of events, how they allow objects to communicate asynchronously, and how to create and handle events through the Event class. It also covers creating custom events for a Worker class to notify when the name or shift changes, attaching callback functions to event handlers, and an example of implementing an interface using events.
This document discusses classes in F# including:
- Constructors are used to initialize class properties and fields when an object is created. Classes can use implicit or explicit constructor syntax.
- Implicit syntax fuses the constructor with the class body while explicit syntax requires declaring fields and constructors separately.
- Let and do bindings execute initialization code during object construction. Fields created by let bindings can be accessed throughout the class.
- Methods can take parameters, call other methods, and be parameterless. Methods support curried or tuple parameter passing forms.
An abstract class is a base class that is meant to be inherited from but cannot be instantiated. It may contain implemented and unimplemented members, with unimplemented members denoted as abstract. Derived classes must implement all abstract members. An interface defines a contract that classes can implement but contains no implementation. Classes implementing an interface must provide method bodies for all interface members. Interfaces can inherit other interfaces.
The document discusses generic classes in F#. It explains that generics allow code to work with any data type without repeating code for each type. It provides examples of generic methods, functions, classes, records, and discriminated unions. It demonstrates how to define a generic method, record, and class. The examples show how to specify type parameters and how the compiler infers types when they are not explicitly provided.
This document discusses delegates in F#. It defines delegates as special functions that encapsulate a method and represent a method signature, similar to function pointers in C/C++. It provides three ways to define delegates and describes simple and multicast delegates. Examples are given to demonstrate defining static and instance methods, defining delegates to reference those methods, and invoking delegates to call the methods. Delegates allow methods to be passed as arguments and attached to functions or methods at runtime.
The document discusses mutable dictionaries in F#. It describes how to create a dictionary, add/remove items from a dictionary, retrieve items from a dictionary, and handle exceptions when accessing non-existent items. It provides examples of creating a dictionary of students by name and accessing dictionary properties like count and keys. It also shows methods for adding, removing, and checking for keys/values and provides an example of a dictionary storing atomic elements by name and weight.
The document discusses mutable lists and dictionaries in F#. It describes lists as mutable collections that can be resized and allow adding elements using methods like Add. Lists are implemented as resizable arrays under the hood. The List<T> class provides properties like Count and Capacity and methods for adding, removing, and accessing elements. Dictionaries are also mutable and map keys to values, providing similar functionality to lists.
The document discusses lists vs arrays in F#, summarizing that:
- Arrays provide constant-time lookups but fixed size, while lists allow variable sizes but are slower;
- Lists are immutable and allow efficient prepending, while mutating arrays is less efficient;
- Multidimensional arrays come in rectangular (same sizes) and jagged (varying row sizes) forms.
Searching arrays uses functions like Array.find to retrieve elements matching a condition. The example shows encrypting a string using ROT13 array indexing.
This document discusses arrays in F# and provides examples of creating and manipulating arrays. It covers:
1. Three ways to create arrays - with semicolon separators, without separators, and using sequence expressions.
2. Accessing array elements using dot notation and indexes, and slice notation to access subranges.
3. Common functions for creating arrays like Array.create, Array.init, and Array.zeroCreate.
4. Other useful functions like Array.copy, Array.append, Array.map, Array.filter, and Array.reverse.
5. An example showing the Apartment type and creating an array of apartments to demonstrate array functions.
The document discusses various ways to create and initialize lists in F#:
1. Using list literals by specifying values separated by semicolons in square brackets.
2. Using the cons (::) operator to prepend values to an existing list or empty list [].
3. Using the List.init method of the List module, which takes the desired length and an initializer function to generate list items.
This document provides an introduction to Microsoft Word 2007 and its features. It covers topics such as creating documents using templates, performing basic tasks, inserting and editing pictures and tables, formatting text, working with language tools like spelling and grammar check, inserting headers and footers, and mail merge. Practical assignments are included at the end to help learners practice different Word functions like formatting text, inserting tables, sorting data, and using mail merge.
The document discusses the String class in Java. It states that a String represents a sequence of characters and belongs to the java.lang package. Character sequences can be represented using character arrays, but character arrays do not support the full range of string operations. In Java, strings are class objects implemented using the String and StringBuffer classes. Strings are immutable while StringBuffers are mutable and support modifying string contents.
The document describes various component constructor methods in Java including Labels, Buttons, TextFields, Checkboxes, RadioButtons, Lists, Dropdown Lists, TextAreas, and Scroll Bars. It provides the constructor syntax and key methods for each component type.
AWT (Abstract Window Toolkit) is a collection of classes and methods that allows creation and management of windows. It provides support for applets and contains support for window-based graphical user interfaces. Different window classes defined by AWT add functionality, with Component and Container being the base classes. Layout managers determine how components are arranged in frames using algorithms. Common layout managers include FlowLayout, BorderLayout, and GridLayout. Graphics methods allow for drawing shapes and text to windows.
The document discusses reading input from the keyboard in Java programs. It covers using the BufferedReader and InputStreamReader classes to get user input as a String. It also discusses extracting separate data items from the input String using a StringTokenizer and converting the items to primitive types using wrapper classes. An example is provided that reads numerical data from the keyboard as a String, uses StringTokenizer to separate the items, and wrapper classes to convert them to ints to calculate a result.
Java Evolution
Java was originally developed by Sun Microsystems in 1991 under the name Oak as a language for programming consumer electronics. It was later renamed to Java and became best known as a language for developing applications and applets to run on web browsers over the Internet. Key features of Java include being platform-independent, object-oriented, robust, secure, and having a rich class library. Java applications are compiled to bytecode that runs on a Java Virtual Machine, allowing them to run on any platform that supports Java.
This document discusses exception handling in Java. It defines exceptions as runtime errors that disrupt normal program flow. Exceptions are represented as objects that can be thrown and caught. There are two main types of exceptions - checked exceptions which must be handled, and unchecked exceptions which do not require handling. The try, catch, and finally keywords are used to define exception handling blocks to catch exceptions and define error recovery. Custom exceptions can also be created by extending the Exception class.
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...TechSoup
ย
Whether you're new to SEO or looking to refine your existing strategies, this webinar will provide you with actionable insights and practical tips to elevate your nonprofit's online presence.
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.pptHenry Hollis
ย
The History of NZ 1870-1900.
Making of a Nation.
From the NZ Wars to Liberals,
Richard Seddon, George Grey,
Social Laboratory, New Zealand,
Confiscations, Kotahitanga, Kingitanga, Parliament, Suffrage, Repudiation, Economic Change, Agriculture, Gold Mining, Timber, Flax, Sheep, Dairying,
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
ย
(๐๐๐ ๐๐๐) (๐๐๐ฌ๐ฌ๐จ๐ง ๐)-๐๐ซ๐๐ฅ๐ข๐ฆ๐ฌ
๐๐ข๐ฌ๐๐ฎ๐ฌ๐ฌ ๐ญ๐ก๐ ๐๐๐ ๐๐ฎ๐ซ๐ซ๐ข๐๐ฎ๐ฅ๐ฎ๐ฆ ๐ข๐ง ๐ญ๐ก๐ ๐๐ก๐ข๐ฅ๐ข๐ฉ๐ฉ๐ข๐ง๐๐ฌ:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
๐๐ฑ๐ฉ๐ฅ๐๐ข๐ง ๐ญ๐ก๐ ๐๐๐ญ๐ฎ๐ซ๐ ๐๐ง๐ ๐๐๐จ๐ฉ๐ ๐จ๐ ๐๐ง ๐๐ง๐ญ๐ซ๐๐ฉ๐ซ๐๐ง๐๐ฎ๐ซ:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...EduSkills OECD
ย
Andreas Schleicher, Director of Education and Skills at the OECD presents at the launch of PISA 2022 Volume III - Creative Minds, Creative Schools on 18 June 2024.
How to Setup Default Value for a Field in Odoo 17Celine George
ย
In Odoo, we can set a default value for a field during the creation of a record for a model. We have many methods in odoo for setting a default value to the field.
1. Contents
1
๏ Data types in Java
๏ Strings & Characters
๏ Arithmetic Operators & Expressions
๏ Type Conversion
๏ Comments
๏ Arrays
๏ Keywords
RAJESHREE KHANDE
2. Data Types, Variables, and
Constants
2
๏ Declaring Variables
๏ Primitive Data Types
๏ Initial Values and Literals
๏ String Literals and Escape Sequences
๏ Constants
RAJESHREE KHANDE
3. Data Types
3
๏ To declare a variable, assign a name (identifier) and a data type
๏ Data type tells compiler:
๏ How much memory to allocate
๏ Format in which to store data
๏ Types of operations you will perform on data
๏ Compiler monitors use of data
๏ Java is a "strongly typed" language
๏ Java "primitive data types"
byte, short, int, long, float, double, char, boolean
RAJESHREE KHANDE
4. Declaring Variables
4
๏ Variables hold one value at a time, but that value can change
๏ Syntax:
dataType identifier;
or
dataType identifier1, identifier2, โฆ;
๏ Naming convention for variable names:
๏ first letter is lowercase
๏ embedded words begin with uppercase letter
RAJESHREE KHANDE
5. Integer Types - Whole Numbers
Example declarations:
int testGrade;
int numPlayers, highScore;
short xCoordinate, yCoordinate;
byte ageInYears;
long cityPopulation;
Type Size in
byte
Minimum Value Maximum Value
byte 1 -128 127
short 2 -32768 +32677
int 4 -2, 147, 483, 648 2, 147, 483, 647
long 8 -9,223,372,036,854,775,808 9,223,372,036,854,775,807
5RAJESHREE KHANDE
6. Floating-Point Data Types
Example declarations:
float salesTax;
double interestRate;
double paycheck,
sumSalaries;
Type Size in
byte
Minimum Value Maximum Value
Float 4 1.4E-45 3.4028235E38
Double 8 4.9E-324 1.7976931348623157E308
6RAJESHREE KHANDE
7. char Data Type
๏ One Unicode character (16 bits - 2 bytes)
Type Size Minimum Value Maximum Value
in Bytes
char 2 character character
encoded as 0 encoded as
FFFF
Example declarations:
char finalGrade;
char newline, tab, doubleQuotes;
7RAJESHREE KHANDE
8. boolean Data Type
8
๏ Two values only:
true
false
๏ Used for decision making or controlling the order
of execution of a program
๏ Example declarations:
boolean isEmpty;
boolean passed, failed;
RAJESHREE KHANDE
9. Assigning Values to Variables
9
๏ Assignment operator =
๏ Value on the right of the operator is assigned to the variable
on the left
๏ Value on the right can be a literal (text representing a specific
value), another variable, or an expression (explained later)
๏ Syntax:
dataType variableName = initialValue;
Or
dataType variable1 = initialValue1,
variable2 = initialValue2, โฆ;
RAJESHREE KHANDE
10. Assigning the Values of Other
Variables
10
๏ Syntax:
dataType variable2 = variable1;
๏ Rules:
1. variable1 needs to be defined before this statement appears
in the source code
2. variable1 and variable2 need to be compatible data types; in
other words, the precision of variable1 must be lower than or
equal to that of variable2.
RAJESHREE KHANDE
11. Compatible Data Types
11
Any type in right column can be assigned to type in left
column:
Data Type Compatible Data Types
byte byte
short byte, short
int byte, short, int, char
long byte, short, int, long, char
float float, byte, short, int, long, char
double float, double, byte, short, int, long, char
boolean boolean
char char
RAJESHREE KHANDE
12. String Concatenation Operator (+)
12
๏ Combines String literals with other data types for printing
๏ Example:
String hello = "Hello";
String there = "there";
String greeting = hello + ' ' + there;
System.out.println( greeting );
Output is:
Hello there
RAJESHREE KHANDE
13. Escape Sequences
13
๏ To include a special character in a String, use an
escape sequence
Character Escape Sequence
Newline n
Tab t
Double quotes "
Single quote '
Backslash
Backspace b
Carriage return r
Form feed f
See Example 2.3 Literals.java
RAJESHREE KHANDE
14. Assigning the Values of Other
Variables
14
๏ Syntax:
dataType variable2 = variable1;
๏ Rules:
1. variable1 needs to be defined before this statement appears
in the source code
2. variable1 and variable2 need to be compatible data types; in
other words, the precision of variable1 must be lower than or
equal to that of variable2.
RAJESHREE KHANDE
15. Sample Assignments
15
๏ This is a valid assignment:
float salesTax = .05f;
double taxRate = salesTax;
๏ This is invalid because the float data type is lower
in precision than the double data type:
double taxRate = .05;
float salesTax = taxRate;
RAJESHREE KHANDE
16. String Concatenation Operator (+)
16
๏ Combines String literals with other data
types for printing
๏ Example:
String hello = "Hello";
String there = "there";
String greeting = hello + ' ' + there;
System.out.println( greeting );
Output is:
Hello there
RAJESHREE KHANDE
17. Common Error Trap
17
๏ String literals must start and end on the
same line. This statement:
System.out.println( "Never pass a water fountain
without taking a drink" );
generates these compiler errors:
unclosed string literal
')' expected
๏ Break long Strings into shorter Strings and use
the concatenation operator:
System.out.println( "Never pass a water fountain"
+ " without taking a drink" );
RAJESHREE KHANDE
18. String Concatenation Operator (+)
18
๏ Combines String literals with other data
types for printing
๏ Example:
String hello = "Hello";
String there = "there";
String greeting = hello + ' ' + there;
System.out.println( greeting );
Output is:
Hello there
RAJESHREE KHANDE
19. Common Error Trap
19
๏ String literals must start and end on the same line. This
statement:
System.out.println( "Never pass a water fountain
without taking a drink" );
generates these compiler errors:
unclosed string literal
')' expected
๏ Break long Strings into shorter Strings and use the
concatenation operator:
System.out.println( "Never pass a water fountain"
+ " without taking a drink" );
RAJESHREE KHANDE
20. 20
๏ Declare a variable only once
๏ Once a variable is declared, its data type cannot
be changed.
These statements:
double twoCents;
double twoCents = .02;
generate this compiler error:
twoCents is already defined
RAJESHREE KHANDE
21. 21
๏ Once a variable is declared, its data type cannot
be changed.
These statements:
double cashInHand;
int cashInHand;
generate this compiler error:
cashInHand is already defined
RAJESHREE KHANDE
22. Constants
22
๏ Value cannot change during program execution
๏ Syntax:
final dataType constantIdentifier =
assignedValue;
Note: assigning a value when the constant is
declared is optional. But a value must be
assigned before the constant is used.
๏
RAJESHREE KHANDE
23. Mixed-Type Arithmetic
23
๏ When performing calculations with operands of different
data types:
๏ Lower-precision operands are promoted to higher-precision
data types, then the operation is performed
๏ Promotion is effective only for expression evaluation;
not a permanent change
๏ Called "implicit type castingโ
๏ Bottom line: any expression involving a floating-point operand
will have a floating-point result.
RAJESHREE KHANDE
24. Rules of Promotion
24
Applies the first of these rules that fits:
1. If either operand is a double, the other operand is converted
to a double
2. If either operand is a float, the other operand is converted to a
float.
3. If either operand is a long, the other operand is converted to a
long.
4. If either operand is an int, the other operand is promoted to an
int
5. If neither operand is a double, float, long, or an int, both
operands are promoted to int.
RAJESHREE KHANDE
25. Explicit Type Casting
25
๏ Syntax:
(dataType)( expression )
Note: parentheses around expression are optional
if expression consists of 1 variable
๏ Useful for calculating averages
RAJESHREE KHANDE
26. Operator Precedence
26
Operator Order of
evaluation
Operation
( ) left - right parenthesis for explicit grouping
++ -- right - left preincrement, predecrement
++ -- right - left postincrement, postdecrement
* / % left - right multiplication, division, modulus
+ - left - right addition or String concatenation,
subtraction
= += -= *=
/= %=
right - left assignment
RAJESHREE KHANDE
27. Variables and Assignments
27
๏ Variables
๏ Types
๏ char 16 bits Unicode character data
๏ boolean Boolean Variable
๏ byte 8 bits signed integer
๏ short 16 bits signed integer
๏ int 32 bits signed integer
๏ long 64 bits signed integer
๏ float 32 bits signed floating point number
๏ double 64 bits signed floating point number
RAJESHREE KHANDE
28. Strings and Characters
28
๏ String : sequence of character
String s = โEnter an integer value: โ ;
Char c = โAโ;
๏ Concatenation Operator โ+โ
String s = โLincoln said: โ + โโ Four score and seven
years agoโโ ;
Result :
Lincoln said: โFour score and seven years agoโ
RAJESHREE KHANDE
29. Expression
29
char ch; int i; float f; double outcome;
ch = โ0โ; i = 10; f = 10.2f;
outcome = ch * i / f;
double
double float
float long
long int
Yes No
Yes No
Yes No
RAJESHREE KHANDE
30. Assignment
30
๏ Widening Conversion
byte b = 127;
int i;
i = b;
๏ Narrowing Conversion
byte b;
int i = 258;
b = (byte) i;
๏ Wrong Conversion
byte b;
int i = 127;
b = i;
๏ Right Conversion (But data may be lost)
byte b;
int i = 127;
b = (byte) i;
Type Casting
RAJESHREE KHANDE
31. Java Keywords
31
๏ 50 Java Keywords
abstract double int super
boolean else interface switch
break extends long synchronized
byte final native this
case finally new throw
catch float package throws
char for private transient*
class goto* protected try
const* if public void
continue implements return volatile
default import short while
do instanceof static strictfp
assert (New in 1.5) enum (New in 1.5)
The โassertโ is recognized as keyword in JDK1.4 compiler, but we could not
use it.
It can be used it from 1.5.RAJESHREE KHANDE
32. Flow of Control
32
๏ Java executes one statement after the other in the
order they are written
๏ Many Java statements are flow control statements:
Alternation: if, if else, switch
Looping: for, while, do while
Escapes: break, continue, return
RAJESHREE KHANDE
34. If โ The Conditional Statement
34
๏ The if statement evaluates an expression and if that
evaluation is true then the specified action is taken
if ( x < 10 ) x = 10;
๏ If the value of x is less than 10, make x equal to 10
๏ It could have been written:
if ( x < 10 )
x = 10;
๏ Or, alternatively:
if ( x < 10 )
{ x = 10; }
RAJESHREE KHANDE
35. Ifโฆ else
35
๏ The if โฆ else statement evaluates an expression and
performs one action if that evaluation is true or a
different action if it is false.
if (x != oldx)
{
System.out.print(โx was changedโ);
}
else {
System.out.print(โx is unchangedโ);
}
RAJESHREE KHANDE
36. Nested if โฆ else
36
if ( myVal > 100 ) {
if ( remainderOn == true) {
myVal = mVal % 100;
}
else {
myVal = myVal / 100.0;
}
}
else
{
System.out.print(โmyVal is in rangeโ);
}
RAJESHREE KHANDE
37. else if
37
๏ Useful for choosing between alternatives:
if ( n == 1 ) {
// execute code block #1
}
else if ( j == 2 ) {
// execute code block #2
}
else {
// if all previous tests have failed, execute code
block #3
}
RAJESHREE KHANDE
38. The switch Statement
38
switch ( n ) {
case 1:
// execute code block #1
break;
case 2:
// execute code block #2
break;
default:
// if all previous tests fail then
//execute code block #4
break;
}
RAJESHREE KHANDE
39. The for loop
39
๏ Loop n times
for ( i = 0; i < n; n++ )
{
// this code body will execute n times
// ifrom 0 to n-1
}
๏ Nested for:
for ( j = 0; j < 10; j++ )
{
for ( i = 0; i < 20; i++ )
{
// this code body will execute 200 times
}
}
RAJESHREE KHANDE
41. do {โฆ } while loops
41
do
{
System.out.print( โID =โ + userID[n] );
n++;
response = readInt( โEnter โ );
}while (response == 1);
RAJESHREE KHANDE
42. Break
42
๏ A break statement causes an exit from the
innermost containing while, do, for or switch
statement.
for ( int i = 0; i < maxID, i++ )
{
if ( userID[i] == targetID )
{
index = i;
break;
}
} // program jumps here after break
RAJESHREE KHANDE
43. Continue
43
๏ Can only be used with while, do or for.
๏ The continue statement causes the innermost loop to start the
next iteration immediately.
for ( int i = 0; i < maxID; i++ )
{
if ( userID[i] != -1 )
continue;
System.out.print( โUserID โ + i + โ :โ + userID)
}
RAJESHREE KHANDE
44. Arrays
44
๏ Am array is a list of similar things
๏ An array has a fixed:
๏ name
๏ type
๏ length
๏ These must be declared when the array is created.
๏ Arrays sizes cannot be changed during the execution
of the code
RAJESHREE KHANDE
45. 45
myArray has room for 8 elements
๏ฎ The elements are accessed by their index
๏ฎ in Java, array indices start at 0
3 6 3 1 6 3 4 1myArray =
0 1 2 3 4 5 6 7
Arrays
RAJESHREE KHANDE
46. Declaring Arrays
46
๏ int myArray[];
๏ declares myArray to be an array of integers
๏ myArray = new int[8];
๏ sets up 8 integer-sized spaces in memory, labelled
myArray[0] to myArray[7]
๏ int myArray[] = new int[8];
๏ combines the two statements in one line
RAJESHREE KHANDE
47. Assigning Values
47
๏ Refer to the array elements by index to store values in
them.
๏ myArray[0] = 3;
๏ myArray[1] = 6;
๏ myArray[2] = 3; ...
๏ Can create and initialise in one step:
๏ int myArray[] = {3, 6, 3, 1, 6, 3, 4, 1};
RAJESHREE KHANDE
48. Iterating Through Arrays
48
๏ for loops are useful when dealing with arrays:
for (int i = 0; i < myArray.length; i++)
{
myArray[i] = getsomevalue();
}
RAJESHREE KHANDE
49. Class & Object
49
๏ What Are Classes?
A class is a blueprint or prototype that defines the
variables and the methods common to all objects of a
certain kind.
๏ What Is an Object?
An object is a software bundle of variables and
related methods. Software objects are often used to
model real-world objects you find in everyday life.
RAJESHREE KHANDE
50. 50
Class vs. Object
๏ฎ Specifies the structure
(the number and types)
of its objectsโ attributes
๏ฎ the same for all of its
objects
๏ฎ Specifies the possible
behaviors of its objects
๏ฎ Holds specific values of
attributes
๏ฎ These values can
change while the
program is running
๏ฎ Behaves appropriately
when called upon
RAJESHREE KHANDE
51. 51
Class vs. Object
๏ฎ A piece of the programโs
source code
๏ฎ Written by a
programmer
๏ฎ An entity in a running
program
๏ฎ Created when the
program is running (by
the main method or a
constructor)
RAJESHREE KHANDE
52. 52
Classes
public class Car
{
...
}
Car.java By convention, the
name of a class (and
its source file) always
starts with a capital
letter.
(In Java, all names are case-sensitive.)
RAJESHREE KHANDE
53. public class SomeClass
53
๏ Fields
๏ Constructors
๏ Methods
}
Attributes / variables that define the
objectโs state; can hold numbers,
characters, strings, other objects
Procedures for constructing a
new object of this class and
initializing its fields
Actions that an object of this
class can take (behaviors)
{
Class header
SomeClass.java
import ... import statements
RAJESHREE KHANDE
54. Classes
54
๏ A class is a collection of fields (data) and methods
(procedure or function) that operate on that data.
๏ The basic syntax for a class definition:
๏ Bare bone class โ no fields, no methods
public class Circle {
// my circle class
}
Class ClassName
{
[fields declaration]
[methods declaration]
}
RAJESHREE KHANDE
55. Classes
55
๏ Classes describe the data held by each of its objects
๏ A class may describe any number of objects
๏ A class may describe a single object, or even no
objects at all.
RAJESHREE KHANDE
57. Adding Fields: Class Circle
with fields
57
๏ Add fields
๏ The fields (data) are also called the instance
varaibles.
public class Circle {
public double x, y; // centre coordinate
public double r; // radius of the circle
}
RAJESHREE KHANDE
58. Adding Methods
58
๏ A class with only data fields has no life. Objects created
by such a class cannot respond to any messages.
๏ Methods are declared inside the body of the class but
immediately after the declaration of data fields.
๏ The general form of a method declaration is:
type MethodName (parameter-list)
{
Method-body;
}
RAJESHREE KHANDE
59. Adding Methods to Class
Circle
59
public class Circle {
public double x, y; // centre of the circle
public double r; // radius of circle
//Methods to return circumference and area
public double circumference() {
return 2*3.14*r;
}
public double area() {
return 3.14 * r * r;
}
}
public class Circle {
public double x, y; // centre of the circle
public double r; // radius of circle
//Methods to return circumference and area
public double circumference() {
return 2*3.14*r;
}
public double area() {
return 3.14 * r * r;
}
}
Method Body
RAJESHREE KHANDE
60. Data Abstraction &
Encapsulation
60
๏ The wrapping of data & method in single unit called
class is known as encapsulation.
๏ The data is not accessible to the outside world & only
those methods which wrapped inside the class can
access it.
๏ These methods provide the interface between objects
data & program.
๏ The insulation of data from direct access is called as
data hidingRAJESHREE KHANDE
61. Data Abstraction & Encapsulation
61
๏ Abstraction refers to representing essential features
without including the background details.
๏ Classes uses the concept of abstraction & are defined
as list of abstract attribute such as size ,weight & cost
and method that operate on theses data.
๏ Declare the Circle class, have created a new data type
โ Data Abstraction
Circle aCircle;
Circle bCircle;
RAJESHREE KHANDE
62. Class of Circle cont.
62
๏ aCircle, bCircle simply refers to a Circle object, not
an object itself.
aCircle
Points to nothing (Null Reference)
bCircle
Points to nothing (Null Reference)
null null
RAJESHREE KHANDE
63. Creating objects of a class
63
๏ Objects are created dynamically using the new
keyword.
๏ aCircle and bCircle refer to Circle objects
bCircle = new Circle() ;aCircle = new Circle() ;
RAJESHREE KHANDE
64. 64
Creating objects of a class
aCircle = new Circle();
bCircle = new Circle() ;
bCircle = aCircle;
P
aCircle
Q
bCircle
Before Assignment
P
aCircle
Q
bCircle
Before Assignment
RAJESHREE KHANDE
65. Automatic garbage collection
65
๏ The object does not have a reference and
cannot be used in future.
๏ The object becomes a candidate for automatic garbage
collection.
๏ Java automatically collects garbage periodically and
releases the memory used to be used in the future.
Q
RAJESHREE KHANDE
66. Accessing Object/Circle Data
66
๏ Similar to C syntax for accessing data defined in a
structure.
Circle aCircle = new Circle();
aCircle.x = 2.0 // initialize center and radius
aCircle.y = 2.0
aCircle.r = 1.0
ObjectName.VariableName
ObjectName.MethodName(parameter-list)
RAJESHREE KHANDE
67. Executing Methods in Object/Circle
67
๏ Using Object Methods:
Circle aCircle = new Circle();
double area1;
aCircle.r = 1.0;
area1 = aCircle.area();
sent โmessageโ to aCircle
RAJESHREE KHANDE
68. Using Circle Class
68
// Circle.java: Contains both Circle class and its user class
public class Circle
{
public double x, y; // centre of the circle
public double r; // radius of circle
//Methods to return circumference and area
public double circumference() {
return 2*3.14*r;
}
public double area() {
return 3.14 * r * r;
}
}
RAJESHREE KHANDE
69. Using Circle Class
69
class MyMain
{
public static void main(String args[])
{
Circle aCircle; // creating reference
aCircle = new Circle(); // creating object
aCircle.x = 10; // assigning value to data field
aCircle.y = 20;
aCircle.r = 5;
double area = aCircle.area(); // invoking method
System.out.println("Radius="+ aCircle.r+ " Area=โ + area);
}
} RAJESHREE KHANDE
70. Access Specifiers
70
๏ In Java code, class and variable and method and
constructor declarations can have โaccess specifiersโ
:
- private
- protected
- public.
- none (default)
๏ The purpose of access specifiers is to declare which
entity can not be accessed from where.
RAJESHREE KHANDE
71. Access Specifiers for Class
Variables and Methods
71
Specifier class subclass package World
private Y
protected Y Y Y
public Y Y Y Y
none Y Y
RAJESHREE KHANDE
72. Protected
72
๏ If a variable is declared protected, then the class
itself can access it.
๏ Its subclass can access it
๏ Any class in the same package can also access it.
RAJESHREE KHANDE
73. Public
73
๏ Public classes, methods, and fields can be accessed from
everywhere.
๏ The only constraint is that a file with Java source code can only
contain one public class whose name must also match with the
filename.
๏ If it exists, this public class represents the application or the
applet, in which case the public keyword is necessary to enable
your Web browser or appletviewer to show the applet.
๏ You use public classes, methods, or fields only if you explicitly
want to offer access to these entities.
public class Square
{ // public class public x, y, size; // public instance variables }
RAJESHREE KHANDE
74. Access Specifiers
74
๏ None
๏ If a class member doesn't have any access
specifier , then the class itself can access it.
๏ Any class in the same package can also access it.
RAJESHREE KHANDE
75. Access Specifiers
75
class P
{
int x = 7;
}
public class AS
{
public static void main(String[] args)
{
P p = new P();
System.out.println(p.x);
}
}
The code compiles and
runs. But, if you add
โprivateโ in front of โint xโ,
then you'll get a compiler
error: โx has private
access in Pโ. This is
because when a
member variable is
private, it can only be
accessed within that
class
RAJESHREE KHANDE
76. Access Specifiers for Classes
76
๏ For classes, only the โpublicโ access specifier can be used.
๏ Basically, Java has this โOne Class Per Fileโ paradigm.
๏ That is, in every java source code file, only one class in the file is
public accessible, and that class must have the same name as
the file.
๏ Optionally, the class can be declared with โpublicโ keyword.
๏ If you use any other access specifier on classes, or declare more
than one class โpublicโ in a file, the compiler will give an error.
RAJESHREE KHANDE
77. Pass by value
77
๏ Pass-by-value
๏ The actual parameter (or argument expression) is fully
evaluated and the resulting value is copied into a location
being used to hold the formal parameter's value during
method/function execution.
๏ That location is typically a chunk of memory on the runtime
stack for the application (which is how Java handles it), but
other languages could choose parameter storage differently.
๏ Pass-by-reference
๏ The formal parameter merely acts as an alias for the actual
parameter. Anytime the method/function uses the formal
parameter (for reading or writing), it is actually using the actual
parameter.
๏ Java is strictly pass-by-value,
RAJESHREE KHANDE
78. Pass by value
78
๏ In Java, Objects are passed by reference, and
primitives are passed by value.
๏ This is half incorrect. Everyone can easily agree that
primitives are passed by value; there's no such thing
in Java as a pointer/reference to a primitive.
๏ However, Objects are not passed by reference. A
correct statement would be Object references are
passed by value.
RAJESHREE KHANDE
79. this keyword
79
๏ Sometimes a method will need to refer to the object
that invoked it.
๏ To allow this, Java defines the this keyword.
๏ this can be used inside any method to refer to the
current object.
๏ That is, this is always a reference to the object on
which the method was invoked.
RAJESHREE KHANDE
80. this keyword
80
๏ 'this' is used for pointing the current class instance.
๏ It can be used with variables or methods. Look into
the following example:
class Test
{ private int i=10;
public void m()
{ System.out.println(this.i);
}
}
RAJESHREE KHANDE
81. this keyword
81
๏ this keyword is useful when we use same name
for parameter and instance variable
๏ In the above code this is used for the current
instance.
๏ Since this is instance of a class it cannot be used
inside a static method.
RAJESHREE KHANDE
82. this : Example
82
class Cat
{
int height weight;
public accept( int height, int weight)
{
this.height = height;
this.weight =weight;
}
}
RAJESHREE KHANDE
83. Static variable & Static Method
83
๏ Like instance variable, static variable is declare inside
a class but outside any method.
๏ Keyword static is used while declaring static variable.
๏ Syntax
static int count;
static int max(int x, int y);
Static variable
Static method
RAJESHREE KHANDE
84. Static variable & Static Method
84
๏ The static variable & static method belong to class
rather than object these variables is also called as
class variable and class method.
๏ Static variable is defined when we have a variable
common to all instance of class.
๏ These member are accessed with class name.
Syntax:
classname.staticVariableName;
classname.staticMethodName();
RAJESHREE KHANDE