Vous êtes sur la page 1sur 18

1.

Java refers to a number of proprietary computer software products and specifications from Sun
Microsystems, a subsidiary of Oracle Corporation, that together provide a system for developing application
software and deploying it in a cross-platform environment. Java is used in a wide variety of computing
platforms from embedded devices and mobile phones on the low end, to enterprise servers and
supercomputers on the high end. Java is used in mobile phones, Web servers and enterprise applications, and
while less common on desktop computers, Java applets are often used to provide improved and secure
functionalities while browsing the World Wide Web.
Writing in the Java programming language is the primary way to produce code that will be deployed as Java
bytecode, though there are bytecode compilers available for other languages such as JavaScript, Python,
Ruby and Scala, and a native Java scripting language called Groovy. Java syntax borrows heavily from C and
C++ but it eliminates certain low-level constructs such as pointers and has a very simple memory model
where every object is allocated on the heap and all variables of object types are references. Memory
management is handled through integrated automatic garbage collection performed by the Java Virtual
Machine (JVM).
On November 13, 2006, Sun Microsystems made the bulk of its implementation of Java available under the
GNU General Public License
[1]
, although there are still a few parts distributed as precompiled binaries due to
copyright issues with Sun-licensed (not owned) code
Usage
Desktop use
According to Sun, the Java Runtime Environment is found on over 700 million PCs.
[13]
Microsoft has not
bundled a Java Runtime Environment (JRE) with its operating systems since Sun Microsystems sued
Microsoft for adding Windows-specific classes to the bundled Java runtime environment, and for making the
new classes available through Visual J++. A Java runtime environment is bundled with Apple's Mac OS X,
and many Linux distributions include the partially compatible free software package GNU Classpath.
[14]

