Java is a High level programming language that produces software for multiple platforms.When a programmer writes a Java application, the compiled code (known as bytecode) runs on most operating systems (OS), including Windows, Linux and Mac OS. Java derives much of its syntax from the C and C++ programming languages.Developed by James Gosling at Sun Microsystems in 1995.
Also known as Core Java, this is the most basic and standard version of the purest form of Java, a basic foundation for all other editions
It consists of a wide variety of general purpose API’s (like java.lang, java.util) as well as many special purpose APIs
J2SE is mainly used to create applications for Desktop environment.
It consist all the basics of Java the language, variables, primitive data types, Arrays, Streams, Strings Java Database Connectivity(JDBC) and much more. This is the standard, from which all other editions came out, according to the needs of the time.
j2ME(Java Platform, Micro Edition)This version of Java is mainly concentrated for the applications running on embedded systems, mobiles and small devices.(which was a constraint before it’s development)
Constraints included limited processing power, battery limitation, small display etc.
J2ME uses many libraries and API’s of J2SE, as well as, many of it’s own.
The basic aim of this edition was to work on mobiles, wireless devices, set top boxes etc.
J2EE(Java Platform, Enterprise Edition)The Enterprise version of Java has a much larger usage of Java, like development of web services, networking, server side scripting and other various web based applications.
J2EE uses many components of J2SE, as well as, has many new features of it’s own like Servlets, JavaBeans, Java Message Services, adding a whole new functionalities to the language.
J2EE uses HTML, CSS, JavaScript etc., so as to create web pages and web services. It’s also one of the most widely accepted web development standard.
There are also many languages like .net and php, which can do that work, but what distinguishes it from other languages is the versatility, compatibility and security features, which are not that much prominent in other languages.
Java Software Development Kit (JSDK) is need for run java
Any Text Editor (Ex: notepad, notepad++, SciTE, etc.) or Any IDE (Ex: Netbeans, Eclipse,Intellij etc.)
Ecxample:
class Hello{ }
Hello.java or Bye.java=>
class Hello{ } class Bye{ }
Hello.java =>
Public class Hello{ } class Bye{ }
In order to create an application in Java, the program must have a class that defines a method or function named main, which is the starting point for the execution of any application and as follows:
public static void main( String varName[]){ //some code here }
Without main method, a program can be compiled but can not be run.
public class HelloWorld{ public static void main( String args[]){ System.out.println(“Hello World”); System.out.print(100); System.out.print(“ “); System.out.println(20.0); System.out.println(“Ends”); } } Output is as follows: Hello World 100 20.0 Ends
number, Number, sum_$, bingo, $$_100, mål, grüßExamples of Illegal Identifiers
48chevy, all@hands, grand-sum
Any constant value which can be assigned to the variable is called as literal/constant.
A literal denotes a constant value, i.e., the value that a literal represents remains unchanged in the program
Literals represent numerical (integer or floating-point), character, boolean or string values.
In addition, there is the literal null that represents the null reference
Example of LiteralsComments are for documentation purposes only and are ignored by the compiler.
Java provides 3 types of comments:
Single line comments: // Something …… Multiple line comments: /* comments on multiple lines */ A documentation Comment: /** * Developed by Company * @author : S. R. * @version 1.0 */
Java supports two data types:
Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed.
For example, Employee, Puppy etc.Class objects, and various type of array variables come under reference data type
Default value of any reference variable is null.
A reference variable can be used to refer to any object of the declared type or any compatible type.
Example : Animal animal = new Animal("giraffe");Data type | Width(bits) | Min Value | Max Value | Wrapper Class |
---|---|---|---|---|
boolean | N/A | true,false | Boolean | |
char | 16 | 0*0 | 0*ffff | Character |
byte | 8 | -27 | 27-1 | Byte |
short | 16 | -215 | 215-1 | Byte |
int | 32 | -231 | 231-1 | Integer |
long | 64 | -263 | 263-1 | Long |
float | 32 | +-1.40129846432481707e-45f | Long | |
Double | 64 | Double |
In Java, there are 3 (three) types of variable depending on the location of the variable declaration
declared inside the method or function
declared outside the method or function but inside the class
declared outside the method or function but inside the class and follows a keyword static
Instance variable and static variable will be discussed later
Syntax: data_type variable_name; [declaration] variable_name = value; [initialization]
int x,w,p,y; [declaration] x = 20; [initialization] y = 30; [initialization] int z=10;
public class HelloWorld{ int x = 10; // instance variable static int y = 20; // static or class variable public static void main( String varName[]){ int z = 30; // Local variable System.out.println(“Hello World”); } }
Syntax: data_type variableName [ ]; Or data_type [ ] variableName ;Example:
int x [ ]; // x is an Array Variable that can hold int element. int x [], y; // x is an Array Variable, but y is an int primitive. int [] x, y; // x and y both are Array Variables those can hold int element.
Syntax: variableName = new data_type [size] ; Example: x = new int [5]; // 5 consecutive memory locations are created and referred by x.
Syntax: variableName[index] = value ; Example: x [0] = 10; x [1] = 20; x [2] = x[0] + x[1]; x [3] = 40; x [4] = 50;
Syntax: data_type variableName [] = new data_type [size] ; Example: int x [] = new int [5];
Syntax: data_type variableName [ ] = { value1, ….., valueN} ;
Here, an array of size N is created. At index 0, we have value1 and at index N-1, we have valueN.
Example: int x [ ] = { 10, 20, 30, 40, 50};
class MyArray{
public static void main(String args[]){
int a [];
a =new int[3];
a[0] = 10;
a[1] = a[0]*2;
a[2] = a[1]*2;
// Printing the value of an Individual Array Element
System.out.println(a[0]);
System.out.println(a[1]);
System.out.println(a[2]);
// Printing the values of an Array using LOOP
for(int index = 0; index<a.length; index++){
// Here, "index" is the loop control variable
// and is the variable to represent INDEX
System.out.println(a[index]);
}
}
}
public class TestArray { public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5}; // Print all the array elements for (double element: myList) { System.out.println(element); } } } This would produce following result: 1.9 2.9 3.4 3.5
class TwoDArray { public static void main(String args[]) { int twoD[][]= new int[4][5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } } This program generates the following output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class TwoDAgain { public static void main(String args[]) { int twoD[][] = new int[4][]; twoD[0] = new int[1]; twoD[1] = new int[2]; twoD[2] = new int[3]; twoD[3] = new int[4]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<i+1; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<i+1; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } } This program generates the following output: 0 1 2 3 4 5 6 7 8 9
Unicode is a universal international standard character encoding that is capable of representing most of the world's written languages. |
Before Unicode, there were many language standards: |
|
This caused two problems:
|
To solve these problems, a new language standard was developed i.e. Unicode System. |
In unicode, character holds 2 byte, so java also uses 2 byte for characters. |
lowest value:\u0000 |
highest value:\uFFFF |
Modifiers are keywords that you add to those definitions to change their meanings. Java language has a wide variety of modifiers, including the following -
Java Access Modifiers
Non Access Modifiers
To use a modifier, you include its keyword in the definition of a class, method, or variable. The modifier precedes the rest of the statement, as in the following example.
public class className { // ... } private boolean myFlag; static final double weeks = 9.5; protected static final int BOXWIDTH = 42;
Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are -
Java provides a number of non-access modifiers to achieve many other functionality.
The static modifier for creating class methods and variables.
The final modifier for finalizing the implementations of classes, methods, and variables.
The abstract modifier for creating abstract classes and methods.
The synchronized and volatile modifiers, which are used for threads.
Total : 20981
Today :35
Today Visit Country :