JAVA
Java Authors: James , Arthur Van
Java is object oriented programming language developed by sun micro systems.there are different type of programming languages but java is unique among them.With Java a developer can write an application and run that on different operating systems including windows, MAC OS without any modification in the code.
When developing an application in an programming language the source code is passed through a compiler that transforms the code into a set of native instructions. The compiler converts the source code into instructions which the processor can understand but when writing Java application the developer does not need to directly call windows or other operating system library function.
Features Of Java
(1) Simple
- Java is a simple language. Many features of C and C++ that are either redundant or sources of unreliable code are not part of Java.According to Sun Microsystem, Java language is a simple programming language because Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc.
(2) Familiar
- Familiarity is another feature of Java. To make the language look familiar to the existing programmers, it was modelled on C and C++ languages. Java uses many constructs of C and C++ and therefore, Java code "looks like a C++" code. In fact, Java is a simplified version of C++.
(3) Object Oriented
- Java is true object oriented language.almost everything in java is an object.it's provides concepts like Inheritance,Abstraction,Encaptulation,Polumorphism.so these concept allow to make develppment easier and maintable.
(4) Multithreaded
- Multithreaded means handling multiple tasks simultaneously. Java supports multithreaded programs. This means that we need not wait for the application to finish one task before beginning another. The Java runtime comes with tools that support multi process synchronization and construct smoothly running interactive systems
(5) Better Performance
- Java performance is impressive for an interpreted language, mainly due to the use of intermediate byte code. According to Sun, Java speed is comparable to the native C/C++.
(6) Platform Independence
- The meaning of platform-independent is that the java compiled code(byte code) can run on all operating systems. programs are compiled into byte code and that byte code is platform-independent. Any machine to execute the byte code needs the Java Virtual Machine.
(7) Secure
- Security becomes an important issue for a language that is used for programming on Internet. Threat of viruses and abuse of resources are everywhere. Java systems not only verify all memory access but also ensure that no viruses are communicated with an applet.
(8) Robust
- Java is robust language. It provides many safeguards to ensure reliable code. It has strict compile time and run time checking for data types.
Structure of Java program
Documentation Section
This section contains set of comments. We can write comment in java within two ways:
Line comment - //
Block Comment - /* */
Documentation Comment is new comment in java - /** */
Package Statement
This statement declare the package name and inform the compiler that classes .declared is contain into this package
Ex: package student;
Import Statement
This is similar to the #include statement in the c language. It instruct to the interpreter to load the class contained in the given package.This statement instruct the interpreter to load the test class contained in the student package.
Ex: import java.util.*;
Interface Statement
An interface is like a class but include group of methods. Interface is a new concept of java. This is optional and implement when we want to implement multiple inheritance
Class Defination
Classes are primary and essential elements of java. Class keyword is used to declare the class. Declare multiple classes in a java program.class is created using class keyword in java.
Main method class
It is essential part of java program. It is starting point of java program. The main method creates objects of various classes and establishes communication between them. On reaching the end of main, the program terminate and the control passes back to the operating system
Example of Java program
public class A
{
public static void main(String args[])
{
System.out.println(“Hello”);
}
}
Class = Keyword5
Public= Access specifier
Static = Keyword
Void = type of modification, it doesn’t returns value
(String args[]) = array of string type
System.out.println(“Hello”); = Output line
System. = class
out. = Object
println = method or functionOperators in Java
Operator in Java is a symbol that is used to perform operations. For example: +, -, *, / etc.
There are many types of operators in Java which are given below:
(1) Unary Operator
The Java unary operators require only one operand. Unary operators are used to perform various operations i.e.:
incrementing/decrementing a value by one
negating an expression
inverting the value of a boolean
Example:
public class OperatorExample
{
public static void main(String args[])
{
int x=10;
System.out.println(x++);//10 (11)
System.out.println(++x);//12
System.out.println(x--);//12 (11)
System.out.println(--x);//10
}
}
(2) Arithmetic Operator
Java arithmetic operators are used to perform addition, subtraction, multiplication, and division. They act as basic mathematical operations.
Example:
public class OperatorExample
{
public static void main(String args[])
{
int a=10;
int b=5;
System.out.println(a+b);//15
System.out.println(a-b);//5
System.out.println(a*b);//50
System.out.println(a/b);//2
System.out.println(a%b);//0
}
}
(3) Assignment Operator
Java assignment operator is one of the most common operators. It is used to assign the value on its right to the operand on its left.
Example:
public class OperatorExample
{
public static void main(String args[])
{
int a=10;
int b=20;
a+=4;//a=a+4 (a=10+4)
b-=4;//b=b-4 (b=20-4)
System.out.println(a);
System.out.println(b);
}
}
(4) Relational Operator
Relational Operators in Java are used to comparing two variables for equality, non-equality, greater than, less than, etc. Java relational operator always returns a boolean value – true or false.
Example:
public class OperatorExample
{
public static void main(String args[])
{
int a = 10;
int b = 20;
System.out.println(a == b);
System.out.println(a != b);
System.out.println(a > b);
System.out.println(a < b);
System.out.println(a >= b);
System.out.println(a <= b);
}
}
(5) Logical Operator
Logical operators are used to check whether an expression is true or false. They are used in decision making.
Example:
public class OperatorExample
{
public static void main(String args[])
{
// && operator
System.out.println((5 > 3) && (8 > 5)); // true
System.out.println((5 > 3) && (8 < 5)); // false
// || operator
System.out.println((5 < 3) || (8 > 5)); // true
System.out.println((5 > 3) || (8 < 5)); // true
System.out.println((5 < 3) || (8 < 5)); // false
// ! operator
System.out.println(!(5 == 3)); // true
System.out.println(!(5 > 3)); // false
}
}
(6) Ternary Operator
The ternary operator (conditional operator) is shorthand for the if-then-else statement. For example,
variable = Expression ? expression1 : expression2
Example:
public class OperatorExample
{
public static void main(String args[])
{
int februaryDays = 29;
String result;
result = (februaryDays == 28) ? "Not a leap year" : "Leap year";
System.out.println(result)
}
}
(7) Bitwise Operator
In Java, bitwise operators perform operations on integer data at the individual bit-level. Here, the integer data includes byte, short, int, and long types of data
Example:
public class OperatorExample
{
public static void main(String args[])
{
int a=10;
int b=5;
int c=20;
System.out.println(a<b&&a++<c);//false && true = false
System.out.println(a);//10 because second condition is not checked
System.out.println(a<b&a++<c);//false && true = false
System.out.println(a);//11 because second condition is checked
}
}
Comments
Post a Comment