Sunteți pe pagina 1din 2

Basics Of Java

Java is basically an object oriented programming language

object oriented programming language

An object-oriented language is one that is built around the concept of objects. In the physical
world, take a look around the room and think of each thing as an object.

For example, In your college when you want to call particular students from you class, there are
two possibilities

1. Going to the class room and calling the students from your class with the students lists.

2. You can stick the students list in the notice board and ask the students to view the list. Here
notice board is an object and the student list has properties about students name and roll
number. Object-oriented languages allow us to define objects like notice board and access
their properties in our code. We can then create and manipulate all sorts of objects to do
different things in our app. For example, we can use the Camera object to take a photo. The
Camera object represents the physical camera on an Android phone, but in a way that we can
interact with in code.

Basic Data Types


Int = 1,2,3,4 etc (An integer value, i.e. a whole number (no decimals) that includes zero and
negative numbers.)

Float = 1.3, 2.4,3.5 (A floating point value that includes as many decimal places as it can hold.
Because the decimal place can change, or float, it’s important to know that these values may
technically be imprecise. When precise decimals are needed, like for currency, we should use
the BigDecimal data type.)


Boolean = True or False (A 1-bit true or false value that can only be in one of those states. The
Java keywords for the values are “true” and “false”, which represent 1 and 0, respectively.)

Char = a,b,c,d (A single character, such as the letter “A” or the symbol “#”. Note that lowercase )

String = “Java Basics For Android” (String data is a bunch of characters strung together to make
text, like a banner strung up at a party.)








Variables
A variable is basically a container used to hold data

For Eg:

1. The first word in a variable declaration is the data type, which tells us what kind of data the
variable will hold.

2. The second word is the name of the variable, which can be anything you want following a
few basic rules. Variable names must not contain any spaces or special characters; they

can only have letters, numbers, and underscores. They must not start with a number,
though.

3. The equals sign (=) is an operator, meaning it performs a specific operation for us. This is
the assignment operator, meaning that we use it to assign values to variables. In this
example it is assigning the text value on the right (#4) to the variable “title” on the left (#2).

4. The text in green is the String value we are working with. In Java, Strings are surrounded
with double quotes to differentiate them from regular text used in the code.

5. Finally, the last character in this line is the semicolon, which is used to finish this
statement. Semicolons in Java are like periods in sentences: we use them to indicate
when we’re done saying something. Every statement in Java must end with a semicolon
(note that a statement may be displayed on multiple lines for better readability).

Some other examples of variable declarations using some of the basic data types we covered are

as follows:

int playerNumber = 24;

float distance = 11.72011f;

boolean isEmpty = true;

char firstLetterOfName = 'B';

S-ar putea să vă placă și