UNIT-1 Introduction to java and elementary programming

UNIT - 1

Introduction to java and elementary programming


Java language specification API, JDK and IDE, Creating, compiling and Executing a simple java program, Programming style, documentation and errors, Reading input from console, identifiers and variables, Assignment statements, Named constants and naming conventions, Data Types (Numeric, Boolean, Character, String) its Operations and Literals, Evaluating Expressions and operator Precedence, Types of Operators (Augmented assignment, Increment and Decrement, Logical), operator precedence and associativity, numeric type conversions.


1.1 The Java Language Specification, API, JDK, and IDE

  • The Java language specification is a technical definition of the Java programming language’s syntax and semantics.
  • The application program interface (API), also known as library, contains predefined classes and interfaces for developing Java programs.
  • Java is a full-fledged and powerful language that can be used in many ways. It comes in three editions:
  1. Java Standard Edition (Java SE) to develop client-side applications. The applications can run standalone or as applets running from a Web browser.
  2. Java Enterprise Edition (Java EE) to develop server-side applications, such as Java servlets, JavaServer Pages (JSP), and JavaServer Faces (JSF).
  3. Java Micro Edition (Java ME) to develop applications for mobile devices, such as cell phones.
  • Oracle releases each version with a Java Development Toolkit (JDK). For Java SE
  • The JDK consists of a set of separate programs, each invoked from a command line, for developing and testing Java programs. Instead of using the JDK, you can use a Java development tool (e.g., NetBeans, Eclipse, and TextPad)—software that provides an integrated development environment (IDE) for developing Java programs quickly. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.
1.2 Creating, Compiling, and Executing a Simple Java Program

  • You save a Java program in a .java file and compile it into a .class file. The .class file is executed by the Java Virtual Machine.
  • Program1 : Welcome.java


1.  Every Java program must have at least one class. 
2.  The program is executed from the main method
3.  Every statement in Java ends with a semicolon (;), known as the statement terminator.Reserved words, or keywords, have       a specific meaning to the compiler and cannot be used for other purposes in the program.
4.  Ex: public, static, class, and void.
5.  Comments are ignored by the compiler. In Java, comments are preceded by two slashes (//) on a line, called a line               comment, or enclosed between /* and */ on one or several lines, called a block comment or paragraph comment.
6.  In Java, each block begins with an opening brace ({) and ends with a closing brace (}).



A Java compiler translates a Java source file into a Java bytecode file. The following command
compiles Welcome.java:
javac Welcome.java
JVM executes java bytecode using java Welcome

1.3 Programming Style and Documentation


Good programming style and proper documentation make a program easy to read and
help programmers prevent errors.

1.3.1 Appropriate Comments and Comment Styles

Java supports comments of a special type, referred to as javadoc comments. javadoc comments begin with /** and end with */. They can be extracted into an HTML file using the JDK’s javadoc command. These comments must precede the class or the method header in order to be extracted into a javadoc HTML file.

1.3.2 Proper Indentation and Spacing

A single space should be added on both sides of a binary operator, as shown in the following
statement:
System.out.println(3+4*4); Bad style
System.out.println(3 + 4 * 4); Good style

1.3.3 Block Styles
A block is a group of statements surrounded by braces. There are two popular styles, next-line
style and end-of-line style, as shown below.




Comments