Amity School of Engineering & Technology - Java Program Compilation and Execution

Slide Note
Embed
Share

Explore the steps for compiling and running a Java program at Amity School of Engineering & Technology. Learn about the compilation and execution process, converting source code into byte code, creating directories, renaming files, and launching command prompts. Dive into the world of Java programming with this comprehensive guide.


Uploaded on Jul 16, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Amity School of Engineering & Technology Java Program Compilation and Execution 1

  2. Amity School of Engineering & Technology STEPS FOR COMPILING AND RUNNING A JAVA PROGRAM

  3. Amity School of Engineering & Technology Compilation and Execution Process

  4. Amity School of Engineering & Technology Java Compiler Java compiler convert Source code into byte code(.class file). Byte code are intermediate code (Not in the form of Source code and Machine code 4

  5. Amity School of Engineering & Technology

  6. Amity School of Engineering & Technology Create a directory:

  7. Create a new text document: Amity School of Engineering & Technology

  8. Rename the text document to program name Amity School of Engineering & Technology

  9. Open the file Amity School of Engineering & Technology 'PrintHelloWorld.java' using 'Notepad'

  10. Launch the command prompt Amity School of Engineering & Technology

  11. Amity School of Engineering & Technology Cont..

  12. Change directory Amity School of Engineering & Technology

  13. Compiling the Java program Amity School of Engineering & Technology

  14. Amity School of Engineering & Technology .Class file

  15. Run the Java program Amity School of Engineering & Technology

  16. How take input from user in Java Java Scanner Class Java Scanner class allows the user to take input from the console. It belongs to java.util package. It is used to read the input of primitive types like int, double, long, short, float, and byte. It is the easiest way to read input in Java program. Scanner sc=new Scanner(System.in); The java.util package should be import while using Scanner class. Amity School of Engineering & Technology

  17. Amity School of Engineering & Technology Methods of Java Scanner Class Method Description int nextInt() It is used to scan the next token of the input as an integer. float nextFloat() It is used to scan the next token of the input as a float. double nextDouble() It is used to scan the next token of the input as a double. byte nextByte() It is used to scan the next token of the input as a byte. String nextLine() Advances this scanner past the current line. boolean nextBoolean() It is used to scan the next token of the input into a boolean value. long nextLong() It is used to scan the next token of the input as a long.

  18. Amity School of Engineering & Technology Example import java.util.*; class UserInputDemo { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.print("Enter first number- "); int a= sc.nextInt(); System.out.print("Enter second number- "); int b= sc.nextInt(); System.out.print("Enter third number- "); int c= sc.nextInt(); int d=a+b+c; System.out.println("Total= " +d); } //System.in is a standard input stream

  19. Amity School of Engineering & Technology Example import java.util.*; class UserInputDemo1 { public static void main(String[] args) { Scanner sc= new Scanner(System.in); //System.in is a standar d input stream System.out.print("Enter a string: "); String str= sc.nextLine(); System.out.print("You have entered: "+str); } } //reads string

Related