Computer STKBHT
Computer STKBHT
These days, most major software development is performed using OOP. Thanks to
the widespread use of languages like Java and C++, you can’t develop software for
mobile unless you understand the object-oriented approach. The same goes for web
development, given the popularity of OOP languages like Python, PHP and Ruby.
That said, many developers start off with top-down languages like Visual Basic or
JavaScript.
You may be used to breaking down large problems into sub-problems and solving
them in separate units of code. Or you may have experience with functional
programming, which treats elements of code as precise mathematical functions, and
prevents them from affecting other elements — that is, no side effects. Come to grips
with OOP, however, and you’ll see that it offers a whole new way of solving
problems.
With OOP, instead of writing a program, you create classes. A class contains both
data and functions. When you want to create something in memory, you create an
object, which is an instance of that class. So, for example, you can declare a
Customer class, which holds data and functions related to customers. If you then
want your program to create a customer in memory, you create a new object of the
Customer class.
That’s the beauty of encapsulation. Objects are self-contained, and each bit of
functionality does its own thing while leaving the other bits alone. Also, this
modularity allows an IT team to work on multiple objects simultaneously while
minimizing the chance that one person might duplicate someone else’s functionality.
2. Reuse of code through inheritance
Suppose that in addition to your Car object, one colleague needs a RaceCar object,
and another needs a Limousine object. Everyone builds their objects separately but
discover commonalities between them. In fact, each object is just a different kind of
Car. This is where the inheritance technique saves time: Create one generic class
(Car), and then define the subclasses (RaceCar and Limousine) that are to inherit
the generic class’s traits.
Of course, Limousine and RaceCar still have their unique attributes and functions. If
the RaceCar object needs a method to “fireAfterBurners” and the Limousine object
requires a Chauffeur, each class could implement separate functions just for itself.
However, because both classes inherit key aspects from the Car class, for example
the “drive” or “fillUpGas” methods, your inheriting classes can simply reuse existing
code instead of writing these functions all over again.
What if you want to make a change to all Car objects, regardless of type? This is
another advantage of the OOP approach. Make a change to your Car class, and all
car objects will simply inherit the new code.
This isn’t to say that OOP is the only way to write software. But there’s a reason that
languages like C++, C# and Java are the go-to options for serious software
development.
Unicode System
Unicode provides a unique number for every character, no matter what the platform,
no matter what the language, no matter what the program. Example – A = U + 0041,
B = U + 0042, C = U + 0043, D = U + 0044.
The Unicode system has been adopted by such industry leaders like Apple, HP, IBM,
Just Systems, Microsoft, Oracle and many others. Unicode is required by modern
standards such as XML, JAVA, ECMAScript (JavaScript), COBRA 3.0, WML, LDAP
etc., and is the official way to implement ISO/IEC 10646. It is supported in many
Operating Systems, all modern browsers, and many other products. The emergence
of the Unicode standard, and the availability of tools supporting it, are among the
most significant recent global software technology trends.
Incorporating Unicode into client-server or multi-tiered applications and websites
offers significant cost savings over the use of legacy character sets. Unicode enables
a single software product or a single website to be targeted across multiple
platforms, languages and countries without re-engineering. It allows data to be
transported through many different systems without corruption.
Unicode and ASCII code are both ways that computer languages store characters as
numbers. ASCII stands for “American Standard Code for Information Interchange”
and it allows encoding for 128 characters. This is fine for English language, but not
enough for others. Unicode can handle 100,000 characters, so by using this encoding
scheme, JAVA allows programmers to work with printed languages from around the
world.
In the above code snippet, public, class, Demo, {, static, void, main, (, String, args,
[, ], ), System, ., out, println, javatpoint, etc. are the Java tokens.
Play Video
The Java compiler translates these tokens into Java bytecode. Further, these bytecodes
are executed inside the interpreted Java environment.
Literals, Identifiers, Punctuators,
Separators, Operators in Java
Types of Tokens
Java token includes the following:
o Keywords
o Identifiers
o Literals
o Operators
o Separators
o Comments
Keywords: These are the pre-defined reserved words of any programming language.
Each keyword has a special meaning. It is always written in lower case. Java provides
the following keywords:
01. abstract 02. Boolean 03. byte 04. break 05. class
06. case 07. catch 08. char 09. continue 10. default
21. import 22. instanceof 23. int 24. interface 25. long
26. native 27. new 28. package 29. private 30. protected
31. public 32. return 33. short 34. static 35. super
36. switch 37. synchronized 38. this 39. thro 40. throws
41. transient 42. try 43. void 44. volatile 45. while
46. assert 47. const 48. enum 49. goto 50. strictfp
Identifier: Identifiers are used to name a variable, constant, function, class, and array.
It usually defined by the user. It uses letters, underscores, or a dollar sign as the first
character. The label is also known as a special kind of identifier that is used in the goto
statement. Remember that the identifier name must be different from the reserved
keywords. There are some rules to declare identifiers are:
o The first letter of an identifier must be a letter, underscore or a dollar sign. It cannot
start with digits but may contain digits.
o The whitespace cannot be included in the identifier.
o Identifiers are case sensitive.
1. PhoneNumber
2. PRICE
3. radius
4. a
5. a1
6. _phonenumber
7. $circumference
8. jagged_array
9. 12radius //invalid
o Integer
o Floating Point
o Character
o String
o Boolean
Literal Type
23 int
9.86 double
"javatpoint" String
Operators: In programming, operators are the special symbol that tells the compiler
to perform a special operation. Java provides different types of operators that can be
classified according to the functionality they provide. There are eight types
of operators in Java, are as follows:
o Arithmetic Operators
o Assignment Operators
o Relational Operators
o Unary Operators
o Logical Operators
o Ternary Operators
o Bitwise Operators
o Shift Operators
Operator Symbols
Arithmetic +,-,/,*,%
Unary ++ , - - , !
Assignment = , += , -= , *= , /= , %= , ^=
Relational ==, != , < , >, <= , >=
Logical && , ||
Bitwise &,|,^,~
Separators: The separators in Java is also known as punctuators. There are nine
separators in Java, are as follows:
Pause
Unmute
1. separator <= ; | , | . | ( | ) | { | } | [ | ]
Note that the first three separators (; , and .) are tokens that separate other tokens,
and the last six (3 pairs of braces) separators are also known as delimiters. For
example, Math.pow(9, 3); contains nine tokens.
o Square Brackets []: It is used to define array elements. A pair of square brackets
represents the single-dimensional array, two pairs of square brackets represent the
two-dimensional array.
o Parentheses (): It is used to call the functions and parsing the parameters.
o Curly Braces {}: The curly braces denote the starting and ending of a code block.
o Comma (,): It is used to separate two values, statements, and parameters.
o Assignment Operator (=): It is used to assign a variable and constant.
o Semicolon (;): It is the symbol that can be found at end of the statements. It separates
the two statements.
o Period (.): It separates the package name form the sub-packages and class. It also
separates a variable or method from a reference variable.
Comments: Comments allow us to specify information about the program inside our
Java code. Java compiler recognizes these comments as tokens but excludes it form
further processing. The Java compiler treats comments as whitespaces. Java provides
the following two types of comments:
The names of the integer types and their sizes in each of the two data models are
shown in the following table. Integers are always represented in twos-complement
form in the native byte-encoding order of your system.
Integer types may be prefixed with the signed or unsigned qualifier. If no sign
qualifier is present, the type is assumed to be signed. The D compiler also provides
the type aliases listed in the following table:
These type aliases are equivalent to using the name of the corresponding base type
in the previous table and are appropriately defined for each data model. For
example, the type name uint8_t is an alias for the type unsigned char.
See Chapter 8, Type and Constant Definitions for information on how to define
your own type aliases for use in your D programs.
D also provides the special type string to represent ASCII strings. Strings are
discussed in more detail in Chapter 6, Strings.
we can apply these unary operators on all primitive types except Boolean.
Syntax:
class PreIncrement {
}
Output:
y value is: 11
On the above example, pre increment operator is applied on x operand, here
first the value of x will be incremented by 1 and then the incremented value will
be assigned to the variable y .
As per example, the initial value of ‘x’ is 10. After applying pre-increment
operator on ‘x’ the value of ‘x’ is incremented by 1 (i.e., 11) and that value is
assigned to the variable ‘y’. So that the final value of ‘y’ is 11.
Post Increment Operator:
If an Increment operator is used after an operand, then is called Post Increment
operator.
Syntax:
class PostIncrement {
}
Output:
y value is: 10
Post increment operator is applied on ‘x’, here the case is exact opposite of pre
increment, first the value of variable ‘x’ is assigned to the variable ‘y’ and then
the value of ‘x’ is incremented by 1 .
As per example, the initial value of ‘x’ is 10. After applying post-increment
operator the current values of ‘x’ (i.e, 10) is assigned to y, and then the value
of ‘x’ is incremented by 1. So when displaying variable ‘y’ it is showing as 10.
Syntax:
class PreDecrement {
public static void main(String[] args) {
int x = 10;
int y = --x;
System.out.println("y value is: " + y);
}
}
Output:
y value is: 9
Pre decrement operator is applied on ‘x’, first, the value of ‘x’ will be
decremented by 1 and then the decremented value will be assigned to the
variable ‘y’.
As per example, the initial value of ‘x’ is 10. After applying pre decrement
operator on ‘x’, the value of ‘x’ is decremented by 1 (i.e., 9) and that value is
assigned to the variable ‘y’. So, when we display the variable ‘y’ it is showing as
9.
y value is: 10
Post decrement operator is applied on ‘x’, here the case is the complete
opposite of pre decrement operator, first, the value of variable ‘x’ is assigned to
the variable ‘y’ and then the value of ‘x’ is decremented by 1.
Syntax:
As per example, the initial value of ‘x’ is 10. After applying post decrement
operator on variable ‘x’ the current values of ‘x’ (i.e, 10) is assigned to ‘y’, and
then the value of ‘x’ is decremented by 1. So when displaying the value of ‘y’ it is
showing as 10.
class IncAndDecOperatorsDemo {
class IncAndDecOperatorsDemo {
public static void main(String[] args) {
int x = 100;
int y = --(--x);
System.out.println("Value of y : " + y);
class IncAndDecOperatorsDemo {
class IncAndDecOperatorsDemo {
}
Output:
Value of x : 10
The Step by Step Analysis on Output:
STEP 2 : The value of ‘x’ is post incremented and assigned again to ‘x’.
The variable ‘x’ will be incremented first but the previous ‘x’ value (10) is
assigned again to ‘x’ variable, and the incremented (11) value will be used after
assigning. But in this example, the next value of ‘x’ is overridden by previous
value (10) always.
STEP 3: The value of ‘x’ is post incremented and assigned to ‘x’ only.
STEP 4: The value of ‘x’ is post incremented and assigned to ‘x’ only.
STEP 5: The value of ‘x’ is post incremented and assigned to ‘x’ only.
Example 2:
class IncrementOperator {
}
Output:
Value of x : 18
The Step by Step Analysis on Output: