Java programming input-output Examples

Codeswithbaby
3 min readAug 29, 2022
Java programming input-output Examples

Getting user input/Output in Java Programming Language

Java input output: While Java provides many different methods for getting user input, the Scanner object is the most common, and perhaps the easiest to implement. java input-output function in the java language. java input-output function can be used to get the input from the keywords.

To use the Scanner class, create an instance of the class by using the following syntax:

import java.util.Scanner;

Scanner scannerexample = new Scanner(System.in);

You can now read different kinds of input data that the user enters.

Here are some methods that are available through the Scanner class:

1. Read a byte — nextByte()

2. Read a short — nextShort()

3. Read an int — nextInt()

4. Read a long — nextLong()

5. Read a float — nextFloat()

6. Read a double — nextDouble()

7. Read a boolean — nextBoolean()

8. Read a complete line — nextLine()

9. Read a word — next()

Example: Write a program used to get user input in Java Language

import java.util.Scanner;

class MyClass {

public static void main(String[ ] args) {

Scanner inputSomething = new Scanner(System.in);

System.out.println(inputSomething.nextLine());

}

}

How to install java runtime environment

Java is available for free on Oracle’s website.

How to download java on windows

Click Here Java Download

Select a version related to your Operating System

Follow the instructions to download and install java.

Once installed you have to set up an environment variable to point to the installation directory.

Java_home environment variable windows 10

If you installed java in

C:\\Program Files\\java\\jdk\\ directory

Right-click on ‘This PC’ or ‘My Computer and select ‘Properties’.

Click the ‘Environment variables’ button under the ‘Advanced’ tab

Now, change the ‘Path’ variable so that it also contains the path to the Java executable.

For example, if the path is currently set to

C:\\WINDOWS\\SYSTEM32

then change your path to read

C:\\WINDOWS\\SYSTEM32;C:\\Program Files\\java\\jdk\\bin

Java_home environment variable Linux

Environment variable PATH is automatically set to point to where the Java binaries have been installed.

If PATH is not set, then you can set it by adding the following line to the end of your ‘.bashrc: export PATH = /path/to/java:$PATH’. if you use bash as a shell.

Java_home environment variable mac

Set JAVA_HOME using this command in Terminal: export JAVA_HOME=/Library/Java/Home

echo $JAVA_HOME on Terminal to confirm the path

You should now be able to run your application.

Best software for java programming

Popular Integrated development environment(IDE) for Java :

NetBeans: NetBeans IDE is free, open-source, and has a worldwide community of users and developers. Available for Windows, Linux, and Mac.

Eclipse: Java IDE developed by the eclipse open-source community.

IntelliJ IDEA: Intelligent java IDE which is also used by Google. Android Studio IDE by Google is based on IntelliJ IDEA.

BlueJ: BlueJ is a free Java development environment designed for beginners. It is also supported by Oracle

Best Text editor for java programming language

Notepad: Notepad is a built-in Windows text editor.

Notepad++: Open-source text editor with syntax highlighting for windows.

Gedit: Open-source text editor for Linux with syntax highlighting.

What is JDK, JRE & JVM in the Java programming language?

JDK: Java Development Kit is the one that provides the environment to develop and execute the Java program. The JDK forms an extended subset of a software development kit (SDK). It includes “tools for developing, debugging, and monitoring Java applications”. Oracle strongly suggests now using the term JDK to refer to the Java SE Development Kit. Read More

--

--