#3 First Code in Java

#3 First Code in Java

Setting up the Environment

In this section, we will set up the development environment and write our first Java code using VS Code.

Opening VS Code

  • Open VS Code by typing "code" in the terminal.
  • Choose a color theme preference (dark is recommended for development).

Exploring VS Code

  • The left-hand side of VS Code displays folders and files.
  • Use the Explorer to navigate through files and folders.
  • Search for specific items using the search option.
  • Extensions can be added later but are not necessary at this point.

Creating a Project Folder

  • Click on "Open Folder" to create a new project folder.
  • Save the folder on your desktop or preferred location.
  • Zoom in to view everything clearly within VS Code.

Configuring Preferences

  • Uncheck the option to show welcome screen on startup.
  • Close the welcome page.

Creating the First File

  • Click on "New File" to create a new file in the project folder.
  • Name the file as "Hello.java" (Java files have a .java extension).

Writing Our First Java Code

In this section, we will write our first Java code that prints "Hello World".

Checking JDK Version

java version

javac -version

  • Verify that JDK is installed and check its version.

Writing Java Code in VS Code

public class Hello

public static void main(String[] args)

System.out.println("Hello World");

  • Write a simple Java program that prints "Hello World".

Introduction to JShell

In this section, the speaker introduces JShell, a feature introduced in Java 9 that allows for experimenting and testing code. JShell provides a prompt where code can be written and executed.

Using JShell for Code Experimentation

  • JShell is a concept introduced in Java 9.
  • It allows for writing and executing code in one line.
  • The speaker demonstrates how to open the terminal and access the JShell prompt.
  • With JShell, you can experiment with code and quickly see the output.
  • Examples of simple operations like addition and subtraction are shown using JShell.

Working with Methods in Java

This section focuses on methods in Java and their importance when performing actions or tasks. The speaker explains that methods are used to solve problems or perform specific actions.

Understanding Methods in Java

  • Methods are used to perform actions or solve problems in Java.
  • When working with methods, values need to be passed as arguments.
  • The speaker introduces the print method, an built-in method in Java used for printing output.
  • To use the print method, you need to specify what should be printed within parentheses after calling the method.
  • A semicolon needs to be added at the end of each statement in Java.

Printing Output with System.out.println()

This section covers how to print output using System.out.println() statement. The speaker explains that this statement is used to print text or values on the console.

Printing Text and Values

  • To print something on the console, use System.out.println().
  • Within parentheses after println(), specify what should be printed (e.g., text or values).
  • Use double quotes when printing text. For example: "Hello World".
  • Numbers can be printed without quotes.
  • The System.out.println() statement is essential for printing output in Java.

Limitations of JShell and Compiling Java Files

This section discusses the limitations of using JShell for building projects and introduces the process of compiling Java files. The speaker explains that JShell is primarily used for experimentation, while Java files are used for building applications.

Limitations of JShell

  • JShell is not suitable for building projects or writing code in Java files.
  • When working with Java files, a different approach is required.
  • To compile a Java file, use the javac command followed by the file name.
  • Compilation errors may occur if there are syntax or logical issues in the code.

Conclusion

In this final section, the speaker concludes by summarizing the key points discussed throughout the video.

Key Takeaways

  • JShell is a useful tool for experimenting and testing code in Java.
  • Methods play a crucial role in performing actions and solving problems in Java.
  • Printing output can be done using System.out.println() statement.
  • JShell has limitations when it comes to building projects; instead, Java files should be used.
  • Compiling a Java file involves using the javac command followed by the file name.

The transcript provided does not cover all parts of the video.

Video description

Check out our courses: AI-Powered DevOps with AWS Live Course V2: https://go.telusko.com/ai-devops-v2 Coupon: TELUSKO10 (10% Discount) Java Spring Boot AI Live Course: https://go.telusko.com/JavaSpringBootAI Coupon: TELUSKO20 (20% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Java Spring:- https://go.telusko.com/Udemyjavaspring Java:- https://go.telusko.com/udemyteluskojava Spring: https://go.telusko.com/udemyteluskospring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 TELUSKO Android App : https://go.telusko.com/TELUSKOAPP TELUSKO IOS App : https://apple.co/3SsgmU2 Discord : https://discord.gg/D8hWe9BqfF In this lecture we will learn: - Using the VsCode IDE - How to start VsCode? - How do we create a project? - Creating the first java code - Use of JShell to run small codes - Steps to compile a code in the terminal #1 We will start doing coding in the VsCode. - VsCode includes Explorer, Search, Run and Debug, and Add Extension options in it. - You can add an extension if you want as per the VsCode recommendation like Extension Pack for Java. - We will create a project in Explorer. - VsCode itself has a terminal where you can run commands. java --version - used to check the version of java javac --version - used to check the version of java compiler - java command is used to run the code while the javac command is used to compile the code. :- How do we create a project? Project is a very broad term that is used when we create some files and merge these files with libraries. - We will create a new folder where we store all the files of our course. :- Creating a first Java file: -You can create the first java file in a folder like Hello.java. - .java is an extension of Java files. #2 Creating our first Java Code to print "Hello World" : JShell:- - We have a concept of JShell that is introduced in Java 9 where you can create small codes and perform operations. - Print is an inbuilt method in Java that is used to print anything and it uses with System.out like: System.out.print(6); System.out.print("hello world"); - double quotes are used to print any text. - a semicolon is required after every statement in Java as per the syntax. -JShell can't be used for doing projects, it is only useful for experiments or learning concepts. Two steps to compile any code: 1. Compile the code using the javac command. javac filename 2. Run the code using the java command. java classname Github repo : https://github.com/navinreddy20/Javacode.git More Learning : Java :- https://bit.ly/3x6rr0N Python :- https://bit.ly/3GRc7JX Django :- https://bit.ly/3MmoJK6 JavaScript :- https://bit.ly/3tiAlHo Node JS :- https://bit.ly/3GT4liq Rest Api :-https://bit.ly/3MjhZwt Servlet :- https://bit.ly/3Q7eA7k Spring Framework :- https://bit.ly/3xi7buh Design Patterns in Java :- https://bit.ly/3MocXiq Docker :- https://bit.ly/3xjWzLA Blockchain Tutorial :- https://bit.ly/3NSbOkc Corda Tutorial:- https://bit.ly/3thbUKa Hyperledger Fabric :- https://bit.ly/38RZCRB NoSQL Tutorial :- https://bit.ly/3aJpRuc Mysql Tutorial :- https://bit.ly/3thpr4L Data Structures using Java :- https://bit.ly/3MuJa7S Git Tutorial :- https://bit.ly/3NXyCPu Donation: PayPal Id : navinreddy20 https://www.telusko.com