Java Programming Tutorial PDF
Document Details
![InterestingHeisenberg](https://quizgecko.com/images/avatars/avatar-13.webp)
Uploaded by InterestingHeisenberg
Tags
Summary
This document appears to be an introduction to Java programming and object-oriented programming principles. It covers key concepts such as classes, methods, and different data types used in Java. This is a useful document for anyone learning the foundations of Java programming.
Full Transcript
2.10 Modularity – the process of dividing a computer program into separate smaller sub-programs that can be implemented and tested on their own before combining them all together to build the final program When a program increases in size and complexity, design...
2.10 Modularity – the process of dividing a computer program into separate smaller sub-programs that can be implemented and tested on their own before combining them all together to build the final program When a program increases in size and complexity, designing, implemen;ng, and tes;ng it becomes cumbersome - Modularity in the program development is meant to solve this drawback by separa;ng the program into smaller pieces The division of the program into smaller sub-programs is more effec;ve when there are logic boundaries between the sub-programs, and there are very few dependencies with each other 3.1 Class – in OOP, defines a template through which objects may be created - Provide specific data and ac;ons Iden>fier – a name that iden;fies an en;ty - Generated by alphanumeric sequences, underscore, and shouldn’t begin with a digit Primi>ve – a predefined iden;fier (keyword) that us provided by a programming language as a basic building block - Primi>ve data includes: 1. Characters (char) – primi;ve type that represents a character 2. Integers (int, short, long, byte) – 4 primi;ve data types that iden;fy integers depending on the range of integers that need to be represented 3. Floa;ng point numbers (float, double) – two or more primi;ve types that iden;fy floa;ng-point numbers depending on the range and precision that is required 4. Boolean (bool) – primi;ve type that may take only one of two values, true/false 3.2 Method – ac;ons that are associated with an object - Provide interface an object depicts to the outside world in that through those methods other classes can access and modify its data proper;es Accessor – a special kind of method that is called in order to read a specific data value of an object Mutator – a special kind of method that is called in order to modify a specific data value of an object Constructor - a special kind of method that is called when an object is instan;ated so that it ini;alizes its data with par;cular values - Run only once when an object is created - They use the name of the class and have no return type Signature – iden;fies the method – every method has it - Includes the name of the method, as well as its parameters, their number, and types - Return types are not considered part of the signature Return value – value that is passed back, returned, to the code that called the specific method which returns the value - The value returned aVer the execu;on of the method has taken place 3.3 Private, protected, public – these three terms are strongly related to each other in that they are access modifiers that allow for the implementa;on of encapsula;on - They provide the compiler with informa;on as to which other classes can have access to class data and ac;ons Private – if some data is private, it can be accessed only by the class that defines it Protected – if some data or ac;on is protected, then only the class that defines it and its subclasses can access it Public – if some data or ac;on is public, then any class can access it 3.4 There are mainly 8 primi;ve data types BYTE – minimum value: -128 - Maximum value: 127 - It occupies 8 bits of memory - Typically used for saving memory in large arrays of small numbers SHORT - minimum value: -32.768 - Maximum value: 32,767 - It occupies 16 bits of memory - Typically used for the same reason as a byte but for a wider range of numbers INT - minimum value: -231 - Maximum value: 231-1 - It occupies 32 bits of memory - Most commonly used primi;ve data type to represent integer numbers LONG - minimum value: -263 - Maximum value: 263-1 - It occupies 64 bits of memory - Primi;ve data type used to represent integer numbers when the range of the int data type is not sufficient FLOAT – minimum and maximum values are beyond the scope of this book - Ranges from 1.4-45 to 3.438 - Occupies 32 bits of memory - Typically used for saving memory in large arrays of floa;ng point numbers - Should not be used as a data type for numbers that need precision DOUBLE Ranges from 4.9-324 to 1.7308 It occupies 64 bits of memory Typically used for the representa;on of decimal values Should not be used as a data type for precise values such as currency CHAR Minimum value: ‘\u000’ – 0 Maximum value: ‘\ufff’ – 65,353 Occupies 16 bits of memory Represents a Unicode character BOOLEAN Can take only one of two values: true or false Typically used for condi;ons that may have one of two outcomes STRING It is not a primi;ve data type but rather a reference class Typically used to represent a series of characters (ex. A word or sentence) Once it is created, its value cannot change, and it is thus immutable 3.5 – 3.8 – code examples 3.9 Modern programming languages enable interna>onaliza>on in a variety of ways: - Support for the display of interna;onal fonts and text - Support for language and local specific needs, such as date and ;me formalng - Support for different keyboard layouts, as well as complex characters and symbols - Support for variety of wri\en languages with the use of Unicode, allowing the representa;on and handling of text in most languages - Support for user language auto-detec;on and tailoring of the user experience according to it - Support for global development of soVware that includes localized content 3.10