Skip to main content

Command Palette

Search for a command to run...

First Java Program - Input/Output Part-1

Updated
4 min read
First Java Program - Input/Output   Part-1
J
Jibachh Singh is a Software Engineer and Full Stack Developer with a passion for DevOps, Docker, and cloud technologies. I completed my bachelor's degree in a B.Sc.CSIT from Tribhuvan University. With experience in Laravel, automation, and CI/CD, I Am currently taking the 90-Day DevOps Challenge to enhance my skills and enjoy building scalable applications and exploring new tech trends.

Introduction

Java is a versatile, object-oriented programming language known for its platform independence. Java is widely used in web development, mobile app development, desktop applications , and enterprise software. It's also available in open-source implementations like OpenJDK.

In this bloggs we cover alots of things , we look into how to code in java, what is classes, comments and how to code in intellij idea or more

Creating .java file

In java one things that I mention that every things you gone writing in Java. It's gone be a classes. every files with the extension of .java it's a class itself.

.java file involves writing Java code, saving it with a .java extension, and compiling it using javac . Then, you can run the Java program with the java command.

firstprogram.java

Creating Main Function:

The main function basically Means where the program will start. In Java, if there is no main function you will not be able to run the program.

 public static void Main(string[] args){

}
// this is main function in java

Writing first code (print "hello world");


public class Main{
public static void main(string[] args){
System.out.println("Hello World!");
  }
}

Converting .java to .class(Byte Code)

one's you install JDK you will get javac

~javac Main.java
~java Main

// output: Hello World!

How to change the location of the byte code?

you can change the location where the bytecode (.class files) is generated during compilation by specifying the output directory using the -d option with the javac command.

~javac -d /path/to/output/directory YourJavaFile.java

-d flags => this is basically asking for a particular location where you want to store the bytecode(.class file)

Starting with Intellij's idea

  1. Download and Install IntelliJ IDEA:

  2. Launch IntelliJ IDEA:

    • After installation, launch IntelliJ IDEA.
  3. Configure IntelliJ IDEA:

    When you first start IntelliJ IDEA, you'll be prompted to configure the IDE settings. You can choose the default settings or customize them based on

  4. Following steps :

  5. Click project

  6. Select the latest version

  7. Open JDK

  8. Click Project from the Template

  9. Create a file

  10. Finish.......

    package com.jibachh
    public class Main{
    public static void main{Strings[] agrs){
    
    // write your code here
      }
    }
    

some Shortcut of Intellij idea:

ActionShortcut
Search everywhereDouble + Shift
Go to fileCtrl + Shift + N
Go to classCtrl + N
Go to symbolCtrl + Alt + Shift + N
Go to declarationCtrl + B

FQA:

  1. what is package?

    \=> A package is a way to organize and group related classes and interfaces.

  2. what is system.out.println()?

    \=> System.out.println() is a Java statement that is used to print text or output to the console.

  3. what is output in java?

    \=> A Printstream adds functionality to another output stream , namely the ability to print representation of various data values, conveniently.

  4. what is input in java?

    \=> "input" refers to the process of obtaining data or information from external sources, typically from the user, a file, a network connection, or another program

  5. what is class in java?

    \=>class in name group of Propertices and function.

  6. what is static in java?

    \=>static is used to create variables and methods that belong to the class itself.

  7. what is public in java?

    \=> Public means that this class is access from everywhere.

  8. what is Main function in java?

    \=> the Main function is entry of the java program

  9. what is void in java?

    \=> void is a keyword used in method declarations to indicate that the method does not return a value.

  10. what is main class in java?

    \=> Main class in java is just a name of the file name.

More from this blog

J

jibachhsingh blogs

21 posts

Consistency is found in that work whose whole and detail suit the occasion. It arises from circumstance, custom, and nature.