1. What is Java?
Java is a programming language. Java is a high-level robust, object-oriented, and safe programming language.
In 1995, Sun Microsystem created Oak, but Oak was already a registered company, so he changed the name to Java.
Now, Java is one of the most popular programming languages.
2. Why do we use Java?
- Java is compatible with a variety of platforms (Windows, Mac, Linux, and Raspberry Pi, among others.)
- A large massive community of support.
- It is a safe and efficient programming language.
- It is among the most used programming languages around the globe.
- It is simple to master and easy to make use of
- It is free and open-source.
- Permits code reuse which reduces development costs.
3. What are the applications of Java
Sun estimates that Java is used by 3 billion devices. Java is used on many devices. These are some of the devices where Java is currently used:
- Desktop applications such as media player, antivirus, acrobat reader, and the media player are all available.
- Web Applications like irctc.co.in
- Enterprise Applications, such as banking applications.
- Embedded System
- Smart Card
- Games, etc.
4. Features Of Java
The primary objective of Java is to create an easier, portable, and secure programming language that every person can learn very easily. Some important features of java are:
- Platform Independent: It can be executed on multiple platforms like Windows, Mac OS, Linux, etc. Java code is compiled by the compiler before being transformed into bytes. It is a platform-independent code since it can be executed on multiple operating systems, i.e., Write Once and Run Anywhere.
- Object-Oriented: Object-oriented refers to the way we arrange our software using a variety of objects that include both data and behavior.
Object-oriented Programming (OOPs), a method that makes software development and maintenance easier by providing some rules, is called object-oriented programming.
The basic Concepts of Opps are:
3. Secured: Java can develop a virus-free system as it is secure because Java programs run inside a virtual machine sandbox.
4. Portable: Java is portable because you can carry the Java bytecode to any platform. It doesn’t need any implementation.
5. Multi-Threading: A thread can be thought of as a separate program that executes concurrently. Multiple threads allow us to create Java programs that can handle multiple tasks simultaneously. Multi-threading has the advantage that each thread doesn’t take up memory. It shares the same memory area. Threads are essential for multi-media and Web applications.
6. Dynamic: Java is a dynamic language. Java supports the dynamic loading of classes. This means that classes can be loaded at will. It supports functions in its native languages, C and C++.Java support automatic memory management and dynamic compilation (garbage collection).
5. Java Installation
Some Systems already have java so first, we need to check by entering the command in the command prompt: ( java –version )
Note: If you get the above output and get the version then the below steps didn’t need to be executed.
For running a java program, we must download some things, the requirements are:
- Download an IDE like Eclipse, IntelliJ, Visual Studio Code, etc.
- Download and Install JDK (Java Development Kit)
- Then set the path in your system of JDK/bin directory.
6. First Java Program
Parameters used in the first program
Let’s see what is the meaning of class, public, static, void, main, String, System.out.println().
- class keyword can be used to declare a Java class.
- public Keyword is an access modifier that indicates visibility. This means that it is visible to everyone.
- static can be a keyword. Any method that is declared static is called the static method. The main advantage of the static methods is that you don’t need to create objects to invoke them. Because the main() function is executed by JVM, it doesn’t need to be invoked with an object. It saves memory.
- void indicates the return type for the method. This means that it doesn’t return any value.
- main is the start point of the program.
- String or string args are used to specify command-line argument It will be discussed in the next section.
- System.out.println() can be used to print a statement. Here, System is a class. Out is an object of PrintStream. Println() is a method from the PrintStream. In the next section, we will talk about the internal workings of System.out.println().
A name in a Java program is called the identifier, it can be a class name or method name or label name.
Rules of Identifiers
- Valid identifiers can include letters, digits and underscores.
- An underscore or a letter should be the first letter of any identifier.
- Keywords like int or while cannot be used. as identifiers.
- There is no limit on the length of an identifier. If the identifier exceeds 31 characters, some compilers may not be able to interpret it correctly.
Variables can be used to store data values.
There are many types of variables in Java.
- String– Double quotations enclose stores text such as “Hello” String values
- int stores integers (whole numbers), without decimals such as 123 and -123
- floating stores floating-point numbers with decimals such as 19.99 and -19.99
- char stores single characters such as a or b. Single quotes surround char values
- Boolean- Stores values with two states: true/false
Types Of Variable
- Local variable
- Instance variable
- Static variable
9. Data Type
Data types describe the sizes and values of variables that can be stored. Java has two data types:
1. Primitive Data Types: These primitive data types are boolean and char, byte short, int long, float, double.
2. Non-primitive Data Types or Derived: These non-primitive types are Classes and Interfaces. Arrays.
3. User-Defined Data Type
- Java Primitive Data Types
Primitive data types in Java language are the foundation of data manipulation. These are the basic data types in Java Language.
There are 8 types of primitive data types:
- boolean data type
- byte data type
- char data type
- short data type
- int data type
- long data type
- float data type
- double data type
2. Java Non-Primitive Data Types
A reference type is also called Non-primitive data types
- The primary difference between non-primitive data types and primitive is:
- Java already defines primitive types. Java does not define non-primitive types.
- Methods can be called by non-primitive types, but primitive types cannot.
- A primitive type always has a value, while nonprimitive types can be NULL.
- Primitive type begins with a lowercase letter. Non-primitive types start with an uppercase letter.
- Primitive types are smaller than non-primitive ones.
Strings, Arrays, Classes, and Interfaces are some examples of the non-primitive type.