0% found this document useful (0 votes)
3 views2 pages

Java Basics: Keywords, Data Types, Operators

The document provides an overview of fundamental Java concepts, including keywords, identifiers, data types, variables, operators, type casting, input and output, and comments. It explains the different types of data, how to declare variables, and the syntax for various operations. Additionally, it highlights the use of the Scanner class for input and the methods for outputting data to the console.

Uploaded by

himanshu20social
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Basics: Keywords, Data Types, Operators

The document provides an overview of fundamental Java concepts, including keywords, identifiers, data types, variables, operators, type casting, input and output, and comments. It explains the different types of data, how to declare variables, and the syntax for various operations. Additionally, it highlights the use of the Scanner class for input and the methods for outputting data to the console.

Uploaded by

himanshu20social
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

History and Features of Java

Java Basics

This section covers fundamental Java concepts that form the building blocks for writing Java programs.

1. **Keywords and Identifiers**

- Keywords are reserved words with predefined meanings in Java (e.g., `class`, `public`, `static`, `int`, `if`,

`else`).

- Identifiers are names given to classes, methods, variables, etc. They must begin with a letter, underscore

(_) or dollar sign ($).

2. **Data Types and Variables**

- Data types define the type of data a variable can hold.

-> Primitive: byte, short, int, long, float, double, char, boolean

-> Non-primitive: String, Arrays, Classes

- Variables store data values. Syntax: `int age = 25;`

3. **Operators**

- Java supports various operators:

-> Arithmetic: +, -, *, /, %

-> Relational: ==, !=, >, <, >=, <=

-> Logical: &&, ||, !

-> Assignment: =, +=, -=, *=, /=

-> Unary: ++, --

-> Ternary: condition ? expr1 : expr2


History and Features of Java

4. **Type Casting**

- Converting one data type to another.

-> Implicit (widening): int to long

-> Explicit (narrowing): double to int

Example: `int a = (int) 3.14;`

5. **Input and Output**

- `[Link]()` is used to print output to the console.

- To take input, use the Scanner class:

import [Link];

Scanner sc = new Scanner([Link]);

int num = [Link]();

6. **Comments in Java**

- Single-line: `// This is a single-line comment`

- Multi-line: `/* This is a

multi-line comment */`

- Used for documentation and making code more understandable.

You might also like