0% found this document useful (0 votes)
7 views7 pages

Java

The document covers various fundamental concepts of Java programming, including data types, control structures, loops, methods, and object-oriented programming principles. It explains the importance of strong typing, conversion between data types, decision-making structures like if statements and switch cases, and the use of loops for iteration. Additionally, it discusses methods for code reuse, object creation, and the organization of classes within packages, providing a comprehensive overview of Java programming basics.

Uploaded by

workonlingct
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Java

The document covers various fundamental concepts of Java programming, including data types, control structures, loops, methods, and object-oriented programming principles. It explains the importance of strong typing, conversion between data types, decision-making structures like if statements and switch cases, and the use of loops for iteration. Additionally, it discusses methods for code reuse, object creation, and the organization of classes within packages, providing a comprehensive overview of Java programming basics.

Uploaded by

workonlingct
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chapter 2:

1. Java is a strongly typed language.


2. narrowing conversion (Explicitly)
3. widening conversion.(Automatic)
4. cast operators : The cast operator lets you manually convert a value, even if it means that a
narrowing conversion will take place. x = (int)number;
The cast operator can be applied to an entire expression enclosed in parentheses. For
example, look at the following statement: piesPerPerson = (double)(pies / people);
5. third Number = first Number + second Number; The error results from the fact that third
Number is a short. Although first Number and second Number are also short variables, the
expression first Number + second Number results in an int value.
6. The final key word can be used in a variable declaration to make the variable a named
constant. Named constants are initialized with a value, and that value cannot change during
the execution of the program.
7. Remember that String is a class, not a primitive data type.
8. Primitive type variables hold the actual data items with which they are associated.
9. A class type variable does not hold the actual data item that it is associated with, but holds
the memory address of the data item it is associated with.
10. The general form of a method call is as follows: [Link](arguments. . .)
The String class’s length method returns the number of characters in the string, including
spaces
11. String lower = [Link]();
10 char letter = [Link](2);
11 int stringSize = [Link]();
12. The Math class, which is part of the Java API, provides a predefined named constant,
[Link]. This constant is assigned the value 3.14159265358979323846, which is an
approximation of the mathematical value pi.
area = [Link] * radius * radius;
13. A string is a sequence of characters. It can be used to represent any type of data that
contains text, such as names, addresses, warning messages, and so forth.
14. The S in String is written in an uppercase letter. By convention, the first character of a class
name is always written in an uppercase letter
15. Mixing calls to nextLine with calls to other Scanner Methods
16. Using the import statement
17. reading Keyboard input
18. programming style
19. comments
20. scope
Chapter 3:
1. The if statement is used to create a decision structure, which allows a program to have more
than one path of execution. The if statement causes one or more statements to execute only
when a Boolean expression is true
2. You do not put a semicolon after the if (expression) portion of an if statement This is because
the if statement isn’t complete without its condition ally executed statement.
3. A flag is a Boolean variable that signals when some condition exists in the program. When the
flag variable is set to false, it indicates the condition does not yet exist. When the flag variable is
set to true, it means the condition does exist.
4. Unicode is an international encoding system that is extensive enough to represent all the
characters of all the world’s alphabets.
5. Comparing Characters
6. : The if-else statement will execute one group of statements if its boolean expression is true, or
another group if its boolean expression is false
7. To test more than one condition, an if statement can be nested inside another if statement
8. Logical operators connect two or more relational expressions into one or reverse the logic of an
expression.
9. The && operator performs short-circuit evaluation.
10. The precedence of Logical operators
11. “! “ > “&&” > “ ||”
12. You cannot use relational operators to compare String objects. Instead, you must use a String
method
13. [Link](StringReference2) [Link](name2)
14. [Link](OtherString)
●If the method’s return value is negative, the string referenced by StringReference (the calling
object) is less than the OtherString argument.
• If the method’s return value is 0, the two strings are equal.
• If the method’s return value is positive, the string referenced by StringReference (the calling
object) is greater than the OtherString argument
15. The equals and compareTo methods perform case-sensitive comparisons, which means that
uppercase letters are not considered the same as their lowercase counterparts.
The String class provides the equalsIgnoreCase and compareToIgnoreCase methods.
16. You can use the conditional operator to create short expressions that work like if-else
statements ,ternary operator.
17. The switch statement lets the value of a variable or expression determine where the program
will branch to.
18. The switch statement is a multiple alternative decision structure.
19. Each of the case values must be unique.
1. Omitting the trailing else in an if-else-if statement. This is not a syntax error, but can
lead to logical errors. If you omit the trailing else from an if-else-if statement, no code
will be executed if none of the statement’s boolean expressions are true.
2. • Using a Case Expression that is not a literal or a final variable. Because the compiler
must determine the value of a Case Expression at compile time, Case Expressions must
be either literal values or final variables
3. 3. Body Mass Index Write a program that calculates and displays a person’s body mass
index (BMI). The BMI is often used to determine whether a person with a sedentary
lifestyle is overweight or underweight for his or her height. A person’s BMI is calculated
with the following formula: BMI 5 Weight 3 703 / Height2 where weight is measured in
pounds and height is measured in inches. The program should display a message
indicating whether the person has optimal weight, is underweight, or is overweight. A
sedentary person’s weight is considered optimal if his or her BMI is between 18.5 and
25. If the BMI is less than 18.5, the person is considered underweight. If the BMI value is
greater than 25, the person is considered overweight.