Some Java applications are in fairly widespread desktop use, including the NetBeans and Eclipse integrated
development environments, and file sharing clients such as LimeWire and Vuze. Java is also used in the
MATLAB mathematics programming environment, both for rendering the user interface and as part of the
core system.
Mobile devices
Java ME has become popular in mobile devices, where it competes with Symbian, BREW, and the .NET
Compact Framework.
The diversity of mobile phone manufacturers has led to a need for new unified standards so programs can run
on phones from different suppliers - MIDP. The first standard was MIDP 1, which assumed a small screen
size, no access to audio, and a 32kB program limit. The more recent MIDP 2 allows access to audio, and up
to 64kB for the program size. With handset designs improving more rapidly than the standards, some
manufacturers relax some limitations in the standards, for example, maximum program size.
2.
boolean
1-bit. May take on the values true and false only.
true and false are defined constants of the language and are not the same as True and False, TRUE
and FALSE, zero and nonzero, 1 and 0 or any other numeric value. Booleans may not be cast into any
other type of variable nor may any other variable be cast into a boolean.
byte
1 signed byte (two's complement). Covers values from -128 to 127.
short
2 bytes, signed (two's complement), -32,768 to 32,767
int
4 bytes, signed (two's complement). -2,147,483,648 to 2,147,483,647. Like all numeric types ints
may be cast into other numeric types (byte, short, long, float, double). When lossy casts are done (e.g.
int to byte) the conversion is done modulo the length of the smaller type.
long
8 bytes signed (two's complement). Ranges from -9,223,372,036,854,775,808 to
+9,223,372,036,854,775,807.
float
4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38
(positive or negative).
Like all numeric types floats may be cast into other numeric types (byte, short, long, int, double).
When lossy casts to integer types are done (e.g. float to short) the fractional part is truncated and
the conversion is done modulo the length of the smaller type.
double
8 bytes IEEE 754. Covers a range from 4.94065645841246544e-324d to
1.79769313486231570e+308d (positive or negative).
char
2 bytes, unsigned, Unicode, 0 to 65,535
Chars are not the same as bytes, ints, shorts or Strings.
3.
Comparing Strings for Equality

public class MainClass {

public static void main(String[] arg) {

String a = "a";
String b = "a";

if(a.equals(b)){
System.out.println("a==b");
}else{
System.out.println("a!=b");
}
}
}
a==b
To check for equality between two strings ignoring the case


public class MainClass {

public static void main(String[] arg) {

String a = "a";
String b = "A";

if(a.equalsIgnoreCase(b)){
System.out.println("a==b");
}else{
System.out.println("a!=b");
}
}
}

a==b

To check for equality between two strings ignoring the case

public class MainClass {

public static void main(String[] arg) {

String a = "a";
String b = "A";

if(a.equalsIgnoreCase(b)){
System.out.println("a==b");
}else{
System.out.println("a!=b");
}
}
}
a==b

4.
A variable is a container that holds values that are used in a Java program. To be able to use a variable it
needs to be declared. Declaring variables is normally the first thing that happens in any program.
Declare a Variable
Java is a strongly typed programming language. This means that every variable must have a data type
associated with it. For example, a variable could be declared to use one of the eight primitive data types:
byte, short, int, long, float, double, char or boolean.
A good analogy for a variable is to think of a bucket. We can fill it to a certain level, we can replace what's
inside it, and sometimes we can add or take something away from it. When we declare a variable to use a
data type it's like putting a label on the bucket that says what it can be filled with. Let's say the label for the
bucket is "Sand". Once the label is attached, we can only ever add or remove sand from the bucket. Anytime
we try and put anything else into it, we will get stopped by the bucket police. In Java, you can think of the
compiler as the bucket police. It ensures that programmers declare and use variables properly.
To declare a variable in Java, all that is needed is the data type followed by the variable name:
int numberOfDays;
In the above example, a variable called "numberOfDays" has been declared with a data type of int. Notice
how the line ends with a semi-colon. The semi-colon tells the Java compiler that the declaration is complete.
Now that it has been declared, numberOfDays can only ever hold values that match the definition of the data
type (i.e., for an int data type the value can only be a whole number between -2,147,483,648 to
2,147,483,647).
Declaring variables for other data types is exactly the same:
byte nextInStream;
short hour;
long totalNumberOfStars;
float reactionTime;
double itemPrice;
Initializing Variables
Before a variable can be used it must be given an initial value. This is called initializing the variable. If we
try to use a variable without first giving it a value:
int numberOfDays;
//try and add 10 to the value of numberOfDays
numberOfDays = numberOfDays + 10;
the compiler will throw an error:
variable numberOfDays might not have been initialized
To initialize a variable we use an assignment statement. An assignment statement follows the same pattern as
an equation in mathematics (e.g., 2 + 2 = 4). There is a left side of the equation, a right side and an equals
sign (i.e., "=") in the middle. To give a variable a value, the left side is the name of the variable and the right
side is the value:
int numberOfDays;
numberOfDays = 7;
In the above example, numberOfDays has been declared with a data type of int and has been giving an initial
value of 7. We can now add ten to the value of numberOfDays because it has been initialized:
int numberOfDays;
numberOfDays = 7;
numberOfDays = numberOfDays + 10;
System.out.println(numberOfDays);
Typically, the initializing of a variable is done at the same time as its declaration:
//declare the variable and give it a value all in one statement
int numberOfDays = 7;


5.
Variables are the nouns of a programming language-that is, they are the entities (values and data) that act or
are acted upon. The countChars method defines two variables-- count and in. The program increments count
each time it reads a character from the other variable in. The declarations for both variables appear in bold in
the following listing:
import java.io.*;
public class Count {
public static void countChars(Reader in) throws IOException
{
int count = 0;

while (in.read() != -1)
count++;
System.out.println("Counted " + count + " chars.");
}
// ... main method omitted ...
}
A variable declaration always contains two components: the type of the variable and its name. The location
of the variable declaration, that is, where the declaration appears in relation to other code elements,
determines its scope.
Data Types
All variables in the Java language must have a data type. A variable's data type determines the values that the
variable can contain and the operations that can be performed on it. For example, the declaration int count
declares that count is an integer (int). Integers can contain only integral values (both positive and negative),
and you can use the standard arithmetic operators (+, -, *, and /) on integers to perform the standard
arithmetic operations (addition, subtraction, multiplication, and division, respectively).
There are two major categories of data types in the Java language: primitive and reference. The following
table lists, by keyword, all of the primitive data types supported by Java, their sizes and formats, and a brief
description of each.
Type Size/Format Description
(integers)
byte 8-bit two's complement Byte-length integer
short 16-bit two's complement Short integer
int 32-bit two's complement Integer
long 64-bit two's complement Long integer
(real numbers)
float 32-bit IEEE 754 Single-precision floating point
double 64-bit IEEE 754 Double-precision floating point
(other types)
char 16-bit Unicode character A single character
boolean true or false A boolean value (true or false)

Purity Tip: In other languages, the format and size of primitive data types may depend on the platform on
which a program is running. In contrast, the Java language specifies the size and format of its primitive data
types. Hence, you don't have to worry about system-dependencies.

A variable of primitive type contains a single value of the appropriate size and format for its type: a number,
character, or boolean value. For example, the value of an int is an integer, the value of a char is a 16-bit
Unicode character, and so on. The value of the count variable in countChars ranges from its initial value of
zero to a number that represents the number of characters in the input.
Arrays, classes, and interfaces are reference types. The value of a reference type variable, in contrast to that
of a primitive type, is a reference to the actual value or set of values represented by the variable. A reference
is like your friend's address: The address is not your friend, but it's a way to reach your friend. A reference
type variable is not the array or object itself but rather a way to reach it.
The countChars method uses one variable of reference type, in, which is a Reader object. When used in a
statement or expression, the name in evaluates to a reference to the object. So you can use the object's name
to access its member variables or call its methods (just as countChars does to call read).
Variable Names
A program refers to a variable's value by its name. For example, when the countChars method wants to refer
to the value of the count variable, it simply uses the name count.
In Java, the following must hold true for a variable name
1. It must be a legal Java identifier comprised of a series of Unicode characters. Unicode is a character-
coding system designed to support text written in diverse human languages. It allows for the
codification of up to 65,536 characters, currently 34,168 have been assigned. This allows you to use
characters in your Java programs from various alphabets, such as Japanese, Greek, Cyrillic, and
Hebrew. This is important so that programmers can write code that is meaningful in their native
languages.
2. It must not be a keyword or a boolean literal (true or false).
3. It must not have the same name as another variable whose declaration appears in the same scope.

By Convention: Variable names begin with a lowercase letter and class names begin with an uppercase
letter. If a variable name consists of more than one word, such as isVisible, the words are joined together and
each word after the first begins with an uppercase letter.

Rule #3 implies that variables may have the same name as another variable whose declaration appears in a
different scope. This is true. In addition, in some situations, a variable may share names with another variable
which is declared in a nested scope. Scope is covered in the next section.
Scope
A variable's scope is the block of code within which the variable is accessible and determines when the
variable is created and destroyed. The location of the variable declaration within your program establishes its
scope and places it into one of these four categories:
Member variable
Local variable
Method parameter
Exception-handler parameter

A member variable is a member of a class or an object. It can be declared anywhere in a class but not in a
method. The member is available to all code in the class. The Count class declares no member variables. For
information about declaring member variables, refer to Declaring Member Variables in the next lesson.
You can declare local variables anywhere in a method or within a block of code in a method. In countChars,
count is a local variable. The scope of count, that is, the code that can access count, extends from the
declaration of count to the end of the countChars method (indicated by the first right curly bracket } that
appears in the program code). In general, a local variable is accessible from its declaration to the end of the
code block in which it was declared.
Method parameters are formal arguments to methods and constructors and are used to pass values into
methods. The discussion about writing methods in the next lesson, Implementing Methods , talks about
passing values into methods through parameters. You can also pass values into constructors in the same
manner, so the discussion regarding method parameters applies equally well to parameters to constructors. In
countChars, in is a parameter to the countChars method. The scope of a method parameter is the entire
method for which it is a parameter. So, in countChars, the scope of in is the entire countChars method.
Exception-handler parameters are similar to method parameters but are arguments to an exception handler
rather than to a method or a constructor. The countChars method does not have any exception handlers, so it
doesn't have any exception-handler parameters. Handling Errors with Exceptions talks about using Java
exceptions to handle errors and shows you how to write an exception handler that has a parameter.
Variable I nitialization
Local variables and member variables can be initialized with an assignment statement when they're declared.
The data type of both sides of the assignment statement must match. The countChars method provides an
initial value of zero for count when declaring it:
int count = 0;
The value assigned to the variable must match the variable's type.
Method parameters and exception-handler parameters cannot be initialized in this way. The value for a
parameter is set by the caller.
Final Variables
You can declare a variable in any scope to be final, including parameters to methods and constructors. The
value of a final variable cannot change after it has been initialized.
To declare a final variable, use the final keyword in the variable declaration before the type:
final int aFinalVar = 0;
The previous statement declares a final variable and initializes it, all at once. Subsequent attempts to assign a
value to aFinalVar result in a compiler error. You may, if necessary, defer initialization of a final variable.
Simply declare the variable and initialize it later, like this:
final int blankfinal;
. . .
blankfinal = 0;
A final variable that has been declared but not yet initialized is called a blank final. Again, once a final
variable has been initialized it cannot be set and any later attempts to assign a value to blankfinal result in a
compile-time error.

6.
As you learned in the previous lesson, an object stores its state in fields.
int cadence = 0;
int speed = 0;
int gear = 1;
The What Is an Object? discussion introduced you to fields, but you probably have still a few questions, such
as: What are the rules and conventions for naming a field? Besides int, what other data types are there? Do
fields have to be initialized when they are declared? Are fields assigned a default value if they are not
explicitly initialized? We'll explore the answers to such questions in this lesson, but before we do, there are a
few technical distinctions you must first become aware of. In the Java programming language, the terms
"field" and "variable" are both used; this is a common source of confusion among new developers, since both
often seem to refer to the same thing.
The Java programming language defines the following kinds of variables:
Instance Variables (Non-Static Fields) Technically speaking, objects store their individual states in
"non-static fields", that is, fields declared without the static keyword. Non-static fields are also known
as instance variables because their values are unique to each instance of a class (to each object, in
other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.
Class Variables (Static Fields) A class variable is any field declared with the static modifier; this
tells the compiler that there is exactly one copy of this variable in existence, regardless of how many
times the class has been instantiated. A field defining the number of gears for a particular kind of
bicycle could be marked as static since conceptually the same number of gears will apply to all
instances. The code static int numGears = 6; would create such a static field. Additionally, the
keyword final could be added to indicate that the number of gears will never change.
Local Variables Similar to how an object stores its state in fields, a method will often store its
temporary state in local variables. The syntax for declaring a local variable is similar to declaring a
field (for example, int count = 0;). There is no special keyword designating a variable as local; that
determination comes entirely from the location in which the variable is declared which is between
the opening and closing braces of a method. As such, local variables are only visible to the methods
in which they are declared; they are not accessible from the rest of the class.
Parameters You've already seen examples of parameters, both in the Bicycle class and in the main
method of the "Hello World!" application. Recall that the signature for the main method is public
static void main(String[] args). Here, the args variable is the parameter to this method. The important
thing to remember is that parameters are always classified as "variables" not "fields". This applies to
other parameter-accepting constructs as well (such as constructors and exception handlers) that you'll
learn about later in the tutorial.
Having said that, the remainder of this tutorial uses the following general guidelines when discussing fields
and variables. If we are talking about "fields in general" (excluding local variables and parameters), we may
simply say "fields". If the discussion applies to "all of the above", we may simply say "variables". If the
context calls for a distinction, we will use specific terms (static field, local variables, etc.) as appropriate.
You may also occasionally see the term "member" used as well. A type's fields, methods, and nested types
are collectively called its members.
Naming
Every programming language has its own set of rules and conventions for the kinds of names that you're
allowed to use, and the Java programming language is no different. The rules and conventions for naming
your variables can be summarized as follows:
Variable names are case-sensitive. A variable's name can be any legal identifier an unlimited-
length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the
underscore character "_". The convention, however, is to always begin your variable names with a
letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You
may find some situations where auto-generated names will contain the dollar sign, but your variable
names should always avoid using it. A similar convention exists for the underscore character; while
it's technically legal to begin your variable's name with "_", this practice is discouraged. White space
is not permitted.
Subsequent characters may be letters, digits, dollar signs, or underscore characters. Conventions (and
common sense) apply to this rule as well. When choosing a name for your variables, use full words
instead of cryptic abbreviations. Doing so will make your code easier to read and understand. In
many cases it will also make your code self-documenting; fields named cadence, speed, and gear, for
example, are much more intuitive than abbreviated versions, such as s, c, and g. Also keep in mind
that the name you choose must not be a keyword or reserved word.
If the name you choose consists of only one word, spell that word in all lowercase letters. If it
consists of more than one word, capitalize the first letter of each subsequent word. The names
gearRatio and currentGear are prime examples of this convention. If your variable stores a constant
value, such as static final int NUM_GEARS = 6, the convention changes slightly, capitalizing every
letter and separating subsequent words with the underscore character. By convention, the underscore
character is never used elsewhere.

7.
Tokens can be used where we want to break an application into tokens. We have to break a String into
tokens as well as we will know how many tokens has been generated. That's what we are trying to do in
this program. In the program a string is passed into a constructor of StringTokenizer class.
StringTokenizer is a class in java.util.package. We are using while loop to generate tokens. The following
methods have been used in this program.
countTokens(): It gives the number of tokens remaining in the string.
hasMoreTokens(): It gives true if more tokens are available, else false.
nextToken(): It gives the next token available in the string.
To break a string into tokens what we need first is to create a class named StringTokenizing. Inside this
class we will declare our main method. Make an object of class StringTokenizer and pass one string
inside the constructor which you want to break into tokens. By using the instance of StringTokenizer call
the method countTokens() which gives the number of tokens remaining in the string. It is a method of
StringTokenizer class. If the object have more tokens available then it will call method
hasMoreTokens() and print the tokens by using nextToken().
The code of the program is given below:
import java.util.*;

public class StringTokenizing{
public static void main(String[] args) {
StringTokenizer stringTokenizer = new
StringTokenizer("You are tokenizing a string");
System.out.println("The total no. of tokens
generated : " + stringTokenizer.countTokens());
while(stringTokenizer.hasMoreTokens()){
System.out.println(stringTokenizer.nextToken());
}
}
}

8.
Reserved words in Java
The Java language uses a number of keywords such as int, char and while. A keyword has a special meaning
in the context of a Java program and can be used for that purpose only. For example, int can be used only in
those places where we need to specify that the type of some item is integer.
All keywords are written in lowercase letters only. Thus int is a keyword but Int and INT are not. Keywords
are reserved, that is, you cannot use them as your identifiers. As such, they are usually called reserved words.
Identifiers in Java
The Java programmer needs to make up names for things such as variables, method and function names and
symbolic constants (see next section). A name that he makes up is called a user identifier. There are a few
simple rules to follow in naming an identifier:
it must start with a letter (a-z or A-Z) or underscore (_) or dollar sign ($);
if other characters are required, they can be any combination of letters, digits (0-9), underscore or dollar
sign;
there is no limit to the length of an identifier.
Examples of valid identifiers:
r
R
sumOfRoots1and2
$1000
_XYZ
maxThrowsPerTurn
TURNS_PER_GAME
R2D2
root$1$2
Examples of invalid identifiers:
2hotToHandle // does not start with a letter or _ or $
Net Pay // contains a space
ALPHA;BETA //contains an invalid character ;
$1,000 //contains an invalid character ,
Important points to note:
Spaces are not allowed in an identifier. If you need one which consists of two or more words, use a
combination of uppercase and lowercase letters (as in numThrowsThisTurn) or use the underscore to
separate the words (as in num_throws_this_turn). We prefer the uppercase/lowercase combination.
In general, Java is case-sensitive (an uppercase letter is considered different from the corresponding
lowercase letter). Thus r is a different identifier from R. And sum is different from Sum is different from
SUM is different from SuM.
You cannot use a Java reserved word as one of your identifiers.


Some naming conventions
Other than the rules for creating identifiers, Java imposes no restriction on what names to use, or what format
(uppercase or lowercase, for instance) to use. However, good programming practice dictates that some
common-sense rules should be followed.
An identifier should be meaningful. For example, if its a variable, it should reflect the value being stored in
the variable; netPay is a much better variable than x for storing someones net pay, even though both are
valid. If its a method/function, it should give some indication of what the method is supposed to do;
playGame is a better identifier than plg.
It is a good idea to use upper and lower case combinations to indicate the kind of item named by the
identifier. In this series, we use the following conventions:
A variable is normally written in lowercase, for example, sum. If we need a variable consisting of two or
more words, we start the second and subsequent words with an uppercase letter, for example, voteCount or
sumOfSeries.
A symbolic (or named) constant is an identifier which can be used in place of a constant such as 100.
Suppose 100 represents the maximum number of items we wish to process in some program. We would
probably need to use the number 100 in various places in the program. But suppose we change our mind and
want to cater for 500 items. We would have to change all occurrences of 100 to 500. However, we would
have to make sure that we do not change an occurrence of 100 used for some purpose other than the
maximum number of items (in a calculation like principal*rate/100, say).
To make it easy to change our mind, we can set the identifier MaxItems to 100 and use MaxItems whenever
we need to refer to the maximum number of items. If we change our mind, we would just need to set
MaxItems to the new value. We will begin a symbolic constant with an uppercase letter. If it consists of
more than one word, we will begin each word with uppercase, as in MaxThrowsPerTurn.

9.
There used to be a time when you called "Information" on the phone and you heard a real, honest-to-goodness voice. All
that is done with. Now you talk to a computer, and the funny thing about computers is that they have no ears. So when I
call up and, for example, ask for the number to Annie's Pizza, it's little surprise that the operator comes back to me with
the number to Danny's Pizza, no matter how much emphasis I place on the A in Annie.
Unlike modern computer operators, Java Operators aren't annoying, and like the phone operators of old, are actually
helpful. You have used operators your entire life, and their function is simple: they allow you to manipulate data. And let's
face it, what good is data if you can't manipulate it?
There are several types of operators, but before we go into them, you should understand a little thing we in the biz call
operator precedence. Precedence determines in which order operators execute. If that's not clear, it will be in a few
moments.
But first, look at this beautiful table designed by yours truly:

Operator Type Operator Precedence
postfix expr++ expr--
unary ++expr expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<=
>>= >>>=

UNARY OPERATORS
In this example we will see how we can make use of the unary operator. In java we have been provided the
unary operators so we should know how to make use of those operators. Unary operators are:
++expr, --expr, +expr, -expr, ~, !
Description of program:
In this section we will know how to make use of the unary operators in java. First all of, we have to define
a class "UnaryOperation" . Inside this class we have defined one class variable. We are making one
overloaded main method which takes one integer type argument. Define one method operate() of type int
where we are going to use the various unary operators. At last inside the main method call the method
operate() so that the result can be displayed to the user. The output will be displayed on the screen by
using the println() method of the System class.
Here is the code of this program
class UnaryOperation {
public static int i=0;
public static void main(int i){
i=i;
}
public static int operate(){
int i = +1;
System.out.println(i);
i--;
System.out.println(i);
i++;
System.out.println(i);
i = ++i;
System.out.println(i);
boolean success = false;
System.out.println(!success);
System.out.println(success);
return 0;
}
public static void main(String args[])
{
UnaryOperation uo= new UnaryOperation();
int i=uo.operate();
}
}

BINARY OPERATORS IN JAVA

1- The AND operator : (&)
Code:

x y x&y
-----------------------------
0 0 0
0 1 0
1 0 0
1 1 1

Example on & operator
Code:

byte x = 50;
byte y = 51;
byte result = (byte) (x&y);
System.out.println("Result of x&y= : " + result );


The result equal = 50

00110010
00110011
-------------
00110010

2- The OR operator : (|)
Code:

x y x|y
-----------------------------
0 0 0
0 1 1
1 0 1
1 1 1


Example on | operator
Code:

byte x = 50;
byte y = 51;
byte result = (byte) (x|y);
System.out.println("Result of x|y= : " + result );


The result equal = 51

00110010
00110011
-------------
00110011

3- The XOR operator : (^)
Code:

x y x^y
-----------------------------
0 0 0
0 1 1
1 0 1
1 1 0


Example on ^ operator
Code:

byte x = 50;
byte y = 51;
byte result = (byte) (x^y);
System.out.println("Result of x^y= : " + result );


The result equal = 1

00110010
00110011
-------------
00000001


4- The Inversion Operator: (~)
Invert each bit in the byte .

Example :
Code:
~00110010 = 11001101

10.
Java is multi platform-> Platform Independent Language, so its used widely in very big softwares or games
where multiple variables needed. To Differentiate among that huge no of variables,,Java is Case Sensitive.
Whether a programming language should be case sensitive or not tends to divide opinion amongst
programmers. Regardless of the debate it's important to remember that Java is case sensitive.
What Does Being Case Sensitive Mean?
It simply means that the case of the letters in your Java programs matter. For example, suppose you decide to
create three variables called "endLoop", "Endloop", and "EnDlOoP".
Even though in English we see the variable names as saying the same thing, Java does not. It will treat them
all differently.
Case Sensitive Tips
If you follow these tips when coding in Java you should avoid the most common case sensitive errors:
Java keywords are always written in lowercase. You can find the full list of keywords in the reserved
words list.

Avoid using variable names that only differ in case. Like the example above, if I did have three variables
called endLoop, Endloop, and EnDlOoP it would not take much for me to mistype one of their
names. I then might find my code changing the value of the wrong variable by mistake.
Always make sure the class name in your code and java filename match.
Follow the Java naming conventions. If you get into the habit of using the same case pattern for different
identifier types then the chances of you not making a typing mistake will increase.
When using a string to represent the path of a filename, i.e. "C:\JavaCaseConfig.txt" make sure you use
the right case. Some operating systems are case insensitive and don't mind that the filename isn't exactly
right. However, if your program is used on an operating system that is case sensitive it will produce a
runtime error.

Vous aimerez peut-être aussi