The original name of this programming language was Oak,a hardwood tree which was a symbol of strength. However, in 1995, Oak got a new name, Java. The programming language's team members were looking for a name that would be easy to spell and fun to say. It is a name of an island in Indonesia where the first coffee was produced.
Canadian computer scientist James Gosling is the inventor of Java and has always liked having a coffee called "Java". Eventually, he named the programming language Java.
What is Java?
Java is an object-oriented language, which means that it is a computer programming model that organizes software design around data, or objects, rather than functions and logic.Second, Java is multi-platform language which means that software, applications can be run on various platforms or systems such as Windows, Linux.Third, Java is network centric language which allows interactions between different devices or systems connected through a network.
What are the data types of Java?
There are two types of data types: primitive and non-primitive.
Primitive data types are
- byte (1 bytes) stores integers from -128 to 127
- short (2 bytes) stores integers from -32,768 to 32,767
- int (4 bytes) stores integers from -2,147,483,648 to 2,147,483,647
- long (8 bytes) stores integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
- float (4 bytes) stores fractional numbers 6 to 7 decimal digits
- double (8 bytes) stores fractional numbers 15 decimal digits
- boolean (1 bit) stores true or false values
- char (2 bytes) stores a single character
We can create variables of these data types and store different values in Java programs.
Example:
int n = 555000;
short s = 18;
double d = 3.1415;
boolean isThisReal = true;
char c = 'a';
Examples of non-primitive data types are
- Strings
- Arrays
- Classes
String represents a sequence of characters. String objects are immutable, so they cannot be changed.
Example:
String originalString = "Hello, hello";
System.out.println(originalString); // Output: Hello, hello
Array is a fixed-size sequence of elements of the same data type
Example:
int arr[];
arr = new int[5];
arr[0]=10;
arr[1]=20;
for (int i = 0; i < arr.length; i++) {
System.out.println("Element at index"+i+"is"+arr[i]);
}
Classes in java are responsible for creating objects, which are instances of the class. Classes serve as the type of the objects they create. A class defines the data and the methods of manipulating the data stored in the object (the instance of that class).
Example:
public class Student {
private String name;
private String surname;
public void printStudentFullName () {
System.out.println("My full name is " + name + " " + surname);
}
}
This was a quick introductory tour in the world of Java programming. I hope it was a good start for you!
Top comments (0)