1.13k likes | 3.46k Views
Introduction to Java Programming. Introduction. Java vs C++ Java Syntax Java API How to build stand-alone applications Examples. Java vs C++. Similar Syntax Run anywhere (Java), Compile anywhere (C++) No native support for unsigned arithmetic in Java
E N D
Introduction • Java vs C++ • Java Syntax • Java API • How to build stand-alone applications • Examples
Java vs C++ • Similar Syntax • Run anywhere (Java), Compile anywhere (C++) • No native support for unsigned arithmetic in Java • Automatic memory garbage collection in Java • Java runs in a virtual machine, C++ runs as native executable machine code
Java Syntax • The set of legal structures and commands that can be used in a particular programming language
Java Syntax class Foo {// Defines class Foo privateint x;// Member variable, normally variables // are declared as private to // enforce encapsulation //initialized to 0 by default publicFoo(){ // Constructor for Foo } publicint bar(inti){ // Member method bar() return3*i+ x; } }
Java Syntax Foo a;// declares a to be a reference to a Foo object a =new Foo();// initializes using the default constructor // Another constructor can be used as Foo a =new Foo(args);
Java API There are 3 types of Java Programming Language Application Programming Interfaces (APIs) • the official core Java API, contained in the JDK or JRE, of one of the editions of the Java Platform. The three editions of the Java Platform are Java ME (Micro edition), Java SE (Standard edition), and Java EE (Enterprise edition). • optional official APIs that can be downloaded separately. The specification of these APIs are defined according to a Java Specification Request (JSR), and sometimes some of these APIs are later included in the core APIs of the platform (the most notable example of this kind is Swing). • unofficial APIs, developed by third parties, but not related to any JSRs.
Java API • For example Java Advanced Imaging (JAI) is a Java platform extension API that provides a set of object-oriented interfaces that support a simple, high-level programming model which allows developers to create their own image manipulation routines without the additional cost or licensing restrictions, associated with commercial image processing software.
Java SE Programming • Install the followings • Java Runtime Environment (JRE) • Java Development Kit (JDK) • Netbeans IDE
Java SE Programming • Create a new Java project • Open NetBeans IDE
Java SE Programming • Go to File->New Project... • Select Javathen select Java Application
Java SE Programming • Click Next and enter Project Name then click Finish
Java SE Programming • .java file is created • Public class is created • Application entry point is created as main() function inside the class
Java SE Programming • Example • Declare a class as following inside the main class
Java SE Programming • Then write the code below inside the main() function
Java SE Programming • Run the application by pressing F6 button on the keyboard or click on the toolbars. • Then you should see the system output as below