Java


About Java

Java is an Object Oriented,High level, Robust and Secured programming language. Java Applications Java Application Running on 3+ billions devices. The devices are shown as follow: Desktop Based Applications Web Based Applications Smart Card Application Robotics Application Enterprise Applications Mobile Applications Embedded System Games Application and many more…….

Java History

Java team members developed a language for digital devices such as televisions, set-top boxes etc. Now a days, Java is widely used in online programming, mobile devices, video games, e-business etc. James Gosling and his team started this project in June 1991. The team is also known as Green Team. The main task of this […]

Java Features

Simple Java language is simple because mostly syntaxlike C++ . Java removed pointers, operator overloading etc. No need Java has Automatic Garbage Collection which removes non referenced objects . Object-oriented Java is an Object-oriented programming(OOPs) .The basic features of OOPs are as follows: Object Class Inheritance Polymorphism Abstraction Encapsulation Platform Independent Java run on multiple […]

First program in Java

Open an editor like: Notepad, Sublime etc and write. class HelloWorld { public static void main(String args[]) { System.out.println(“Hello World!”); } } Save this file as “HelloWorld.java” (save as Class name) Go to command prompt: (javac for compile and java for run) D:/>javac HelloWorld.java D:/>java HelloWorld Output: D:/>java HelloWorld Hello Java D:/> Details first java […]

Java Data Types

Data Type Default Value Default size boolean false 1 bit char ‘\u0000’ 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte

Java Operators

Java Operators is a symbol which is used to perform operations. Java Operators has defined such as unary operator, arithmetic operator, relational operator, shift operator, bitwise operator, ternary operator and assignment operator. Java Arithmetic Operators Java Arithmetic operators are used to perform common mathematical operations. Operator Name Description Example + Addition Adds together two values […]

Java Keywords

A keyword is a reserved word. You cannot use it as a variable name, constant name etc. Keyword Description abstract Abstracts are used to implement an abstraction in Java. A method with no definition must be declared as abstract and the class containing it must be declared as abstract. Abstract classes cannot be instantiated. Abstract […]

Java Variables

Variable allocates reserved memory area. char ch=’A’;//chis variable int num=10;//num is variable Types of Variable Local Variable is declared inside the method. Instance Variable is declared inside the class but outside the method. Static variable is declared as with static keyword. Example: class MyVariables{ int num1=50;//instance variable static int2 m=100;//static variable void method(){ int num3=90;//local […]

Java Type Casting or Type Conversion

Type casting is when you assign a value of one primitive data type to another type. In Java, there are two types of casting: Widening Casting (automatically) – converting a smaller type to a larger type size byte -> short -> char -> int -> long -> float -> double Narrowing Casting (manually) – converting […]

Java Comments

Java Comments can be used to help for description the code. It will never show on run time. Single-line comments It starts with two forward slashes (//). class HelloWorld { public static void main(String args[]) { // This is a comment System.out.println(“Hello World!”); System.out.println(“Hello World”); // This is a comment } } Java Multi-line Comments […]

Java if else

if Statement Use the if statement to specify a block of Java code to be executed if a condition is true. if (condition) { // block of code to be executed if the condition is true } Sample program with if Write a program or WAP to find a number is greater or not. class […]

Java switch

Java switch statement is used to select one of many code blocks to be executed. switch(expression) { case x: // code block break; case y: // code block break; default: // code block } How to Java switch works: Matching each expression with case Once it match, execute all case from where it matched. Use […]

Java while

What is Loops? When we want to execute a block execute multiple time then we use loop.It executes until condition is true. The while executes a block of code as long as a given condition is true. while (condition) { // code block to be executed } Sample program with if Write a program or […]

Java do while

What is Loops? When we want to execute a block execute multiple time then we use loop.It executes until condition is true. The do – while executes a block of code as long as a given condition is true. do { // code block to be executed }while (condition); Sample program with do-while loop Write […]

Java for

What is Loops? When we want to execute a block execute multiple time then we use loop.It executes until condition is true. The for executes a block of code as long as a given condition is true. It has multiple statements. This is very popular in all loops. for (initialization; condition;increment/decrement) { // code block […]

Java break and continue

Java break Java break is keyword which is used to going out from “switch” and loops(while, do-while, for). class SampleBreak { public static void main(String args[]) { int num= 1; while (num