Chapter 4:
1. A loop is part of a program that repeats
2. The while loop is known as a pretest loop, which means it tests its expression before
each iteration.
3. It’s also possible to create an infinite loop by accidentally placing a semicolon after
the first line of the while loop.
4. The while loop can be used to create input routines that repeat until acceptable
data is entered.
5. “garbage in, garbage out.”
6. Input validation is the process of inspecting data given to a program by the user and
determining whether it is valid.
7. Each repetition of a loop is known as an iteration.
8. The do-while loop is a posttest loop, which means its boolean expression is tested
after each iteration
9. Pretest and posttest concepts
10. The do-while loop must be terminated with a semicolon.
11. the loop asks the user whether he or she wants to repeat the process. This type of
loop is known as a user-controlled loop.
12. The for loop is ideal for performing a known number of iterations.
13. A conditional loop executes as long as a particular condition exists.
14. A loop that repeats a specific number of times is known as a count-controlled loop.
15. In Java, the for loop is ideal for writing count-controlled loops.
16. The first line of the for loop is known as the loop header.
17. Creating a User Controlled for Loop
18. Using Multiple Statements in the Initialization and Update expressions
19. If you wish to combine multiple boolean expressions in the test expression, you
must use the && or || operators
20. A running total is a sum of numbers that accumulates with each iteration of a loop.
The variable used to keep the running total is called an accumulator. A sentinel is a
value that signals when the end of a list of values has been reached.
21. A sentinel value is a special value that cannot be mistaken as a member of the list,
and signals that there are no more values to be entered.
22. note that the sentinel value is not included in the running total.
23. A loop that is inside another loop is called a nested loop.
24. • An inner loop goes through all of its iterations for each iteration of an outer loop.
• Inner loops complete their iterations before outer loops do.
• To get the total number of iterations of a nested loop, multiply the number of
iterations of all the loops.
25. The break statement causes a loop to terminate early. The continue statement
causes a loop to stop its current iteration and begin the next one.
26. Although most repetitive algorithms can be written with any of the three types of
loops, each works best in different situations.
27. • The while loop. The while loop is a pretest loop. It is ideal in situations where you
do not want the loop to iterate if the condition is false from the beginning. It is also
ideal if you want to use a sentinel value to terminate the loop. • The do-while loop.
The do-while loop is a posttest loop. It is ideal in situations where you always want
the loop to iterate at least once. • The for loop. The for loop is a pretest loop that
has built-in expressions for initializing, testing, and updating. These expressions
make it very convenient to use a loop control variable as a counter. The for loop is
ideal in situations where the exact number of iterations is known.
28. • The Java API provides several classes that you can use for writing data to a file and
reading data from a file. To write data to a file, you can use the PrintWriter class
and, optionally, the FileWriter class. To read data from a file, you can use the
Scanner class and the File class.
29. An input file is a file that a program reads data from.
30. An output file is a file that a program writes data to.
31. A text file contains data that has been encoded as text, using a scheme such as
Unicode.
32. A binary file contains data that has not been converted to text.
33. import [Link].*;
34. PrintWriter outputFile = new PrintWriter("[Link]")
35. [Link]("Jim");
36. [Link]();
37. . A buffer is a small “holding section ” of memory.
38. The close method writes any unsaved data remaining in the file buffer.
39. The println method in file writes data to the file and then writes a newline character
immediately after the data.
40. A delimiter is an item that separates other items.
41. Print & println
42. Adding a throws Clause to the Method Header
43. think of an exception as a signal indicating that the program cannot continue until
the unexpected event has been dealt with.
44. public static void main(String[] args) throws IOException
45. Appending Data to a File: Appending to a file means writing new data to the end of
the data that already exists in the file.
46. FileWriter fwriter = new FileWriter("[Link]", true);
47. When you create the PrintWriter object, you pass a reference to the FileWriter
object as an argument to the PrintWriter constructor.
48. FileWriter fwriter = new FileWriter("[Link]", true); PrintWriter outputFile =
new PrintWriter(fwriter);
49. When you open a file you may specify its path along with its filename.
50. PrintWriter outputFile = new PrintWriter("A:\\[Link]");
51. Java allows you to substitute forward slashes for backslashes in a Windows path. For
example, the path "C:\\MyData\\[Link]" could be written as
"C:/MyData/[Link]". This eliminates the need to use double backslashes.
52. [Link]();
53. The Scanner class’s nextLine method reads a line of input, and returns the line as a
String.
54. String str = [Link]();
55. The string that is returned from the nextLine method will not contain the newline
character.
56. Random numbers are used in a variety of applications. Java provides the Random
class that you can use to generate random numbers.
57. import [Link];
58. Random randomNumbers = new Random();

