Amity School of Engineering & Technology - Java Program Compilation and Execution
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.
Download Presentation
![](/assets/img/so-down.gif)
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
Amity School of Engineering & Technology Java Program Compilation and Execution 1
Amity School of Engineering & Technology STEPS FOR COMPILING AND RUNNING A JAVA PROGRAM
Amity School of Engineering & Technology Compilation and Execution Process
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
Amity School of Engineering & Technology Create a directory:
Create a new text document: Amity School of Engineering & Technology
Rename the text document to program name Amity School of Engineering & Technology
Open the file Amity School of Engineering & Technology 'PrintHelloWorld.java' using 'Notepad'
Launch the command prompt Amity School of Engineering & Technology
Change directory Amity School of Engineering & Technology
Compiling the Java program Amity School of Engineering & Technology
Amity School of Engineering & Technology .Class file
Run the Java program Amity School of Engineering & Technology
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
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.
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
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