Вы находитесь на странице: 1из 15

Contents

1. First program in JAVA


2. Data types in JAVA
3. Operators in JAVA
4. Input/output in JAVA
First Program in JAVA

import java.io.*;
class nitw{
public static void main(String args[]){
System.out.println("Hello Java");
}
}

To compile: javac nitw.java


To execute: java nitw

When we compile Java program using javac tool, java compiler converts the source
code into byte code.The bytecode name is same as class name
and is platform independent.
First Program in JAVA
Parameters used in First Java Program
class nitw{
public static void main(String args[]){
System.out.println("Hello Java");
}
}

Meaning of class, public, static, void, main, String[], System.out.println().

•class keyword is used to declare a class in java.


•public keyword is an access modifier which represents visibility. It means it is visible to all.
•static is a keyword. If we declare any method as static, it is known as the static method. The core
advantage of the static method is that there is no need to create an object to invoke the static
method.
•void is the return type of the method. It means it doesn't return any value.
•main represents the starting point of the program.
•String[] args is used for command line argument.
•System.out.println() is used to print statement. Here, System is a class, out is the object of
PrintStream class, println() is the method of PrintStream class.
Datatype in java
Data types specify the different sizes and values that can be stored in the variable. There are
two types of data types in Java:

Primitive data types: The primitive data types include boolean, char, byte, short, int, long,
float and double.

Non-primitive data types: The non-primitive data types include Classes, Interfaces, and
Arrays.
Datatype in java
Java Primitive Data Types
In Java language, primitive data types are the building blocks of data manipulation. These
are the most basic data types available 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
Datatype in java

Primitive Data Types Size and Default Values


Datatype in java

Java Non Primitive Data Types


Non-primitive, or reference data types, are the more sophisticated members of the data
type family. They don't store the value, but store a reference to that value. The default value
of any reference variable is null.

Following are non primitive data type

1. Class
2. Object
3. String
4. Array
5. Interface
Operators in java

Operator in java is a symbol that is used to perform operations.


.

There are many types of operators in java which are given below:

•Unary Operator,
•Arithmetic Operator,
•Shift Operator,
•Relational Operator,
•Bitwise Operator,
•Logical Operator,
•Ternary Operator and
•Assignment Operator
Operators in java
Java operator precedence

.
TAKING INPUT IN JAVA
Taking input in java

1) SCANNER CLASS

2)BUFFERREADER AND
INPUTSTREAMREADER CLASS
Scanner Class

Scanner is a class in java.util package used for


obtaining the input of the primitive types like int,
double etc. and strings. It is the easiest way to
read input in a Java program, though not very
efficient if you want an input method for
scenarios where time is a constraint like in
competitive programming.
Scanner Class

code:-

import java.util.Scanner;
class prac
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();
System.out.println("You entered " + number);

}
}
BUFFERREADER AND
INPUTSTREAMREADER CLASS

STEP 1:- An InputStreamReader object is responsible for obtaining a


stream of bytes from the keyboard, and converting them to characters
for the java program to read.

STEP 2:- A BufferedReader object can be initialized using an


InputStreamReader object within the constructor(or any other subclass
of java.io.Reader). The job of the BufferedReader is to "Buffer" input
from the underlying Reader object, for effecient uselater (such as
initialization of Strings, arrays and so on).
BUFFERREADER AND
INPUTSTREAMREADER CLASS
code:-

import java.io.BufferedReader;
import java.io.InputStreamReader;
class prac
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int i = Integer.parseInt(br.readLine());
System.out.println("You entered string " + s);
System.out.println("You entered integer " + i);

Вам также может понравиться