Chapter no 5:
1. Methods can be used to break a complex program into small, manageable
pieces. A void method simply executes a group of statements and then
terminates. A value-returning method returns a value to the statement that
called it.
2. divide and conquer
3. This benefit of using methods is known as code reuse
4. A void method is one that simply performs a task and then terminates.
5. A value-returning method not only performs a task but also sends a value back
to the code that called it.
6. A value-returning method not only performs a task but also sends a value back
to the code that called it.
7. In this text, the values that are passed into a method are called arguments, and
the variables that receive those values are called parameters.
8. Also, some call the arguments actual parameters and call the parameters formal
parameters
9. A method’s local variables exist only while the method is executing. This is
known as the lifetime of a local variable.

Chapter no 6:
1. An object is a software component that exists in memory and serves a
specific purpose in a program. An object is created from a class that
contains code describing the object
2. The data stored in an object are commonly called fields.
3. The operations that an object can perform are called methods
4. Each object that is created from a class is called an instance of the class.
5. .
6. .
7. .
8. .
9. The process of matching a method call with the correct method is known as
binding.
10. A method’s signature consists of the method’s name and the data types of
the method’s parameters, in the order that they appear. Instance fields are
visible to all of the class’s instance methods.
11. The classes in the Java API are organized into packages. An import
statement tells the compiler which package a class is located in.
12. A package is simply a group of related classes. Each package also has a
name.
13. There are two types of import statements: explicit and wildcard.
14. An explicit import statement identifies the package location of a single class.
15. A wildcard import statement tells the compiler to import all of the classes in
a package.
16. The Java API does have one package, [Link], which is automatically
imported into every Java program.
17. Get a written description of the problem domain.
Identify all the nouns (including pronouns and noun phrases) in the
description. Each of these is a potential class.
Refine the list to include only the classes that are relevant to the problem
18. The problem domain is the set of real-world objects, parties, and major
events related to the problem.
19. The first step is to analyze the problem that you are trying to solve and
determine the classes that you will need.
20. Typically, your goal is to identify the different types of real-world objects
that are present in the problem, and then create classes for those types of
objects within your application
21. 1. Get a written description of the problem domain.
2. Identify all the nouns (including pronouns and noun phrases) in the
description. Each of these is a potential class.
3. Refine the list to include only the classes that are relevant to the problem
22. The problem domain is the set of real-world objects, parties, and major
events related to the problem.
23. It is often helpful to ask the questions “In the context of this problem, what
must the class know? What must the class do?
Chapter no 7:
1. One solution is to make the array large enough to hold the largest possible
number of items. This can lead to another problem, however. If the actual
number of items stored in the array is less than the number of elements,
the array will be only partially filled.
2. An array of String objects may be created, but if the array is uninitialized,
each String in the array must be created individually
3. Because the array’s length member is a field, you do not write a set of
parentheses after its name. You do write the parentheses after the name of
the String class’s length method
4. You may create arrays of objects that are instances of classes that you have
written
5. A search algorithm is a method of locating a specific item in a larger
collection of data. This section discusses the sequential search algorithm,
which is a simple technique for searching the contents of an array
6. A two-dimensional array is an array of arrays. It can be thought of as having
rows and columns.
7. To declare a two-dimensional array, two sets of brackets and two size
declarators are required: The first one is for the number of rows and the
second one is for the number of columns.
8. When initializing a two-dimensional array, you enclose each row’s
initialization list in its own set of braces.
9. The length Field in a Two-Dimensional Array
10. summing All the elements of a Two-Dimensional Array
11. When the rows of a two-dimensional array are of different lengths, the
array is known as a ragged array.
12. Java does not limit the number of dimensions that an array may have. It is
possible to create arrays with multiple dimensions, to model data that
occurs in multiple sets.
13. A sorting algorithm is used to arrange data into some order. A search
algorithm is a method of locating a specific item in a larger collection of
data. The selection sort and the binary search are popular sorting and
searching algorithms.
14. The binary search is a clever algorithm that is much more efficient than the
sequential search.
15.

You might also like