- Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere.
- The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as reflection and runtime code modification) that are typically not available in traditional compiled languages.
- Java was originally developed by James Gosling at Sun Microsystems. It was released in May 1995 as a core component of Sun Microsystems' Java platform. The original and reference implementation Java compilers, virtual machines, and class libraries were originally released by Sun under proprietary licenses.
Comments can be used to explain Java code, and to make it more readable. It can also be used to prevent execution when testing alternative code.
In Java we have two type of comment
- single line comment
// this is single line comment
System.out.print("hello world!") // hello world!- multi line comment
/*
for (let i = 0; i<10; i++){
System.out.println("you are in a loop")
}
*/To run Java or to create Java file we should create file with .java extension,
In java everything run on class, under class we have a main method (function: function is who lived in outside any class, and method: a function that live in side a class), under main method we write our code
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}Variable are noting just a container that store data value
To create a variable, you should specify the type and give the value
// type variableName = data
String outputString = "Hello world"as we know we container data in variable but we need some data type to store a variable, there comes Data type
In java we have primitive Data type and Non-primitive data
byte, short, int, long, float, double, boolean and char
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = 'D'; // Character
boolean myBool = true; // Boolean
String myText = "Hello"; // Stringsuch as String, Arrays and Classes