Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22
Java For Beginners
Exploring the Fundamentals of Java
Rida Akram What Is Java? Java is Object Oriented Programming language as well as platform. Java was developed by James Gosling at Sun Microsystems. It promised Write Once, Run Anywhere (WORA) functionality. Java is a powerful, versatile, and widely-used programming language known for its robustness, portability, and scalability. Java's popularity stems from its platform independence, extensive standard library, and strong community support. History of Java Java was conceived by James Gosling, Mike Sheridan, and Patrick Naughton in the early 1990s. First released in 1995 as Java 1.0. Significant milestones: Introduction of Swing GUI toolkit in Java 1.2. Java 5 (2004) introduced generics and enhanced for loop. Java 8 (2014) introduced lambda expressions and the Stream API. Latest LTS version: Java 17 (2021). Key Features of Java Object-Oriented: Java follows the object-oriented programming paradigm, where everything is treated as an object. Platform-Independent: Java programs can run on any platform with the help of the Java Virtual Machine (JVM). Robust and Secure: Java's strong memory management, exception handling, and security features make it robust and secure. Rich Standard Library: Java comes with an extensive standard library that provides ready-to-use classes and methods for various programming tasks. Where is JAVA Used? There are many devices where java is currently used: Desktop Applications: Acrobat reader, Media Player, Antivirus etc. Web Applications: irctc.co.in, Javapoint.com etc Enterprise Application: Banking Application, Business Application. Mobile Games Java Virtual Machine Java virtual machine is the like usual computer which translate high level language into machine language. Just like that Java virtual machine also translate Bytecode into machine language. JVM are available for many hardware and software Plateform. Java Development Kit JDK is a software(JDK) development kit used for developing Java applications. Components of JDK include: Java Compiler (javac) Java Virtual Machine (JVM) Java Runtime Environment (JRE) Java Standard Library Documentation and Development Tools Control Flow Statements if-else: Conditional statement for decision-making. switch: Multi-branch decision-making statement. for loop, while loop, do-while loop: Iterative statements for loop execution. Examples demonstrating each control flow statement. Basic Java Syntax Class Declaration: Java programs are organized into classes. Main Method: Entry point of a Java program. Variables and Data Types: Java supports various data types such as int, double, String, etc. Comments: Single-line (//) and multi-line (/* */) comments. Object-Oriented Programming (OOP) in Java Classes and Objects: Building blocks of Java programs. Inheritance: Mechanism for code reuse and building relationships between classes. Encapsulation: Bundling data and methods that operate on the data into a single unit. Polymorphism: Ability to take different forms based on the context. Abstraction: Hiding complex implementation details and showing only essential features. Exception Handling Try-catch-finally: Java's exception handling mechanism. Checked and Unchecked Exceptions: Different types of exceptions in Java. Throw and Throws: Keywords used in exception handling. Java Standard Library java.lang: Fundamental classes and utilities. java.util: Data structures, such as ArrayList, HashMap, etc. java.io: Input and output operations. java.net: Networking support. java.awt and javax.swing: GUI development Java Application Examples Desktop Applications: Java Swing, JavaFX. Web Applications: Java Servlets, JavaServer Pages (JSP). Enterprise Applications: Java EE (Enterprise Edition) applications using frameworks like Spring and Hibernate. Mobile Applications: Android development using Java (though Kotlin is preferred now). Embedded Systems: Java ME (Micro Edition) for small, resource-constrained devices. A First Simple Program /* This is a simple Java program. Compiling the Program Call this file "Example.java".*/ class Example { C:\>javac Example.java // Your program begins with a The javac compiler creates a file call to main(). called Example.class that public static void main(String contains the bytecode version of args[]) { the program System.out.println("This is a The output of javac is not code simple Java program."); that can be directly executed. } } Cont… To actually run the program, you The keyword void simply tells the must use the Java interpreter, called compiler that main( ) does not java. return a value C:\>java Example String[ ] args declares a parameter When a class member is preceded by named args, which is an array of public, then that member may be instances of the class String. args accessed by code outside the class in receives any command-line which it is declared arguments. The keyword static allows main( ) to be called without having to instantiate a particular instance of the class A Second Short Program class Example2 { public static void main(String args[]) { int num; // this declares a variable called num num = 100; // this assigns num the value 100 System.out.println("This is num: " + num); num = num * 2; System.out.print("The value of num * 2 is "); System.out.println(num); } } Advantages of Java Disadvantages of Java ● Platform independent: Java code can run on any platform that 1. Performance: Java can be slower has a Java Virtual Machine (JVM) installed, which means compared to other programming that applications can be written once and run on any device. ● languages, such as C++, due to its use Object-Oriented: Java is an object-oriented programming language, which means that it follows the principles of of a virtual machine and automatic encapsulation, inheritance, and polymorphism. memory management. ● Security: Java has built-in security features that make it a 2. Memory management: Java’s secure platform for developing applications, such as automatic memory management can automatic memory management and type checking. lead to slower performance and ● Large community: Java has a large and active community of increased memory usage, which can be developers, which means that there is a lot of support available for learning and using the language. a drawback for some applications. ● Enterprise-level applications: Java is widely used for developing enterprise-level applications, such as web applications, e-commerce systems, and database systems. Conclusion Java is a versatile and powerful programming language with a rich ecosystem and community support. Understanding Java fundamentals opens up opportunities in various domains. Continuous learning and practice are essential for mastering Java development. Credits: This presentation template was created by Slidesgo, and includes icons by Flaticon, and infographics & images by Freepik