Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
83 views
211 pages
Java 6 in Simple Steps
Uploaded by
Java Developer
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save 8177228560 Java 6 In Simple Steps For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
83 views
211 pages
Java 6 in Simple Steps
Uploaded by
Java Developer
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save 8177228560 Java 6 In Simple Steps For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save 8177228560 Java 6 In Simple Steps For Later
You are on page 1
/ 211
Search
Fullscreen
« An all-inclusive book to + Quick and Easy learning in sami teach you everything Simple Steps dream ech about Java 6 « Most preferred choice Lr » Easy, Effective, and worldwide for Reliable learning java 6 Welcome to the Installation Wizard for Java(TM) SE Development Kit 6 Java(TM) SE Development Kit 6 Setup is preparing the = Installation Wizard which will guide you through the progr setup process. Please wait.©Copyright by Dreamtech Press, 19-A, Ansari Road, Daryaganj, New Dethi-1 10002 ‘This book may not be duplicated in any way without the express written consent af the publisher, except in the form of brief excerpts or quotations for the purposes of review. The information contsined herein is for the Personal use of the reader and may not be incorporated in any commercial programs, other books, databases, or any kind of software without written consent of the publisher. Making copies of this book oc any portion for any purpose other than your own is a violation of copyright laws. Limits of Liabitity/disclaimer of Warranty: The author and: publisher have used their best efforts in preparing this book. The author make no representation or warranties with respect to the accuracy or completeness of the contents af this book, and specifically disclaim any implied warranties of merchantability or fiiness of any particular purpose. There are no warranties which extend beyond the descriptions contained in this paragraph. No warranty may be created or extended by sales representatives or written sales materials. The accuracy and completeness of the information provided hercin and the opinions stated herein are not guaranteed or warranted to produce any particulars results, and the advice and strategies contained herein may not be suitable for every individual. Neither Dreamicch Press nor author shall be lisble for any loss of profit or any other commercial damages, including but not limited ta special, incidental, consequential, or other damages. Trademarks; All brand names and product names used in this book are wademarks, registered wademarks, or trade names of their respective holders. Dreamtech Press is not associated with any product or vendor mentioned in this book, ISBN: — 13-978-81-7722-856-4 Edition: 2009 Printed at: Printman India, Patparganj, Delhi.CONTENTS RG ee Baes Introduction of java SE Desktop Improvements. Core Improvements.... Getting and Installing Java, A Simple Java Program Compiling and Running the Program. _ Summary, 12 Declaring a Variable.. 14 Understanding Data Types. Integer Types... Understanding Operators Using Arithmetic Operators ws Increment and Decrement Operator Using Bitwise Operators. Using Relational Operators Using the Boolean Operator... Using the Boolean Logical Operator Using the ?: Operator. Working with Arrays. Using One Dimensional Array Using Two Dimensional Array Using the Varargs Feature. Summary... ia Fi Sa ss ego ob Implementing Conditional Statements. Using if statement... Using if-else statement Using switch statement. Implementing Iteration Statements ..Using for Loop ... Using for-each Leop Working with Nested Loop.. Implementing Jump Statements Using break statement .. Using continue statement Using return Statement Summary... Qvervlew Of C15. sissiseississiessnssessaiscsscissississiscissiasniasisscsassissisirnsesennn SE Working with Objects.. Working with Methods Working with Constructors.. Using Default Constructor... Using Parameterized Constructors... Working with Inner Classes Explosing Packages .. Built-in Packages . User-defined packages. Using Access Specifiers Summary ... Java 6 in Simple Steps 1 - Using do-while Loop i Understanding Encapsulation Understanding Abstraction . Understanding Inheritance. Using Method Overriding..... Understanding the final Keyword Implementing Interfaces... Implementing Abstract Classes and Methods... Difference between Abstract Classes and Interfaces os seteeeeses 2B Defrence Between Polymorphism.. Understanding Static Polymorphismfer de Bienes enn cae ar 83 Overview of Exceptions... Exception Handling Techniqu Using the try and catch Blocks... Using Multiple catch Blocks.. Using Nested t Using the throw Clause. Using the throws Clause Built-in Exceptions. Implementing Inter-Thread Communicatior Understanding DeadLocks in Threads... The Queue Interface. The Deque Interface. Exploring the Collection Classes. The ArrayList Class. The HashSet Class. viiJava 6 in Simple Steps eee aay els sth tun) eect Stam Byte Streams... Character Streams, Reading Console Input. Reading Lines from a Text File. Writing Text to a File Reading Bytes from a File Summary. fe iets ViliWorking with the JTabbedPane.. Implementing Layout Managers ‘The FlowLayout Manage! The BorderLayout Manager. The GridLayout Manager. The GridBagLayout Manager ‘Overview of Events.. ‘Components of Eve KeyListener.. MouseListener.. AdjustmentListener. Understanding Applets Life Cycle of an Applet Using the
HTML Tag Drawing Graphics in Applets Adding Controls to Applets Advanced GUI Features asses Working with the System Tray Working with the Splash Screen. Working with Dialog Modality Working with the GIF Writer .. SummatUrheberrechtlich geschiitztes Bild Urheberrechtlich geschiitztes MaterialJava 6 in Simple Steps ‘ava is a programming language, which inherits its object oriented features from C++. Java language was created by a software developer, James Gasling, at Sun Micrasystems in 1991. It was first called Oak, which got changed to Java in 1995, when it was first released for public use. The original idea for Java was to create a platform independent and object oriented language that could run on any operating system. Java has a slogan that is ‘write once, compile once, and run anywhere’. This slogan means once a program is compiled and run successfully on a platform then that program can easily be executed on any other operating system. Downloading and installing the Java Software Development Kit is also discussed in this chapter. Then, we discuss how to create, compile, and run a simple Java program, Now, let's start with discussing the following features of Java that make it mare robust than other languages: 2 Portability: in the distributed world of Internet, an application developed with the help of a programming language might be accessed on various computers having different kinds of Operating systems. But, it's mot guaranteed that the application is portable, that is the application runs successfully on all operating systems. To overcome this portability issue, Java introduces a cancept of what is known as Bylecode. Bytecode is a set of instructions that is generated by Java compiler on compiling a Java program. In other madern programming languages, a program is compiled into an executable code but in Java, a program gets compiled into an intermediate code called Bytecade. This Bytecode then gets executed by Java runtime system called the Java Virtual Machine (JVM). Now, only the JVM needs to be implemented on the system where the Java program has to be executed. JVM is also considered as the Interpreter of Bytecade. In this way, Java has solved the problem of portability. Q Muhithreading: Java is a programming language designed for the distributed environment of the Internet and for that the concept of multithreading is implemented. This feature helps to write interactive programs wherein multiple tasks can be performed simultaneously; thus. making it a robust programming language. Q Memory Management: In Java, all memory management processes are handled automatically. Whenever a program is created, you allocate some memory to the objects used in the program and deallocate (frees) that allocated memory. In Java, you do not need to worry about freeing the memory because Java provides automatic garbage collection that is when the objects are not in use the memory allocated to them will be freed by Java. For example, you have created an array that can store 100 elements, which means you have reserved space for 100 elements. So, when the array completes its functioning and no longer in use then Java frees up the memory allocated to the array. Now, this space can be used by other Java objects. In other programming languages such as C+, you also have to write the code to deallocate (frees) the memory, which seems a very tedious process as a programmer needs to remember that memory for which object needs to be deallocated. Sometimes programmers deallocate the memary of the objects that are currently in use and this can harm the process. That’s why memory management is a tedious in languages such as a C++ but not in Java because here the memory management is automatic. Security: Java is a secure language as the programs created in Java are confined to the Java runtime environment that is they can only access that part of your computer hard disk, which is required to execute the program. Java programs are not allowed to. access the data outsideChapter 1: Geiting Started with fava SE 6 of Java runtime environment so, downloading Java application through internet won't harm your computer than the applications made in other programming languages can does. That's why Java is a secure language. D Distributed: Java is a distributed language as it can be used to create applications to communicate over the network, Java can communicate over the network because it supports TCP/IP (Transmission Control Protacol/nternet Protacol). The TCPAP protocol is a set of network communication protacol. The latest release of Java Standard Edition platform is called Java SE 6, which we discuss in the next section. Introduction of Java SE 6 With the release of Java SE 6, Sun came up with a new naming convention for Java Platform by dropping *2" from its name, thereby making the platform Java SE. As with J2SE 5, the 6 in Java SE 6 is the product version number. The developer version number for the same is 1.6. Java SE 6 comes up with many new features as an improvement to the platform. These improvements can be broadly seen under following categories: Q Desktop Q Core Desktop Improvements ‘With Java SE 6, it is now possible to integrate Java with the host system it runs on to improve the development of desktop applications. This became possible with the introduction of some new desktop features, such as browser, email editor, file-type associations, the system tray, application launching, and printing available with the latest Java release. These desktop features are based on JDesktop Integration Components (DIC). Here, an overview of the new features regarding desktop improvements is given: Q System Tray Support: It is an area that can be shared by all running applications that are usually located at the bottom right corner of the desktop. The addition of SystemTray and Traylcon classes in java.awt package enables us to add icons, tool-tips, and pop-up menus to the system tray. Java application can respond ta mouse clicks on system tray items. Q Splash Screen Support: It is a processing screen that appears just before starting of an application and informs the user that the application has been started. Java SE 6 provides support for Splash screen which can be displayed even before JVM starts. Q java 2D Enhancements: Now with Java SE 6, Java 20 graphical libraries started using desktop's anti-aliasing font settings to ensure consistent text rendering. This improvement has been made to improve the quality af the text to be displayed on LCD monitors. Q@ The New Desktop API: A new java.awt.Desktop class has been introduced in Java SE 6, which helps in Desktop application development. Java applications can now launch browser, email clients, and other desktop applications.Java 6 in Simple Steps Core Improvements In Java SE 6, many improvements have been made in core features, such as Framework, Security, and Web Services, Let’s now see the features related to core improvements introduced in Java Q Enhanced Collection Framework, Dynamic Compilation a Database Q Web Services a Security Enhanced Collection Framework Collection framework is a framework that provides a set of interfaces (such as List, Map) and classes, (such as ArrayList, LinkedList to store elements of different datatypes. Collection framework has been improved with addition of same new collection interfaces and some new class implementations. For example, Double ended queue (Deque) that supports insertion and deletions from both ends has been introduced. The package java.util.concurrent has been updated with interfaces, such as BlockingDeque and ConcurrentNavigableMap. Sorted sets and maps with bidirectional navigation have been introduced, New methads, such as copyof and copyofRange that can resize, truncate, and copy arrays of all types have been introduced in the Array class. Dynamic Compilation Compiling a Java source code at the time of running a Java application is called as Dynamic Compilation. Java SE 6 implements JSR 199 that specifies some interfaces that support runtime access to Java compiler (javac) programmatically to compile a dynamically generated Java code. Compiler Framework contains Java Compiler API, which has been developed around JavaCompilerToo! interface representing a dynamically usable Java compiler. This API is useful not only for normal Java programmers but it also helps in the creation of Java development tools. Database Java SE 6 comes with new features of JOBC 4.0 that help in automatic loading of the database drivers. Other enhanced features include use of Query interface and JDBC annotation. A new interface java.sql. Dataset has been added in JDBC 4.0, which gives a collection of data returned by a method designed with @select annotation in a Query interface. A dataset can work in a connected ot in a disconnected mode. Web Services ‘Web services are Web based applications that are used to exchange data with the clients. New APIs (Application Programming Interfaces) to support Web services have been introduced in Java SE 6. These APIs give every suppon needed for writing XML based Web service client applications. The XML Digital Signatures API allows you to secure Java-based Web services by performing cryptographic operations on XML data. The Java-XML Web Service (JAX-WS) 2.0Chapter 1: Getting Started with Java SE 6 API updates the library named as JAX-RPC. Improvements to Java-XML Binding (JAXB) 2.0 include XML schema support and class binding to a schema, Lastly, the Streaming API for XML (STaX) provides a bi-directional API to read and write XML via a stream of events, including the ability to skip sections, and focus on subsections of documents. Security In Java SE 6, a new API called XML-Digital Signature has been introduced to improve the security. This API is used to create and modify digital signatures. It has now became possible to design security policies more quickly, as it has provided new ways to access security services. Java SE 6 includes Java Generic Security Services (GSS) and Kerberos services, Java Authentication and Authorization Service AAS) for authentication and access to LDAP servers for user authentication. To understand these features more clearly, we will have to create programs showing their implementation. To create any Java program, the Java class libraries need to be available on the local computer system. These libraries are available in a free package called the Java Software Development Kit (SDK). Let’s now take a look on how to download and install this software package. Getting and Installing Java 1. To download Java SDK Standard Edition 1.6, visit Sun Microsystems’s website at http: //java.sun.com/javase/downloads/index. jsp. 2. After downloading the SDK, run the downloaded SDK executable file. The welcome window as shown in Fig.Java-1.1 appears. FigJava-Ll The welcome window disappears in few moments and a dialog box showing the license agreement appears (Fig.Java-1.2).Java 6 in Simple Steps 3. Now, click the Accept button (Fig.Java-1.2) on license agreement to continue the installation process. The installer’s Custom Setup dialog box appears, as shown in Fig.Java-1.3. Fig.Java-L2 4. Now, Choose a list of components (Fig.Java-1.3) that may be installed. Continuing with the Development Tools component, which is selected by default, is sufficient to get started with Java programming. FigJava-13 Either accept the default installation path or select a location where the Java files are to be installed by clicking on the Change button.Chapter 1: Getting Started with java SE 6 5. Now, click the Next button to start the installation, as shown in Fig.Java-1.3. The progress window appears (Fig.Java-1.4). FigJava-L4 When the progress completes Installing window disappears, Custom Setup dialog box for Java runtime environment appears as shown in Fig Java-1.5. 6. Now, click the Next button (Fig.Java-1.5) to continue the installation process. Fig.Java-1.5 The Java runtime environment progress window appears as shown in Fig Java-1.6.Java 6 it Simple Steps Fig Java-1.6 When the progress completes Installing window disappears and a window as shown in Fig.Java-1.7 appears informing you that the installation is completed. 7. Now, click the Finish button on the Wizard Completed dialog box, as shown in Fig.Java-1.7 to exit from the installation wizard. Fig Java-L.7 This is how to install the Java on your system. Now, you can take the advantage of the tools used for compiling and running a Java program (javac and java). The tools used for compiling and running are located in the ‘bin’ folder of the Java installation directory and these tools are normally operated from a Command Prompt. These tools can however be made available from anywhere on the computer by adding their location to the system path, as shown in the following steps: 1. Select Start>Control Panel>System. The System Properties dialog box appears, as shawn in Fig.Java-1.4.Chapter 1: Getting Started with Java SE 6 2. Now, click the Advanced tab, as shown in the Fig.Java-1.8. A System Properties dialog box appears displaying some advance options including the Environment Variables. Fig.Java-L8 3. Now, click the Environment Variables button, as shown in Fig.Java-1.8. The Environment Variables dialog box appears, as shown in Fig.Java-1.9. 4. Now, selectthe Path Variable given in the System variables, as shown in Fig.java-1.9. FigJava-L9 5. Now, click the Edit button to add the path of the Java bin directory to the end of the list in the Variable value field as shown in Fig.Java-1.9.Java 6 in Simple Steps Fig.Java-1.10 6. Now, click the OK button to close the Edit System Variable dialog box as shown in Fig Java-1.10. And finally click on OK button in Environment Variables dialog box. 7. Now, to test that the Java tools can be accessed globally, type java version at the Command Prompt window, as shown in Fig. Java-1.11. FigJava-1.11 The output shows that Java has responded correctly to the java-version command, thereby making the Java tools globally accessible. Now, we can continue working with Java. Let's write a Java program. A Simple Java Program Let's now create a simple Java program using text editor called Notepad. First of all, put some Java code into the editer such as Notepad to create our first Java program, as shown in the following code snippet: In the abave code snippet, the Cass neywuru is used 1 ueLiale a class called HelloWorld. HelloWorld is used as an identifier, which is used to give an appropriate name to a Let’s take a look at the follawing line: 10Chapter 1: Getting Started with Java SE 6 This is the line at which the program begins executing. It is by calling this main() method that all Java programs begin their execution. The line begins with public keyword which is an access specifier, making the main () method accessible outside the class in which it is deelared. Static keyword allows main() to exist before creating abject of the class in which the main method is declared. void keyword specify that the main () does not return any value. Now, save the file as Hel loWorld. java to a desired location on your system. Java programs are saved with the file extension ‘java’. It is to be noted that in Java, name of the file should match with name of the class. Java is a case- sensitive language, that is the word ‘hello’ and ‘Hello’ have two different meanings in Java. Once a Java program is written, its time to compile and then run it to show the desired output. Compiling and Running the Program To run a Java program, it is necessary to compile it first using Java compiler, This Java compiler is an application named javac.exe located in the java directory bin folder. To compile a program, type javac followed by a space and then the name of the file to be compiled, as shown in Fig.Java-1.12. Fig.Java-1.12 The errors may occur during compilation due to the following reasons: Q Incorrect syntax Q Inability of compiler to find the source file Q Incorrect file name Once the source file gets compiled, a new file with the same name as that of the source file followed by an extension ‘.class’ gets created. Now, its time to run this .class file. To do so, SDK provides tool called java.exe, which is an application used to run Java programs. To run the program, type java followed by name of the .class file and press enter to show the output, as shown in Fig.Java-1.13. Fig.Javacl.13 ctJava 6 in Sinnple Steps With this, we have also reached the end of this chapter, Before closing this chapter, let's have a look at the topics covered in this chapter. Summary In this chapter, we learned about: a a a a Origin and development of Java language. Core features intraduced with Java SE 6. Downloading and installing SDK 6. Creating, compiling, and running a Java program. 12Urheberrechtiich geschdtztes Bild Urheberrechtlich geschitztes Materialjava 6 in Simple Steps Java program, similar to programs in other programming languages, uses variables, data’ types, operators, and arrays to execute the program logic. A variable is the basic entity of a program, and can be defined as an arbitrary placeholder for storing data. The data to be stored in a variable must be assigned a data type, which specifies the type of data that the variable can store. For example, a variable of the int data type can store integer values. Operators areused to perform operations on variables to execute the program logic. For example, the + operator is used to perform additions of two or mare variables of the int data type. An array is a collection of data storage locations that store variables of similar data types. You can use arrays in large programs to prevent declaring large number of variables and reducing the effort required to write a program. In this chapter, we learn how to declare a variable in a Java program. We also explore various kinds of data types and operators available in Java. In addition, we learn about one dimensional and two dimensional array types. Declaring a Variable Java provides us containers or placeholders to store data within a program. These containers are called variables since the value stored in them can be changed during the course of execution of @ program. To define a variable in a Java program, you need to use the combination of a data type and an identifier. An identifier should be a logical name representing a variable, constant, or method, Following code snippet shows how to declare a variable: datatype ‘identifier;// declaring variable In the preceding syntax, Q dataType: It specifies a valid Java's data type, such as int, char, and so on. Q identifier: t can be any name that follows some specified naming conventions. Naming conventions are discussed later in this topic. After declaring the variable, let's now see how to initialize it, identifier = val;// declaring variable a The ‘val’ in the preceding syntax represents the value that is used to initialize the variable and it should be according to the datatype used with the variable. It is not only that you first have to declare a variable and then initialize it. You can also initialize the variable at the time of declaration. Now, see the folowing syntax to initialize the variable at the time of declaration: datatype vardablename’= val j//"deelaring: variable Net Data types are discussed in detail in this chapter under the section Understanding Data Types. A As we know, the name given to a variable is known as an identifier, which should reflect the contents. contained inside the variable. An identifier must take care af the following rules specified in Java: 14Chapter 2: Exploring Variables, Data Types, Operators, and Arrays An identifier must stant with an underscore, a letter, or a dollar sign ($). An identifier may consist of a letter, a number, an underscore, and dollar sign. Spaces are not allowed in between an identifier. identifiers are case sensitive that means the words salary, Salary, and SALARY are taken as three different identifiers. @ Java keywords should not be used while naming an identifier since they hold some special meaning in Java. Table2.1 shows a list of Java keywords that have special meaning in java. coca abstract ‘throw poblic instancoot else ne ‘void strictfp native ‘float for if While declaring a variable, appropriate datatype must also be associated with it. Let's now have a look at different datatypes used in Java. PPRLERPCTLTE TEEECHELE'Y [presen tel] Understanding Data Types Data types are very important in java as you cannot even declare a variable without specify’ data type. In Java, the data types can be divided imo three broad categories: Integer: Represents integers using byte, short, int, and long. @ Character: Represents char, which is used to store characters, such as letters and numbers. Floating point: Represents fractional numbers using float and double data types. 9 Boolean: Represents logical values using boolean data type. 15Java 6 in Simple Steps Jnteger Types Java provides four integer types — byte, short, int, and long. As Java only supports the signed integers, these integers types have -ve and +ve values. Among all, the byte is the smallest integer type while the long is the largest integer type. Table 2.2 lists the width and range of the Data Type Representation Width (bytes) Range byte - 1 : +1280 127 short 2 32, 168 to 32, 767 int a $ + =2,187,483,648 wo 2, 147,403,688 Let's see some examples of integer types. Here, ‘x’, ‘sum’, and ‘age" are variables having the int datatype. Character This datatype follows the Unicode character set to represent the characters that can be uniquely identified by the processor. Unicode is a standard character set that supports all the international characters of various languages, such as American, Latin, and so on. Table 2.3 lists the range of character datatype. | = char! 2 : eto 65895 Let's see the falowing statement to use char with variables: char-ch-=-‘aty In the preceding syntax, a variable ch is declared and initialized with ‘a’, Remember to enclose any character within single quotes while initializing it. Floating point types ‘We already know that Floating point numbers are represented by float and double data types. These are used to represent numbers along with decimal values. Difference in float and double is 16Chapter 2: Exploring Variables, Data Types, Operators, and Arrays that float can represent a maximum of 7 digits after decimal while double can represent 15 digits. Let's have a look at Table 2.4 where characteristics (such as datatype representation, width) of float and double are summarized. Let's see the folowing statement to know how to use floating point types while declaring, variables: ‘Float x=35458; In the preceding syntax, a variable *x’ is declared and initialized that has float datatype. In the same way, you can use dauble datatypes with variables. Boolean Type The boolean data type represents two logical values denoted by true or false. Let's see the folowing syntax to use boolean datatype: oboolean’x'= true; In the preceding syntax, a varible ‘x’ of type boolean is declared and initialized as true. You can also initialize it with false. We have seen all the data types that are available with Java. Now to perform manipulation on the data stored in the variables, we need operators. These operators perform manipulation on the operands (variables). So let's now discuss the operators available in Java. Understanding Operators While creating a program, a programmer may need to do some operations, such as addition, multiplication on the declared variables to perform some specific functioning. These operations can be done with the help of operators. An operator is just a symbol, such as *+" that acts on some variable (operands). Following are the operators that we are going to study in this section: Q Arithmetic operators Q Increment and Decrement operators Q_ Bitwise operators Q_ Relational operators 17Java &in Simple Steps 2 Boolean operators 9 Boolean Logical operators GQ f:operator Using Arithmetic Operators ‘These operators are used to perform mathematical calcualtions on the operands of numeric types. These operators are also called as binary operators as these operators work on two operands, Arithmetic operators availble in Java are listed in Table 2.5. ats nical hae eras ele ht nian preemie Listing 2.1. Listing 2.1: Arithmetie.javaListing 2.1 demonstrates the implementation of some of the commonly used arithmetic operators. Here ‘+" operator is serving two purposes. One is addition of two numeric operands and giving back a numeric output. Another purpose is that it joins together two string values and returns a concatenated string as an output. The ‘~' operator shown in the example is used to perform the subtraction using two given numbers and return their difference. The ‘** operator is used to return the product of two numbers as an output. The modulus ‘operator ‘%’ is used to divide the first number by the second number and returns the remainder as an output. Tr arns the quotient as output, Thi Jacrement and Decrement Operators The increment (++) and the decrement (--) operators perform manipulation on a single operand and hence they are known as unary operators. Increment operator increases the value of an operand by one whereas decrement operator decreases the value of an operand by one. These operators appear in two forms— postfix and prefix. The interesting thing to note is that these forms increment or decrement the appropriate variable, but they do so at different times. The statement ++i (prefix form) increments i before using its value, while i++ (postfix form) increments it after its value has been used. Similarly, --i decreases ‘i* before using its value, while i- - decreases it once its value has been used. The difference between prefix form of increment and decrement operators can be made clear with the help of an example. Let's take a look at Listing 2.2 to understand prefix form of increment and decrement operators. Lisitng 2.2: Using Increment and Decrement operators 19Java 6 in Simple Steps In Listing 2.2, ‘y’ is set to an incremented value of ‘x* since in the prefix form of increment should occur before ‘x’ is assigned to ‘y’. In the same way, ‘b’ is set to be decremented the value of ‘a* before ‘a’ is assigned to ‘b’. The output of the given example can be seen in FigJava-2.2 Fig Java-22 In FigJava-2.2, the value of ‘x' is set to 2 as it went through an increment. The value of *y" however is set to 2 since the increment occurs before ‘x’ is assigned to ‘y’. In the same way, the value of ‘a’ is set to 1 because of the decrement done on it. The value of ‘b’ is also set to 1 because the decrement occured before ‘a’ is assigned to *b’. Using Bitwise Operators These operators perform on the individual bits (0 and 1) of their operands. They can be applied only on integer types that is long , int, short, and byte. Bitwise operators should be used where memory savings are needed, such as for system programming. Some of the useful Bitwise Operators are shown in Table2.6.Chapter 2: Exploring Variables, Duta Types, Operators, and Arrays Let's now discuss the operators listed in Table2.1. The AND Operator This operator produces ‘1” bit in case the corresponding bits in both the operands are ‘1’; otherwise, it produces zero, as shown in Table 2.7. AGB A B o o o a 0 o 9 1 Q 1 1 1 The OR Operator This operator produces *1" if ane or both of the corresponding bits in its operands are ‘1°, and produces ‘0’ if both of the corresponding bits are ‘O°. In other words, OR “I operator returns one in all cases except in a situation where the corresponding bits of both operands are zero, as shown in Table 2.8. A B A 0 0 0 1 0 1 o 1 1 1 1 1 The Exclusive OR Operator This operator produces ‘1’ where the corresponding bits in its operands are different and produces ‘0" if they are the same as shown in Table 2.9. AB A 8 o o o 1 | 1 0 { 1 1 { 0Java 6 in Simple Steps Let’s now discuss shift operators. Before that, we must understand what exactly does shifting mean. Shifting means moving bits left or right depending upon the kind of shift operator used. Here, one bit maves forward making space for the next bit to take its place. The Right Shift Operator This operator *>>" shifis the bits to the right by a specified number of positions. The number of positions upto which the shifting should occur depends on the value given afier the operator. When shifting right ‘>>*, the lost bits are filled in with previous leftmost bits. To understand right shift operator more clearly, let’s see an example: Consider 78 whose binary equivalent is: 00000000 00000000 oo000000 01001110 By shifting it right >>" 2 times , the output we get is: 20000000. 00000000 doon0000 G0010011 ¢ = 19 The Left Shift Operator This operator shifts the bits to the left by a specified number of positions. When you shift leit *<<*, the void left behind by the shift is filled by zeros and the lost bits are filled in with previous rightmost bits. To understand the left shift operator mare clearly, let’s see an example: Consider 78 again whose binary equivalent is: ‘op900000'.00000000- G9000000: 01001110 By shifting it left “<<* 3 times , the output we get is: ‘90000000:-00900000''00000010 01210000 )(:= 624.) Using Relational Operators The relational operators compare two operands and draws relationship between them, such as whether the two operands are equal to each other or not. The outcome of these operators is a boolean value that is true or false. These operators are most often used in conditional statements and the loop statements. The canditional statements and the loop statements. are discussed in chapter 3. Now, see Table 2.10 whish shows the various relational operators.Chapter 2: Exploring Variables, Data Types, Operators, and Arrays Using the Boolean Operator The operators that act on the Boolean variables are called Boolean operators. They produce the result in the form of ‘true’ or ‘false’, Let’s see Table 2.11 in which the Boolean operators are summarized. The || operator returns true if any of the operand is true. The *&" operator returns true if bath the operands are true, else it returns false; whereas, the *!" operator is used to convert the true value to false and false to true. Let's suppose, you have declared two variable ‘x’ and *y’. Then ‘x’ is initialized as true while ‘y’ as false. Now to convert ‘x’ to false the *!' can be used as follows: RE REA TE Now, it will return a false value. Using the Boolean Logical Operator These operators also operates only on the boolean operands and are used with compound conditions. For example, suppose you initialize three variables with value ‘2’ and then want to check whether those variables are initialized with the same values that is *2” or not then you can use ‘Boolean logical operators’. Table 2.12 lists the important Boolean Logical operators.Java 6 in Simple Steps These operators somewhat look similar to the Bitwise logical operators discussed under the topic “Using Bitwise operators’ in this chapter. The major difference between these two operators is that the ‘Boolean logical operators’ operate on integers whereas ‘Bitwise logical operators‘ operate on the Boolean operands. Java provides two Boolean logical operators (short-circuit operators)— &&(short-circuit AND) and I (short-circuit OR). The && is very useful in cases where a value has to be checked for two facts as shown in Listing 2.3, where one has to test whether a value holds 0 and whether its reciprocal is less than 1000, If the value is indeed 0, the second part of the expression, where its reciprocal is calculated, is not executed. This way, a divide-by-zero overflow error does not occur, as shown in Listing 2.3. Listing 2.3: shortCircuit java In Listing 2.3 , the variable ‘value’ is checked against two conditions—one if it is not zero and another if its reciprocal is less than 1000. Since the value stored in the variable ‘value’ is zero, which is false; the second part of expression will not get executed and the output is displayed, as shown in Fig.Java-2.3. rig java-z9, Let’s now understand another interesting operator that works somewhat similar like if-then-else statements. This operator is ?: operator. 24Chapter 2: Exploring Variables, Data Types, Operators, and Arrays Using the ?: Operator There is a special kind of operator that can replace certain types of if-then-else statements. The if- then-else is a conditional statement, which is used to evaluate an expression for boolean value. We will study more about conditional statements in Chapter 3 of this book. The general syntax for using ?: operator is as follows: Expression1? Expression2: Expression3 Here, expression! can be any expression that evaluates to a boolean value. In case it comes out to be true, then expression2 is evaluated; otherwise, expression3 is evaluated. To understand this operator more clearly, let’s see the example shown in Listing 2.4. Listing 2.4: Conditional. java gets converted into Integer using a method called Integer.parseint(). This converted value is then used to check whether its an odd or an even number using ? operator. It works similar as that of if-then-else statement where first the variable is checked against a condition, In case the condition is true, the statement after ? gets executed; otherwise, the statement at the end gets executed. The output of the program shown in Listing 2.4 can be seen in Fig. Java-2.4. 25Java 6 in Simple Steps Fig.Java-24 The use of ? operator is shown in Fig.Java-2.4. Here, first of all a number is entered by a user. This number is checked against a condition to check whether its an even number or an add. If the condition is true, then lines stating that its an even number get displayed on the screen. This is all about operators. Let's now begin with another topic called Arrays. Unlike a regular variable that contains only a single value, array is a special variable that can hold multiple values of the same data type. These values are stored as elements of an array. The values in an array are stored at a specific location called index. The starting index in an array is zero. One can refer to these individual elements stored in the array using their respective index numbers. Working with Arrays An array is a collection of data storage locations, each of which holds the same type of data. But the question is why we need this kind of a complex structure? There can be a situation where you need to store similar type of values for a large number of data items. Simple types are fine as long as they are used for storing single data, but what if the data to be stored is more complex. For example, you want to store names of 50 students. One approach is to declare 50 variables each storing names in them, which is not a correct approach. Imagine writing 50 statements just to store the names of students. There is a solution to this problem in the form of arrays. With arrays, we can declare a single variable that is capable of storing all these 50 names. The advantage of using arrays is that they simplify programming by replacing a lot of statements by just one or two statements. In Java, arrays are created on dynamic memory that is allotted at runtime by JVM. Arrays are generally categorized in the following two parts: One Dimensional Arrays Q Two Dimensional Arrays. Using One Dimensional Array ‘One dimensional array is the array with only one index associated with it. It is a collection of data storage locations, each of which holds the same type of data. The number of indexes associated with any array is its dimension. To create a one dimensional array, declare the array and allocate some memory to it by using new operator. Follawing statement shows how to declare 'aone dimensional anay: String Books_category[]; //declare Books_category array of. string type: 26Chapter 2: Exploring Variables, Data Types, Operators, and Arrays In the preceding statement, String determines the data type of each element of the array. The syntax here specifies ‘Books_category’ as the name of one-dimensional array. Declaring an array does not ensure its successful creation, So, once you have declared a one- dimensional array, the next step is to actually create that array by allocating memory to it. Now, consider the following statement to allocate memory to an array: Books_categoryenew String[5];// allots memory for storing 5 elements In the preceding statement, some memory is allocated to ‘Books_category" by using the new operator. We can however combine declaration and memory allocation statements into a single statement as well. You can combine declaration and memory in one step as follows: String Book_category[]=new String[5]; Here, JVM allots memory for storing 5 string elements in elements stored in the array so far. Let's now see how to ini Initializing an Array ing an array means storing some value at a specific index in the array. For example, ion’ at 0" index in array Books_category means, the 0™ position is initialized by iction’. To store the elements into the array, one can use the following statements: the array. But there are no actual ize an array. You can also store elements in a one dimensional array directly at the time of declaration as follows: String Books category[]= {"Fiction", "Autobiography", "Children" ."Travel”, “Cookery”: So far, we have learned about declaring, allocating memory, and initializing an array. Let's now see an example showing the implementation of one-dimensional array in Listing 2.5. Listing 2.5: ArrayExample! java 27Java 6 in Simple Steps In Listing 2.5, a one-dimensional array of string type called ‘Books _category" is declared to group simple data types into a more complex structure using a single index|]. The array is then initialized with five string values. These values are accessed using for loop where each value stored in the array is accessed using their respective index numbers and are displayed one by cone, as shown in Fig.Java-2.5. Fig.Java-25 This is all about one-dimensional array. Now, we study about two-dimensional array. Using Two Dimensional Array So far, we have seen only one dimensional arrays where only a single value can be allocated but there can be a case when more values are needed to represent elements of an array. In that case, two dimensional array can be used to represent the data. A two dimensional array is also known as array of arrays. It is declared with anather set of square brackets representing index, as shown in Listing 2.6. Listing 2.6: TwoD.javaz Variables, Data and 2.6, first ten even are displayed using a two dimensional array called arr of Integer type. This array type is with two rows and five columns. In two arrays, the left index specifies the in the array, and the right index specifies the column. output of Listing 2.6 is shown in 2.6, So far, we have leamed the of using arrays but consider a situation when you need to pass in many instances of the object type to a method, but you do not know at compile time how many instances there _be. The only way to handle this situation was to bundle these objects in an array but with 5.0, a convenient new feature has been added that lets a method to take zero or more of a given data type. This new feature is called Varargs that stands for variable length Using the Varargs Feature ‘Varargs is a feature that allows a to accept more than one arguments as parameters. This feature makes it easier to create methods whose argument list widely varies. To understand Varargs clearly, take a look at an shown in Listing 2.7. Listing 2.7: VarargsExample.javaJava 6 in Simple Steps In Listing 2.7, the method displayNames () takes an unspecified number of string objects as input. This is indicated by the use of ellipses in the parameter declaration String... names. A method can have at most one parameter that is Varargs, but it must be the last parameter taken by the method. In Listing 2.7, the overloading feature of Varargs is shown. This overloading feature allows displayNames () method to perform a similar operation with varied signatures, as shown in Fig.Java-2,7, Fig.Java-2.7 Overloading requires methods with distinct signatures. The signature of a method includes its name and the ordered list of its argument types. All other items appearing in a method header, such as exceptions, return type, final, and synchronized do not contribute to a method's signature. With this, we have reached the end of this chapter. Before closing the chapter, let’s have a look at all that we have covered in this chapter. Summary In this chapter, we have studied about: Q Variables in Java Q Primitive data types available in Java OQ Operators available in Java to perform manipulation on the data OQ Arrays including one-dimensional and two-dimensional types with the concept of Varargs.Urheberrechtlich geschitztes Bild Urheberrechtlich geschiitztes MaterialJava 6 in Simple Steps I a Java program, sometimes to achieve certain results, some specific operations need to be performed repeatedly. The execution of these operations are based upon the fulfillment of certain conditions. These conditions are placed in various control flow statements, such as conditional statements, iteration statements, and jump statements. The operation to be performed is provided in the block of control flow statements. A conditional statement is a control statement that allows choosing between two or more execution paths in a program. lteration statements repeatedly execute the code block on the basis of the conditional statement. Once the conditional statement evaluates to false, the loop exits. After that, the control transfers to the next statement that follows the loop. Jump statements explicitly redirect the flow of program execution. In this chapter, we study all these types of control flow statements in detail. Implementing Conditional Statements Conditional statements, as the name itself suggests, cause a program to execute a block of code on evaluating a conditional expression. if the conditional expression comes out to be true, the accompanying block of code is executed and if it is false, the accompanying block of code is bypassed. Following are the conditional statements that we are going to study in this section: O if statement if-else statement switch statement Using If statement The If statement is a conditional construct that is used to evaluate an expression for a boolean value. In case the expression returns true, the statements following the conditional expression will be executed but in case it returns false, the cade following the conditional expression would not be executed and the program would just move along to the next statement. Here is a general syntax for if statement: if (conditional expression)
; Let’s see Listing 3.1 to understand the use of if statement. Listing 3.1: Ifexample.java In Listing 3.1, If statement is used to test a condition that is whether age specified in the program is less than 18 or not. The value for age variable is set to 16 in the program. Since 16 is less than 32Chapter 3: Controlling Program Flow 18, the condition set in the if statement becomes automatically true. The statement following the condition therefore gets displayed, as shown in Fig.Java-3.1 Fig Java-3.1 Let’s naw take a look on if-else conditional construct next, Using if-else statement The if-else statement is used in situations where we can provide an alternative course of action, in case the if clause returns false. For example, when the conditional expression for the if clause evaluates to false, the statements coded in else clause gets executed. Here's a general syntax for ‘if-else’ statement: Here, the condition is written inside the small brackets (). According to the preceding code snippet, if the condition specified after *i £* is true, then statement! is executed; else, statement2 is executed. Let’s understand the use of if-else statement with the help of an example shown in Listing 3.2. Listing 3.2: IfElseExample.java In Listing 3.2, the ‘I£" statement is used to test a condition that whether value stored in variable ‘a’ is greater than the value stored in variable *b’ or nat. Since the value stored in variable ‘a’ is set to 10 and that of ‘b* to 20, the condition automatically evaluates to false and the statement 33Jatva 6 in Simple Steps immediately following the condition does not get executed. It is the statement after the else construct which gets executed, as shawn in Fig.Java-3.2. Fig.Java-3.2 Let's now discuss another type of conditional statement known as switch statement that lets you execute one option from various options. Using switch statement When there are several options and we have to choose only one option from them, we can use switch statement. Depending on the selected option, a particular task is performed. Task here Tepresents one or more statements. Here is the general syntax for using switch statement: Here, depending on the value of the variable, a particular task (statements) is executed. if the variable value is equal to value1, statements! will be executed. If the variable value is value2, statements2 will be executed, and so on. If the variable value does not equal to valuel, value2, ... then none of the statements will be executed. In that case, control comes to the default clause and the set of default_statements gets executed. In the preceding code snippet the default statment is enclosed in square bracket, [ ] because it is optional. However, it should be remembered that we cannot use all data types with switch statement. We can use char, int, byte, and short types only. Let’s understand the implementation of the switch statement with the help of an example shown in Listing 3.3. Listing 3.3: SwitchExample javaChapter 3: Controtling Program Flow In Listing 3.3, a variable of char type named country is declared and is initialized to *i*. nding on the value stored in the variable country, America is displayed when the value is ‘a’; Canada is displayed when the value is ‘c"; India is displayed when the value is *i"; and England is displayed when the value is ¢. If the value of a country is neither of the specified values—‘a’, ‘c’, *i’, or ‘e’, then none of the statements is executed. Fig.Java-3.3. shows the output of Listing 3.3. Fig.Java-3.3 The output shown in Fig.Java-3.3 is not as expected. We expected that it would display India, but it is displaying every statement from India onwards. The question here is what could possibly be ‘the reason? The value of variable country is set to “i", so India should get displayed but we found that it has executed the rest of the statements following India. The reason for this problem is that once India is displayed, the control should come aut of the switch statement but it is not able to do so. For this purpose, break statement should be used in the program (Listing 3.3), which allows the program to come out of the switch statement after displaying India, as shown in Listing 3.4. Listing 3.4: SwitchExample1.java 35Java 6 in Simple Steps In Listing 3.4, i” becomes true and hence, JVM displays India as shown in Fig.Java-3.4 and then executes break, which terminates the switch block. So far, we have learned various conditional statements. Let’s now take a look on another ‘category of contral flow statements used to execute a block of statements repeatedly. These types ‘of control flow statements are known as Iteration statements. Implementing Iteration Statements Repeating the same code fragment several times is called iterating. The basic logic behind iteration is that a sequence of statements is repeated until a certain condition is met. When this condition is false, the iteration terminates, and the loop is completed. There are various types of iteration statements available in Java. The iteration statements are also known as loops in Java. Following are the iteration statements that we are gaing to study in this section: while loop 2 do-while loop Q for loop a a for each loop Nested loop Using while Loop The function of the while loop is to execute a specific block of statements until a condition evaluates to true. Once the condition becomes false, the loop gets terminated. Here is a general syntax for using while loop: 36Chapter 3: Controlling Program Flow In the preceding syntax, the condition is first tested. If the condition is true, the statements following it will go on executing repeatedly till it continues to be true, Once the condition becomes false, the loop terminates. The statement block must contain the code that should make the evaluation result to return false; otherwise, an infinite loop is created. Let's understand the use of while loop with the help of an example shown in Listing 3.5. Listing 3.5: WhileExample.java In Listing 3.5, first ten odd numbers are displayed using while loop. Firstly, variable ‘i’ is set to 1. To display odd numbers, ‘i' gets incremented by 2 on each iteration. When the evaluation becomes false, that is once the value of ‘i” exceeds 20, the loop terminates, as shown in Fig.Java-3.5. hig.Java-3.5 Let's now take a look on another loop called do-while loop which is almost like a while loop but with a slight difference. Unlike while loop, the statement code will always be executed at least once by the do-while loop as the conditional expression is evaluated at the end of the loop. Using do-while Loop The do-while loop performs like a while loop where a group of statements is executed as long as the condition is true. If the condition becomes false, the flow of execution comes out of the do- while loop. Here's a general syntax for using while loop: WrJava 6 in Simple Steps In the preceding syntax, the statement code is followed by the while keyword and a test expression, In case the evaluation returns true, the control goes back to the do keyword and continues until the evaluation becomes false. Let’s understand the use of do-while loap with the help of an example shown in Listing 3.6. Listing 3.6: DoWhileExample,java In Listing 3.6, first ten odd numbers are displayed using do-while loop in the same way as that of while loop. There is however no difference in the results shown by both the while and do-while loop. The difference, hawever, comes in the manner in which they are implemented. Here, in Listing 3.6 the value of ‘i” gets displayed before evaluating the conditional expression unlike while loop where the condition is checked first and only then the statements are processed further. Firstly, variable i is set to 1. To display odd numbers, i gets incremented by 2 on each iteration. The loop gets terminated when the evaluation becomes false, that is once the value of i exceeds 20, as shown in Fig.Java-3.6, FigJava-3.6 After having learned the basic difference between while and do-while loop, let's now discuss yet another type of iteration statement called for loop.Chapter 3: Controlling Program Flow Using for Loop The for loop is also like a while loop, but is syntactically more compact. The for loop executes a group of statements as long as a condition is true. Here is a general syntax of a for loop: In the preceding syntax, initializer is used to set the initial value for the counter to control the iteration. Far this purpose, a variable may be declared. A boolean condition is evaluated at each pass of the laop to check whether the loop will continue to run or not. In case the condition evaluates to true, the loop will continue; otherwise, it will terminate. Let's understand the use of for loop with the help of an example shown in Listing 3.7. Listing 3.7: ForLoopExample.java In Listing 3.7, the first ten add numbers are displayed with the help of for loop. Firstly, variable 4 is set to 1. To display odd numbers, i gets incremented by 2 on each iteration. The evaluation becomes false once the value of i exceeds 20 and the loop terminates, as shown in Fig Java-3.7. rigyavacsy The next type of iteration statement that we are going to discuss is for-each loop. This loop executes statements for each element of the collection. 39Java 6 in Simple Steps Using for-each Loop The for-each loop is specifically designed to handle the elements of a collection. A collection is represented by a group of elements. Array is an example of collection since it stores a group of elements, such as integer values or strings. Similarly, the classes of java.util package are developed to handle a group of objects. The for-each loap repeatedly executes a group of statements for each element of the collection. It executes as many times as there are number of elements in the collection. The general syntax for using for-each loop is as follows: In the preceding syntax, ‘var’ represents each element of the collection one by one. For instance, there is a collection of 5 elerfents then this loop will execute 5 times and the ‘var’ will represent these elements one by one. Let's understand the use of for-each loop with the help of an example shown in Listing 3.8, Listing 3.8: ForEachExample.java In Listing 3.8, the for-each loop is used to display each element of an array. Here, there is a collection of array type containing ten elements. The foreach loop will execute 10 times.and i will represent these elements thereby executing statements for each of these elements, as shown in Fig,Java-3.6. FigJava-3.8Chapter 3: Controlling Program Flow The next type of iteration statement that we are going to discuss is nested statements. Working with Nested Loop It is possible to nest conditional statements as well as iteration statements in Java. Nested statements can be conditional statements within another conditional statements (nested if statements) or it can also be iteration statements containing other iteration statements (nested for loop). A nested for loop is a for loop within another for loop. Here, execution starts from the outer for loop and the control then passes to the inner for loop. The inner for loop continues to execute till the condition evaluates to true. Once the inner loop is completed, the flow of execution is passed to outer loop for the next iteration and executes till the evaluation returns true. Let’s understand the use of nested for loop with the help of an example shown in Listing 3.9. Listing 3.9: NestedLoopExample.java In Listing 3.9, executions in with an outer for loop in which num2 is initialized to 0, Now, the: execution enters into the inner for loop where num! is set to 0. The inner for loop continues to execute until the condition becomes false. In this way, the inner loop is executed three times, with num! changing its value from 0 to 2. (Once the inner for loop is completed, then the execution goes to the outer for loop and num2 is set to 1. This time, the execution again comes into the inner for loop and the statements following this loop will execute again for three times. Again, the control goes back to the outer for loop and num2 is set to 2. The outer loop executes till its value exceeds 3. In this way, the outer loop executes for 4 times. In Listing 3.9, the outer for loop is executed 4 times and the inner for loop is executed about 3 times for each value of num2 and hence inner loop is executed 12 times in total, as shown in Fig.Java-3.9. 41Jaon 6 in Simple Steps FigJjava-3.9 Implementation of nested for loops is shown in Fig.Java-3.9. Here, a for loop is used within another for loop. The outer for loop is first executed. Variable for controlling the iteration for this loop is num2, which is set to an initial value of 0. The control soon goes to the inner for loop where num is set to 0. This loop executes till the value of numi exceeds 2. In that case, the inner loop executes 3 times with value of num2 set to 0 and that of numl as 0, 1, and 2 respectively in all the three executions. The flow of execution is then passed back to the outer loop where the value of num2 is now set to 1 after undergoing increment. Again, the control is passed to the inner loop and it will execute for 3 times with the value of num2 set to 1 and that of num1 as 0, 1, and 2 respectively. The outer loop continues to execute until the value of num2 exceeds 3 and the condition becomes false. In that case, the outer loop continues to execute as long as the value of num2 is equal to 3. So far, we have discussed about control flow statements, such as conditional statements and lteration statements. In the next section, we study another kind of control flow statements known as Jump statements. Implementing Jump Statements : Jump statements are the statements that transfer control from one part of the program to another. The jump statements supported by Java are as follows: a break Q continue O return Using break statement One of the important purpose of break statement is to exit from switch statement. At times, we need to break out of a loop before the whole thing gets executed. The break statement allows us to get out of a loop even before it is completely executed. This statement is written in the form of a simple break keyword followed by a semicolon. Let's understand the use of break statement with the help of an example shown ii iChapter 3: Controlting Program Flaw Listing 3.10: BreakExample.java In Listing 3.10, an infinite loop is shown to display even numbers up to infinity. In order to avoid this situation, a break statement is used within a condition stating that if the value of i variable exceeds 10, then the control comes out of the while loop. If the control comes out of the loop, then the first 5 even numbers are displayed, as shown in Fig.Java-3.10. Fig.Java-3.10 The break statement can also be used as an alternative to the goto statement. Java does not support goto statements directly but indirectly the same can be implemented with the help of a break keyword followed by a label. The break statement, without a label, transfers control out of the nearest enclosing for, while, do, or switch statement. If the break keyword is followed by a label of an enclosing statement, execution transfers out of that enclosing statement. Let's understand the use of a labeled break statement with the help of an example shown in Listing 3.11. Listing 3.11:Java 6:in Simple Steps In Listing 3.11, an infinite loop is shown to display odd numbers up to infinity. In order to avoid this situation, a labeled break statement is used within a condition stating that if the value of i variable exceeds 10, the control comes out of the while loop and only first 5 odd numbers will get displayed, as shown in Fig.java-3.11. Using continue statement Now, we know that a break statement causes a loop to exit. A continue statement, however, causes the current loop to quit iteration and begin executing the next loop. When continue is used without a label, it causes the innermost loop to start a new iteration. When used with a label, which represents name of the containing loop, it causes the named loop to start a new iteration, Let’s understand the use af continue statement with the help of an example shown in Listing 3.12. Listing 3.12: ContinueExample.javaChapter 3: Controlling Program Flow In Listing 3.12, first ten even numbers are shown excluding 12 from the result. This is done with the help of continue statement inside an if condition, which gets executed in case the value of i variable becomes 12. Here, even numbers are shown successfully until the value of i becomes 12. When the value of i becomes 12, the control of execution quits from the current loop and retums back to the for-loop. The next iteration then begins to display the remaining even numbers till the value of i exceeds 20, as shown in Fig-Java-3.12. Fig.Java-3.12 That was all about continue statement. Let's now discuss about another kind of jump statement available in Java called return statement. Using return Statement This statement causes the control of execution to return back to the caller of the method, With this, the control explicitly returns back to the caller of the method. Let’s understand the use of ‘continue statement with the help of an example shown in Listing 3.13. Listing 3.13: ReturnExample.javaJava 6 in Simple Steps In Listing 3.13, a method square () accepts an integer value, calculates its square value, and returns that value to the main () which is its calling method. In the main method, we are calling square () and passing the input that is supplied by the user at run time. Here, we are directly calling the square () method since it is a static method as static methods can only be referred inside a static context, The output of this program is shown in Fig.Java-3.13. Fig,Java-3.13 Now, we have discussed all the categories of control flaw statements. These control flow statements are useful to a programmer for writing better and complex programs as they are designed to implement any sort of logic. Before closing this chapter, let's have a look on ail that we have covered in this chapter. Summary In this chapter, you learned about: Conditional statements, such as if, if else, switch and their implementation. Iteration statements, such as for loop, while loop and their implementation. ‘Jump statements, such as break, continue, return and their implementation,Urheberrechtlich geschitztes Bild Urheberrechtlich geschiitztes MaterialJava 6 in Simple Steps I Java, every small or large program can only be created with the use of a template called class. A class is used to create and define the nature of objects, which are the instances of a class, We can also create a class within another class and the class created inside another class is called as inner class. A class also consist of methods in which the actual code to perform any specific task is written. A method can have any logical name that expresses the functionality of the method. For example, if you have to add two numbers then the name of the method can be sum, add, or addition. Java also provides us with constructors that are syntactically similar to methods and are used to initialize the objects. This. chapter is dedicated to classes and various others features related to classes. Here, we also study about another useful feature known as package. A package can be considered as a folder to store various classes that are related to an application. Let’s move ahead with an overview of classes. Overview of a class Class is a template to create Java programs consisting of variables and methods. The variables declared in a class are known as instance variables. A class has two parts—declaration and definition, The class keyword is used to declare a class. A class is defined using various methods in it. Let’s see the following cade snippet to understand the basic structure of a class: In the preceding code snippet, we have declared only two variables but you can create as many as required. In the same way, number of methods that need to be used in a class depends on the Program requirement. A Java class must contain main method as main method is the staring point of Java program. You need to call the class containing main method to compile and run the Java programs. Note Let's see Listing 4.1 to understand how to create a class.prugrann. In Listing 4.1, first we have declared some variable, which is then followed by assigning some valu : Let's In Fig.Java-4.1, you can see that the values assigned to the variables are displayed along with the statements specified within System.out.printin();. This is how you can create a class. Now, we will continue by discussing objects.Java 6 in Simple Steps Working with Objects Instances of a class are known as Objects and the process of creating objects from a class is known as Instantiation, While creating an instance of a class, the class works as a datatype. For example, in Listing 4.1, we have declared two variables— fname and sname—of String class working as a datatype. Let's see the process to create an object. To create an object, you have to declare a variable of class type to store the object reference. For example, if you have to create an object of the class sample (Listing 4.1) then you first have to declare a variable of sample class type. You can create the variable of the sample class as follows: sample infa: Now, you can create the object of the class. To create an object, new operator is used that dynamically allocates memory to an object and returns a reference to it. This reference is then stored in the variable declared through the use of previous step. Let’s see how to create an object of the sample class (Listing 4.1). “info = new sample (); Seni sR : HS You can also combine both the steps to create an object: as eee sample"info:= "new: sampleQi Each object has its own copy of the variable declared in the class definition. Let’s see (idling 42 to create and use object of sample (Listing 4.1) class. Listing 4.2: Creating and using ObjectChapter 4: Classes, Methods, Packages, and Aowss Specifers In Listing 4.2, we have created a method called disp, which contains the program code that defines the class. The program code is same as in Listing 4.1. Note: We will study more about methods in next section of this chapter. In the main method, first we have declared a variable called info of sample class type, which is then followed by creating object of the sample class. At last, we have used the object to call the disp method to use the program code written in that method. Fig.Java-4.2 is showing the output of Listing 4.2. Fig Java-t.2 This is all about creating and using objects. Now, we continue our discussion with methods. Working with Methods Methods are considered as functions that are used to perform some specific task in an jon. A method can have any name, such as disp, vol, and so on. Depending on the requirement of the program, many methods can be created in a program. The format to create a methad is as follows: In the preceding format: Q access_modifier: Access modifier is used to set the visibility of the code written in the methods to other members of the class. An access madifier can be public, private, or protected. Access modifiers will be discussed in detail ahead in this chapter. Q return_type: It can be any datatype depending on the type of values that a method is returning. If the method is not returning any value, then the datatype is replaced with void. A method returns the value to calling routine through the return statement. Q method_name: ltis the method name. 51Q para! It represents a list of parameters that are passed in a method. It may happen that there is no need to use parameters in a method. In that case, para_list is not used and brackets remain empty. In the curly braces, the body of the method is written. Let's see Listing 4.3 to create and use the methods. Listing 4.3: Creating and using methods In ing 4.3, we have created a class named sum in which we have created two methods. The first method is no_para, which has no parameter and the second one is para_y in which we have passed two parameters. We have used both no_para and para_y methods to calculate the sum of two numbers. In the method no_para, we have declared two variables and then initialized them with some value. After that, we have used ‘+’ operator to calculate their sum, which is then followed by assigning the sum into a third variable. Finally, we have displayed the sum assigned in the third variable along with the statement written within ‘System.out.printin’. After that, we have created para_y method in which we have performed the same functioning as done in no_para method, The only difference between both the methods is that in para_y method, we have passed two parameters— ‘a’ and ‘b’ of the type int. Inside the para_y method, we have declared two variables ‘c’ and ‘d’ of type int. In the variables ‘c’ and ‘d’, the values retrieved in ‘a’ and *b’ are assigned.Chapter 4; Clases, Methods, Packages, and acess Specfers Finally, we have used the main method to use the methods created in sum class. In the main method, first we have created two objects of the sum class. Then, we have used those abjects to invoke no_para and para_y methods. The no_para method is invoked with no parameter values because a non parameterized method while two TRATES are passed in para_y method because para_y is a parameterized method, Note Fig.Java-4.3 displays the output of Listing 4.3. Fig.Java-43, In Fig.Java-4.3, you can see the output of both methods used in Listing 4.3. This is how methods are created and used. Now, we discuss another important feature that is constructors. Working with Constructors Constructors are methods having the same name as the class name, for example, if a class carries a name demo then the constructor will also have the name demo. Constructors are syntactically similar to methods and are used to initialize the objects. A constructor initializes the object as. soon as the object is created. Following are few important points that must be remembered while working with constructors: The name of the constructor should be same as that of a class. Q Aconstructor does not have any return type—not even void—because implicitly, the return type of a constructor is class itself. First line of a constructor must either be a call to other constructor in the same class or a call to superclass constructor. If you do not call other constructor or superclass constructor explicitly, then the compiler implicitly calls the parameter less constructor of its superclass. Now, we discuss the types of constructors and how to create and use constructors under the following subheadings: Q Using Default Constructors Q Using Parameterized Constructors Let’s study these constructors in detail. 53Java 6 in Simple Steps Using Default Constructor A constructor without any parameter is called a default constructor. A default constructor is automatically created by Java. When no constructor is created explicitly then Java first implicitly creates a parameter less constructor and then calls the default parent constructor. The default parent constructor then initializes the instance variables to default values, that is Zero for numeric data types, null for object reference and String type, and false for boolean. Let's reconsider Listing 4.3 to understand the default constructor. In Listing 4.3, we have created two objects named get_sum and get_sum1 in class sum. But there we have not created any ‘constructor to initialize the instance variable for those objects. In that case, a default constructor is created and used by Java to initialize the instance variables related to those objects. Default constructors are used implicitly by Java when no other constructor is available. If you create any default constructor (parameter less) explicitly then Java uses the constructor created by you to initialize the instance variable related to objects of a class. Let's see Listing 4.4 to create the default constructor explicitly. Listing 4.4; Creating default constructor In Listing 4.4, we have created a class named def_cnstr to show how to create and use a default constructor in a class. In def _cnstzr, first we have declared two instance variables- x & y. Then a parameter less constructor is created in which variables x & y are initialized with some values. Now, we have created a method called mul to calculate the multiple of the instance variable that is initialized in the constructor. Finally, we have created an object called chk, which is then used to invoke the mu1 method. Let’s see the output of Listing 4.4 in Fig. Java-4.4Chapter 4: Classes, Methods, Packages, and Access Specifiers FigJavad4 This is all about default constructor, Now, let’s study the parameterized constructor, Using Parameterized Constructors The constructors having parameters are knawn as parameterized constructors. In parameterized constructors, the instance variable is initialized automatically at run time according to the values passed to parameters during the object creation. Parameterized constructor allows us to initialize the instance variable with different values; whereas, in case of default constructor, the values will remain same for all objects. For example, in case of default constructor, we have to initialize the instance variables with some fixed value and that value remains the same for all the objects of the class. In case of parameterized constructor, we do not initialize the instance variable with some fixed values, rather we use parameters to initialize instance variables. Parameters used in parameterized constructor receive the value passed during object creation and assign those values to instance variables. Now, see Listing 4.5 to know how to create parameterized constructors. Listing 4.5: Creating Parameterized constructorJava 6 in Simple Steps In Listing 4.5, we have created a class named para_cnstr to show how to create and use a parameterized constructor in a class. In para_enstr, first we declare two instance variables- x & y. Then a parameterized constructor is created in which the variable x & y are initialized with some dynamic values through the parameters used in constructor. Now, we have created a method called mu1 to calculate the multiple of the instance variable that are initialized in the constructor. Finally, we have created two objects called chk and chk1, which are then used to invoke the mul method. We have passed different values in both the objects to show that separate values will be initialized to instance variables at run time. Let's see the output of Listing 4.5 in Fig.Java-4.5. FigJava-45 In Listing 4.5, we have created only one constructor. We can create more than one constructor in a class and creating more than one constructor in a class is known as constructor overloading. We will discuss constructor overloading in detail in Chapter 5. We can also call the constructors and methods of a class into other constructors and methods in the same class. To do this, Java has provided a keyword called *this’. You can also use this keyword to refer the instance variables of the present class, Now, see Listing 4.6 to understand the functioning of this keyword. Listing 4.6: Program to understand the working of this keywordChapter 4: Classes, Methods, Packages, and Acwss Specifers In Listing 4.6, we have created a method and two constructors—default constructor and parameterized constructor. In default constructor, we have used this keyword to call the parameterized constructor and the method. In parameterized constructor, we have used this keyword to refer the instance variable. If you compare this parameterized constructor with the parameterized constructor created in Listing 4.5, then you see that in Listing 4.5 different variables are used as parameters. But here we have used the same name for parameters and instance variables. In Java, it is not allowed to use the same name for local variable or variables enclosed in the same scope. But with the use of this keyword, we can use the same name for instance variables and parameters, which saves us fram the trouble of remembering different names. After that, we have created a method to calculate the multiple of the values passed as parameters during the call to parameterized constructor from default constructor. Finally, the abject of the class is created, When the object is created then the control will transfer to the default constructor, which in turn invokes the parameterized constructor. The instance variables are then initialized with the values passed to parameterized constructor and then the method is called to perform computation. Now, see Fig.Java-4.6 to view the output. FigJava-4.6 This is all about creating and using constructors. Now, let's move ahead by discussing a very interesting feature of Java that allows you to use one class into another class.Java 6 in Simple Steps : 5 Working with Inner Classes In Java, it is possible to create a class inside another class. The class that is created inside the other class is known as inner class and the class in which inner class resides is known as outer class. An inner class has full access:ta the member variables of its outer class and in the same way outer class can also access member variables of inner class. The benefit of using inner class is that inner class is visible to its outer class only. So no other class can use the code written inside the inner class. The object of an- inner class can only be created by its outer class. You can use inner class to implement security features when you are writing some important code, such as password checking in an application and do not want to grant access of this code to other classes except its outer class. Let’s see Listing 4.7 to implement the concept of inner class in a Java’ program. Listing 4.7: Using inner classChapter 4: Classes, Methods, Packages, and Access Specifiers In Listing 4.7, we have created an outer class named out_cls and inside out_cls, another class called in_cls is created, which is the inner class. In in_cls, we have created a method called odd_even to segregate odd and even values from the values stored in the array. After that, a method called cal_inr is created in which we have created the object of inner class. Then we have called the inner class method inside the outer class method. In the main method, object of outer class is created, which is then followed by calling the outer class method, As soon as the outer class method is called, the contral transfers to the cal_inr method, which in tum performs its functioning. Let’s see Fig.Java-4.7 to have a look at the output of Listing 4.7. mgyava-a7 This is how you can use inner classes. Now, we continue our discussion with another important feature of Java that allows you to keep all the related classes together and also helps in resolving problem, such as class names collision. Exploring Packages A package can be considered as a directory or folder that allows you to store various classes related to each other in an application. Packages resalve the problem of class name collision. Till now, we have created many classes and if you have noticed that every class has a unique name because in Java you cannot create two classes with the same name. It means that for every new class, we have to assign a different name. Assigning a different.and unique name to every new class is a tedious task. To resolve this problem, you can use package. To understand how packages resolve the class name collision, let's consider an example. Suppose you have created some classes with names pass, detail, and so on in an application to justify the purpose of class just by reading the name. Now, you have to create another application in which you want to use the same name of the classes as in previous application. But in Java, it is not allawed to create multiple classes with the same name. This issue can be solved by using packages. To resolve the class name collision, put all the related classes in a package. Now, suppose you have created a class named pass in a package and also want to use the same name for any other class outside that package then you are allowed to do that. In Java, packages are divided into following two broad categories: Q Built-in Packages User-defined Packages 59Java 6 in Simple Steps Note We study about the process of creating a package under the subheading “User-defined” packages. Built-in Packages The packages that are already available in Java and help in performing various tasks in the programs are called Built-in packages. For example, there is a package called java. lang that provides classes required to develop basic Java program. To take the advantage of Built-in packages, you need to import them. Now see Table 4.1 in which we have summarized some important Built-in packages. 2s | Tablet: Buittin Packages javalang lang in java.lang stands for language. This package. Package Name Description contains primary classes that are essential for developing basic Java programs. The most important class it contains is object class, which is the root of class hierarchy and represents the class instances at run time. It contains. Wrapper classes that are used to convert primitive datatypes into objects. This package also contains runtime and system classes that have methods to execute an application and finding total available memory in JVM. javantil util im java.util stands for utility. This package contains collection classes, such as Arrays, Stack, and Linked List. It also contains classes to handle date and time operations. This package also contains. classes to implement internationalization in your application. io in java.io stands for input and output. This package . contains streams that are useful to store the data in the form of files and in performing input/output operations. javaio javaawt awt in java.awt stands for abstract window toolkit. This package contains classes to develop GUI (Graphical User Interface) application. Contains classes to use graphics and images in your application. javax.swing This package is also used to create GUI application as java.awt package. “x” in this package represents that it is extended from any other package to some additional features to develop GUI applications. javanot net in java.net stands for network. This package is used to perform networking operations, such as creating sockets to establish communication between client and server, 60& Methods, anid Access These are some important and commonly used Built-in packages that have classes to perform various tasks. Java, packages are not only limited to Built-in packages. can also create your own to perform many tasks according to your requirements convenience. User-defined packages The package created by the to perform some specific tasks is known as a user-defined package. User-defined packages also be imported and used in the same way as the Bt packages. To create a package, © package statement is used. Now, type the following snippet to create a package: package!
iy/-statenent) to’ create a package The pack_name in the preceding statement can be any logical name that you want to assign to your package. A package statement must be the first statement in Java source file, Let’s see Listing 4.8 to know the process to create a package. Listing 4.8: Creatine packageJava 6 in Simple Steps { for(k=0; k
x[k+1]) cu ‘kemp=x[ kel]; $ : A xfket}= xi; xEk]=temp; *< } z } } System.out.printIn("Elements after sorting are:"); ta ; for’ (Ja0; Jox-Tengths j++) “es £ ‘System, out. print In(xti]); // Printing iors array elements ‘on commnad prompt } n public static void main (string args{]) t int m[(J={5,3,2}; // Oecalring and initializing array bub_sort1 val = new bub_sortl(m); // creating ohiectg of class and — passing array : | wal.arrQ; // calling arr method 37 pe In Listing 4.8, we have created a package named son. In this package, we have created a class named bub_sort1 to perform sorting operation on some numbers through bubble sort algorithm. In the constructor, we have passed an array as parameter because the values on which the sorting has to be performed are stored in array, m. After that, we have created a method named arr in which the code to perform sorting on array elements has been written. In the main method, first we have declared and initialized an array, which is then followed by creating an object called val. Then, we have passed the reference of the array in val as parameter. At last, we have called the arr method. This is how to create a package. Now, let’s see how to compile and execute a program contained by package. The process to compile a program in a package is same as a basic Java class but it includes some more options, such as -d. To compile a package, you need to tell the compiler to create a package in the current directory. You can use the following statement to create a package and to compile the program created in the package: classpath> javac -d .
.java : The class name in the preceding statement can be any logical name given to the class. After executing this statement, you need to run the program. To run the program, you just have to refer the class name along with the package name. You can refer the class name by using *.” operator as follows: ‘Classpath> java
.
4: Classes, Methods, and Access Let's see of Listing 4.8. Fig Java-t8 In Listing 4.8, we have only a single program of sorting. But you can create more programs of sorting and put in the same package. In this way, you can create separate packages to assemble related programs. Let’s now see how to import packages. Importing Packages. Importing packages in an application allows you to take the advantages of classes stored in those packages. You can import as many packages as you need to use in an application. You can also import user-defined packages. You can take the benefit of any package by using the import statement with the package name in a Java program. Import statement must come after the package specification and before the class definition. Listing 4.9 shows how to import packages using imnort statement imp_pack has been created in which, first we have declared and initialized an array. Then, an object of the class used in sort package is created, which is then followed by calling the method arr to perform sorting on the array elements. In Listing 4.9, you can see that we have just passed some elements in the array on which the sorting has to be done. But the code to perform sorting has not yet been written in this listing because the code is already written in the package that we have imported. In brief by importing packages, we can simplify our work by using the code written in the programs stored in the packages. Now, see Fig.Java-4.9 to view the output. 63Java 6 in Simple Steps FigJavat.o In Fig.Java-4.9, you can see that the elements stored in the array are successfully sorted. Using Access Specifiers In Java, you can restrict or allow any class or method to access the code written in other class or method in a program. In the same way, you can also set the visibility of the classes enclosed in packages. To do that, Java has provided following access specifiers that help in controlling the access to code, class, and packages: Q public: This specifier is used when you want the classes, methods, and fields to be visible to other classes and methods. A public specifier makes the methods, classes, and fields accessible for all the other classes, methods, or packages. protected: This specifier is used when you want that the methods and fields used in a class or method can only be accessed by the members of the class in which those fields and methods are declared, subclasses related to that class, and within the classes of the same package. This specifier is used in the same way as public specifier in many of the Java programs. O default: When no specifier is used explicitly, then all the fields, methods, and classes are available to other classes and methods that are enclosed in the same package. private: This specifier is just the opposite of the public specifier. If private specifier is used then the methods and fields can only be accessed within the same class in which they are declared. This is all about access specifiers. With this, we have reached the end of this chapter. Let’s have a brief look on all that we have cavered in this chapter. Summary In this chapter, you learned about: Creating and using classes ‘Creating and using objects Using methods in Java programs Initializing instance variables using constructors Implementing Inner classes Creating and using packages coococn Access specifiersUrheberrechtlich geschitztes Bild Urheberrechilich geschiitztes MaterialJava 6 int Simple Steps bject-oriented programming (GOP) is a programming technique where you specify various objects and define the interaction among them to implement program logic. Classes and objects are the two main elements of OOP. Objects in OOP are based on real-life objects, such as a car. Similar to real-life objects that have specific properties and behavior, objects in OOP encompass specific properties and behaviors, which make them unique. For example, the color of a car represents a property, and the speed of the car represents its behavior. Similarly, the properties and behavior of objects in GOP are represented through variables and methods. The properties and behavior of an object in OOP are defined in a class. A class is a template for creating objects. An instance of a class is called an object. For example, car is an instance of the automobile class. In Java, OOP is implemented through encapsulation, (protecting data of a class from being accessed by members of another class}, abstraction, thiding data of a class from other classes), inheritance, (using the code written in a class within other classes), and polymorphism, (using various methods with the same name). In this chapter, we explore the principles of OOP, such as encapsulation, abstraction, polymorphism, and inheritance. In addition, we discuss interfaces and abstract classes in Java. Understanding Encapsulation Encapsulation is a mechanism that binds class members (variables and methods) together and prevents them from being accessed by other classes, thereby protecting the class members. In Java, you can consider a class an example of encapsulation, because a class binds variables and methods together and hides their complexity from other classes. Variables in a class are generally marked private to prevent ather classes in the program from accessing them. Now, the question arises, if variables cannot be accessed by other classes in a program, then how can its data be used? The answer lies in creating public methods that other classes can access. By accessing these public methods, you can access the variables used in the methods, This is the only way of interacting with the variables declared in a class. This means that other classes are unaware of the variables used in a particular class as well as the code written in the methods to access the variables. In this way, other classes are able to access the methods, You now have a brief idea about encapsulation. Let's therefore learn how to create a class that uses the concept of encapsulation, as shawn in Listing 5.1: Listing 5.1: Implementing the Concept of EncapsulationChapter 5: Implementing Objects Oriented Programming In Java In Listing 5.1, the Student class declares two private variables, name and subject, and a method, desc (). Listing 5,1 also creates a class called Student Instance, which is used to access the private variables of the Student class. In Java, one class cannot directly access. the members of another class. We therefore mark the dese () method of the Student class public, so that it can be accessed by the Student Instance class. The s instance of the Student class is created in the Student Instance class and used to invoke the desc() method, which accesses the private variables of the Student class. In this way, the private variables of a class can be accessed with the help of a public method. In Listing 5.1, the desc{) method of the Student. class can only be accessed in the Studentinstance class, but the method's definition cannot be modified. Fig.Java-5.1 shows the output of Listing 5.1: Fig.Java-5.1 Fig.java-S.1 displays the message specified in the desc() method. In this way, the concept of encapsulation is implemented in Java. Now, let’s explore another important OOP’s principle called abstraction. Understanding Abstraction Abstraction is the mechanism by which we hide data that is not required by a user. The advantage of abstraction is that the user can work only with the required data and does not need to view unwanied data. Let's take the example of the car to understand the concept of abstraction. As the owner of the car, you must know how to drive it. This obviously implies that you know about the various ‘components of the car and how to use them, For example, you know that the accelerator pedal is used to increase the speed of the car and pressing the brake pedal stops it. To perform these simple actions, you just need to know how to use these components, and not how they function, Similarly, in OOP, you need to know about the specific classes or methods that are called to implement specific program logic, without knowing how these classes or methads function. This concept is known as abstraction. Listing 5.2 shows you how to implement abstraction in Java: a7
You might also like
Core Java
PDF
100% (3)
Core Java
292 pages
IQ Puzzles
PDF
96% (25)
IQ Puzzles
210 pages
Dark Psychology Secrets William Cooper Z Library
PDF
89% (71)
Dark Psychology Secrets William Cooper Z Library
124 pages
Great Critical Thinking Puzzles
PDF
89% (18)
Great Critical Thinking Puzzles
96 pages
The Mental Toughness Handbook-Damon Zahariades
PDF
88% (17)
The Mental Toughness Handbook-Damon Zahariades
212 pages
SPOKEN ENGLISH and Grammar A Self Learning Book Made Simple For All (Strong Foundation For IELTS & TOEFL) - Nodrm
PDF
90% (29)
SPOKEN ENGLISH and Grammar A Self Learning Book Made Simple For All (Strong Foundation For IELTS & TOEFL) - Nodrm
344 pages
English Vocabulary List
PDF
86% (7)
English Vocabulary List
29 pages
Class 4 Addition and Subtraction
PDF
87% (15)
Class 4 Addition and Subtraction
10 pages
How To Be A Math Genius - Your Brilliant Brain and How To Train It
PDF
96% (26)
How To Be A Math Genius - Your Brilliant Brain and How To Train It
128 pages
Grade 5 Math Book
PDF
100% (10)
Grade 5 Math Book
212 pages
Manipulation and NLP Techni...
PDF
96% (28)
Manipulation and NLP Techni...
166 pages
(2006) Amazing Aha! Puzzles by Lloyd King
PDF
88% (8)
(2006) Amazing Aha! Puzzles by Lloyd King
180 pages
Math Calculation Tricks PDF
PDF
100% (1)
Math Calculation Tricks PDF
58 pages
How To Talk To Anyone About Anything Improve Your Social Skills Master Small Talk
PDF
92% (50)
How To Talk To Anyone About Anything Improve Your Social Skills Master Small Talk
103 pages
Master Your Mindset How To Get What You Truly Deserve - Reading Mindset
PDF
95% (22)
Master Your Mindset How To Get What You Truly Deserve - Reading Mindset
66 pages
Matrix
PDF
100% (3)
Matrix
45 pages
Maths Olympiad
PDF
80% (10)
Maths Olympiad
90 pages
ISFO Maths Olympiad Workbook PDF
PDF
75% (8)
ISFO Maths Olympiad Workbook PDF
64 pages
Fractions
PDF
100% (11)
Fractions
50 pages
Delegation of Taxation Power
PDF
No ratings yet
Delegation of Taxation Power
6 pages
Math and Logic Puzzles
PDF
94% (31)
Math and Logic Puzzles
140 pages
CIPP Exam Preparation Tips 1725949523
PDF
No ratings yet
CIPP Exam Preparation Tips 1725949523
29 pages
Default Methods in Java 8 - Shaikh
PDF
No ratings yet
Default Methods in Java 8 - Shaikh
3 pages
9-Article Text-21-4-10-20240829
PDF
No ratings yet
9-Article Text-21-4-10-20240829
11 pages
Lambdas and Functional Interfaces in Java 8 - Shaikh
PDF
No ratings yet
Lambdas and Functional Interfaces in Java 8 - Shaikh
2 pages
Title - Overview of Java 8 Features - Shaikh
PDF
No ratings yet
Title - Overview of Java 8 Features - Shaikh
2 pages
Cipp-E - Sample Test 4-To Read
PDF
No ratings yet
Cipp-E - Sample Test 4-To Read
21 pages
Math Word Problems Book
PDF
92% (39)
Math Word Problems Book
368 pages
Std. II Practice Worksheet Hindi
PDF
No ratings yet
Std. II Practice Worksheet Hindi
3 pages
Adverbs - Worksheet 1
PDF
No ratings yet
Adverbs - Worksheet 1
1 page
Interview Brain Teasers Questions With Answers - Genius Puzzles PDF
PDF
No ratings yet
Interview Brain Teasers Questions With Answers - Genius Puzzles PDF
11 pages
Interjections Worksheet: A: Identify The Interjection
PDF
No ratings yet
Interjections Worksheet: A: Identify The Interjection
1 page
Was / Were: Simple Past
PDF
No ratings yet
Was / Were: Simple Past
8 pages
Subject and Predicate Worksheet
PDF
No ratings yet
Subject and Predicate Worksheet
1 page
Lose Not Your Heart
PDF
No ratings yet
Lose Not Your Heart
10 pages