Java Tutorial
IntroductionEnvironment SetupIDEBuild ManagementLanguage SpecificationBasic ProgramVariablesData TypesPackagesModifiersConditionalsLoopsObject OrientedClassesSuperInterfacesEnumStatic importInheritanceAbstractionEncapsulationPolymorphismBoxing & UnboxingConversion Formatting numbers Arrays Command line arguments in java Variable Number of arguments in Java Exception handling in Java String handling in Java StringBuffer and StringBuilder in Java Mathematical Operations in Java Date and Time in Java Regular expressions in Java Input output programming in Java File Handling Nested Classes Collections Generics Serialization Socket programming Multi-Threading Annotations Lambda Expressions Reflections in Java Singleton class in Java Runtime Class in JavaHow to load resource in JavaHow to load properties file in JavaAdvanced
Log4j – Logging framework in JavaInterview Questions in JavaIn this topic, we will learn below topics.
- Writing first Java program
- Compiling the program using IDE, javac
- Executing the program using IDE, java
- Debugging the program
- Looking at output
Here is the simple Java class – Basic.Java
package simple;
/**
* Created by Sagar on 16-04-2016.
*/
public class Basic {
public static void main(String [] args){
System.out.println("Hello www.softpost.org");
}
}
Compiling the Java class.To compile the Java class file, you need to execute below command.
javac simple/Basic.java
Above command creates class file called Basic.class.
Running the Java class
To run the Basic.class file, you need to execute below command. Notice that you should be in the parent directory of simple (package directory) when running below command. Also note that how we access the class name. Since the class is in simple package, you need to access it using simple.Basic
Another important thing to note is that -cp switch. It tells JVM that classes can be found in current directory. If you do not pass correct class path, you will get error saying – could not find or load main class simple.Basic
java -cp . simple.Basic
Debugging the Java source code
Different IDEs provide different ways to debug the code using breakpoints. For example – Intellij IDEA allows us to add breakpoints, step into, step out of the break point.
Web development and Automation testing
solutions delivered!!