Lab Report 1 - Understanding Java Code Execution and User Interaction 1
Lab Report 1 - Understanding Java Code Execution and User Interaction 1
University
Dept of CSE
Submitted By :
Sudip Mandal
Batch D-85
Roll 05
HackerRank Profile : https://www.hackerrank.com/profile/sudip7981
Submitted To :
Majharul Hasan Lecturer,
Dept of Computer Science & Engineering
Dhaka International University
Introduction
In this lab, we explored the fundamental concepts of Java programming, including how Java
code is compiled and executed. We also practiced basic input and output operations in Java,
which are crucial for developing interactive programs.
Objectives
• Understand Java Code Execution: Learn how Java code is compiled and run.
• Practice Basic Input/Output Operations: Implement code to read from and write to the
console.
Lab Exercises
1. Java Code Execution
Discussion:
Java code undergoes a specific process to be executed on a computer. Here's a detailed look at
how Java code is compiled and run:
javac HelloWorld.java
• Output: This command produces a .class file, which contains the bytecode. For
instance, compiling HelloWorld.java results in HelloWorld.class.
• Bytecode:
• Intermediate Code: Bytecode is not tied to any specific hardware. It is designed
to be executed by the JVM, making Java code platform-independent.
• Execution:
• Java Virtual Machine (JVM): The JVM executes the bytecode. It interprets or
compiles the bytecode into machine code specific to the host system's hardware.
• Command: To run the compiled program, use the java command followed by the
class name (without the .class extension). For example:
code
java HelloWorld
•
• Output: The JVM runs the bytecode, producing the output as defined by the
program. For example, it prints "Hello, World!" to the console.
Procedure:
•
• Explanation: The Scanner class provides methods to read different types of
input. In this case, nextLine() reads a full line of text entered by the user.
• Outputting Data:
• We used System.out.println() to print messages to the console.
Conclusion
This lab provided a foundational understanding of how Java code is compiled and executed, as
well as basic input/output operations. We learned to write simple Java programs, compile them,
and run them to interact with the user through the console.
Future Work
• Explore more complex data types and structures in Java.
• Implement error handling for user input.
• Develop more interactive programs using advanced Java features.