Java Tutorial for Beginners - a Cheat Sheet

Total Page:16

File Type:pdf, Size:1020Kb

Java Tutorial for Beginners - a Cheat Sheet Java Tutorial For Beginners - A Cheat Sheet Review Java 9 Concepts at Jet Speed. Complete Java Course Introduction Background Popularity of Java Platform Independent or Portable Object Oriented Language Security Rich API Great IDE's Omnipresent Web Applications (Java EE (JSP, Servlets), Spring, Struts..) Mobile Apps(Android) Microservices (Spring Boot) Platform Independence Build once, run anywhere Java bytecode is the instruction set of the Java virtual machine graph TD A[Java Code] -->|Compiled| B(Bytecode) B --> C{Run} C -->|bytecode| D[Windows JVM] D --> K[Windows Instructions] C -->|bytecode| E[Unix JVM] E --> L[Unix Instructions] C -->|bytecode| F[Linux JVM] F --> M[Linux Instructions] C -->|bytecode| G[Any other platform JVM] G --> N[Linux Instructions] JDK vs JVM VS JRE JVM (Java Virtual Machine) runs the Java bytecode. JRE JVM + Libraries + Other Components (to run applets and other java applications) JDK JRE + Compilers + Debuggers ClassLoader Find and Loads Java Classes! Three Types System Class Loader - Loads all application classes from CLASSPATH Extension Class Loader - Loads all classes from extension directory Bootstrap Class Loader - Loads all the Java core files Order of execution of ClassLoaders JVM needs to find a class, it starts with System Class Loader. If it is not found, it checks with Extension Class Loader. If it not found, it goes to the Bootstrap Class Loader. If a class is still not found, a ClassNotFoundException is thrown. First Java Program public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } Notes Every line of code we write in Java is part of something called Class. We will talk about Class later. First line defines a public class called HelloWorld. All the code in a class is between { and }. When a program runs, Java should know which line of code has to be run first. public static void main(String[] args) is the first method that is run when a program is executed. Java, like any other programming language, is particular about syntax!! Using Java and JavaC There are two steps involved in running a Java Program Compilation Execution Compilation We use javac to compile java code. Open CommandPrompt/Terminal and cd to the folder where HelloWorld.java file is present execute the command below javac HelloWorld.java You should see two files HelloWorld.java and HelloWorld.class in the folder. HelloWorld.class contains the java bytecode Execution Now we can run the program using JVM execute the command below java HelloWorld You should see the output "Hello World" printed in the console. Class and Object What is a class? Definining an instance of a class - an object Invoking a method on the object Variables Value of a variable changes during the course of a program execution. int number; number = 5; System.out.println(number);//5 number = number + 2; System.out.println(number);//7 number = number + 2; System.out.println(number);//9 Declaring and Initializing Variables Declaration is give a variable a name and type TYPE variableName; Tips Two or more variables of single type can be declared together. Variable can be local or global. The local variables can be referenced (ie, are valid) only within the scope of their method (or function). All six numeric types in Java are signed. Primitive Variables Variables that store value. Java defines few types like int (numbers), float(floating point numbers), char (characters). Variables of these types store the value of the variable directly. These are not objects. These are called primitive variables. An example is shown below: Primitive Variables contains bits representing the value of the variable. int value = 5; Different primitive types in java are char, boolean, byte, short, int, long, double, or float. Because of these primitive types, Java is NOT considered to be a pure objected oriented language. Numeric Data Types Types : byte, short, int, long, float, double Number of bits : 8, 16, 32, 64, 32, 64 Range : -x to x-1 where x = Power(2, number of bits -1) char Data Type Used to store characters. Size of character is 16 bits. Examples int i = 15; long longValue = 1000000000000l; byte b = (byte)254; float f = 26.012f; double d = 123.567; boolean isDone = true; boolean isGood = false; char ch = 'a'; char ch2 = ';'; Reference Variables Animal dog = new Animal(); The instance of new Animal - Animal object - is created in memory. The memory address of the object created is stored in the dog reference variable. Reference Variables contains a reference or a guide to get to the actual object in memory. Puzzles Animal dog1 = new Animal(); dog1 = new Animal(); What will happen? Two objects of type Animal are created. Only one reference variable is created. Animal animal1 = new Animal(); Animal animal2 = new Animal(); animal1 = animal2; What will happen? What would happen if the same was done with primitive variables? Identifiers Names given to a class, method, interface, variables are called identifiers. Legal Identifier Names Combination of letters, numbers, $ and under-score(_) Cannot start with a number Cannot be a keyword No limit on length of identifier Java Keywords List of Java Keywords Primitives DataTypes : byte,short,int,long,float,double,char,boolean Flow Control : if, else,for,do, while, switch, case, default, break, continue,return Exception Handling : try, catch, finally,throw,throws,assert Modifiers : public,private,protected,final,static,native,abstract, synchronized,transient,volatile,strictfp Class Related : class,interface,package,extends,implements,import Object Related : new, instanceof,super,this Literals : true, false, null Others : void, enum Unused : goto,const Literals Any primitive data type value in source code is called Literal. There are four types of literals: Integer & Long Floating Point Boolean Double Literals Integer Literals There are 3 ways of representing an Integer Literal. Decimal. Examples: 343, 545 Octal. Digits 0 to 7. Place 0 before a number. Examples : 070,011 Hexadecimal. Digits 0 to 9 and alphabets A to F (10-15). Case insensitive. An integer literal by default is int. Long Literals All 3 integer formats: Decimal, Octal and Hexadecimal can be used to represent long by appending with L or l. Floating point Literals Numbers with decimal points. Example: double d = 123.456; To declare a float, append f. Example: float f = 123.456f; Floating point literals are double by default. Appending d or D at end of double literal is optional Example: double d = 123.456D; Boolean Literals Valid boolean values are true and false. TRUE, FALSE or True, False are invalid. Character Literals Represented by single character between single quotes Example: char a = 'a' Unicode Representation also can be used. Prefix with \u. Example: char letterA = '\u0041'; A number value can also be assigned to character. Example: char letterB = 66; Numeric value can be from 0 to 65535; Escape code can be used to represent a character that cannot be typed as literal. Example: char newLine = '\n'; Puzzles int eight = 010; int nine=011; int invalid = 089;//COMPILER ERROR! 8 and 9 are invalid in Octal int sixteen = 0x10; int fifteen = 0XF; int fourteen = 0xe; int x = 23,000; long a = 123456789l; long b = 0x9ABCDEFGHL; long c = 0123456789L; float f = 123.456;//COMPILER ERROR! A double value cannot be assigned to a float. boolean b = true; boolean b=false; boolean b = TRUE;//COMPILATION ERROR boolean b = 0; //COMPILER ERROR. This is not C Language char ch = a; char a = 97; char ch1 = 66000; //COMPILER ERROR! Tip - Assignment Operator Assignment operator evaluates the expression on the right hand side and copies the value into the variable on the left hand side. Basic Examples int value = 35;//35 is copied into 35 int squareOfValue = value * value;//value * value = 35 * 35 is stored into squareOfValue int twiceOfValue = value * 2; Puzzles int a1 = 5; int b1 = 6; b1 = a1; // value of a1 is copied into b1 a1 = 10; // If we change a1 or b1 after this, it would not change the other variable.. b1 will remain 6 Actor actor1 = new Actor(); actor1.setName("Actor1"); //This creates new reference variable actor1 of type Actor new Actor() on the heap assigns the new Actor on the heap to reference variable Actor actor2 = actor1; actor2.setName("Actor2"); System.out.println(actor1.getName());//Actor2 Casting - Implicit and Explicit Casting is used when we want to convert one data type to another. A literal integer is by default int. Operation involving int-sized or less always result in int. Floating point literals are by default double Implicit Casting Implicit Casting is done directly by the compiler. Example : Widening Conversions i.e. storing smaller values in larger variable types. byte b = 10; //byte b = (int) 10; Example below compiles because compiler introduces an implicit cast. short n1 = 5; short n2 = 6; //short sum = n1 + n2;//COMPILER ERROR short sum = (short)(n1 + n2);//Needs an explicit cast byte b = 5; b += 5; //Compiles because of implicit conversion int value = 100; long number = value; //Implicit Casting float f = 100; //Implicit Casting Explicit Casting Explicit Casting needs to be specified by programmer in code. Example: Narrowing Conversions. Storing larger values into smaller variable types; Explicit casting would cause truncation of value if the value stored is greater than the size of the variable. long number1 = 25678; int number2 = (int)number1;//Explicit Casting //int x = 35.35;//COMPILER ERROR int x = (int)35.35;//Explicit Casting int bigValue = 280; byte small = (byte) bigValue; System.out.println(small);//output 24. Only 8 bits remain. //float avg = 36.01;//COMPILER ERROR. Default Double float avg = (float) 36.01;//Explicit Casting float avg1 = 36.01f; float avg2 = 36.01F; //f or F is fine //byte large = 128; //Literal value bigger than range of variable type causes compilation error byte large = (byte) 128;//Causes Truncation! Compound Assignment Operators Examples : +=, -=, *= int a = 5; a += 5; //similar to a = a + 5; a *= 10;//similar to a = a * 10; a -= 5;//similar to a = a - 5; a /= 5;//similar to a = a / 5; Other Operators Remainder(%) Operator Remainder when one number is divided by another.
Recommended publications
  • 1. Output of a Java Compiler Is Non Executable Code I.E Bytecode
    Q.1. Write the features of Java Programming. Ans: The primary objective of Java programming language creation was to make it portable, simple and secure ​ programming language. Apart from this, there are also some excellent features which play an important role in the popularity of this language. The features of Java are also known as java buzzwords. ​ ​ A list of most important features of Java language is given below- 1. Simple 2. Object-Oriented 3. Portable 4. Platform independent 5. Secured 6. Robust 7. Architecture neutral 8. Interpreted 9. High Performance 10. Multithreaded 11. Distributed 12. Dynamic Q.2. Why we say Java is a Portable Language. Ans: Java is Considered as Platform independent because of many different reasons which are listed below – 1. Output of a Java compiler is Non Executable Code i.e Bytecode. ​ ​ 2. Bytecode is a highly optimized set of instructions ​ 3. Bytecode is executed by Java run-time system, which is called the Java Virtual Machine (JVM). ​ ​ Q. 3. Short Notes on JVM. Ans: JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed. It can also run those programs which are written in other languages and compiled to Java bytecode. JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform dependent because the configuration of each OS is different from each other. However, Java is platform independent. ​ There are three notions of the JVM: specification, implementation, and instance.
    [Show full text]
  • Java Programming Language Keywords
    Color profile: Generic CMYK printer profile Composite Default screenCertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 1 Blind Folio 1:1 Part I The Programmer’s Exam CHAPTERS 1 Language Fundamentals 6 Java.lang—The Math Class, Strings, and Wrappers 2 Declarations and Access Control 7 Objects and Collections 3 Operators and Assignments 8 Inner Classes 4 Flow Control, Exceptions, and Assertions 9 Threads 5 Object Orientation, Overloading and Overriding, Constructors, and Return Types P:\010Comp\CertPrs8\684-6\ch01.vp Thursday, November 14, 2002 3:38:51 PM Color profile: Generic CMYK printer profile Composite Default screen CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 Blind Folio 2 P:\010Comp\CertPrs8\684-6\ch01.vp Thursday, November 14, 2002 3:38:51 PM Color profile: Generic CMYK printer profile Composite Default screenCertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 1 Blind Folio 1:3 1 Language Fundamentals CERTIFICATION OBJECTIVES • Java Programming Language Keywords • Literals and Ranges of All Primitive Data Types • Array Declaration, Construction, and Initialization • Using a Variable or Array Element That Is Uninitialized and Unassigned • Command-Line Arguments to Main ✓ Two-Minute Drill Q&A Self Test P:\010Comp\CertPrs8\684-6\ch01.vp Thursday, November 14, 2002 3:38:52 PM Color profile: Generic CMYK printer profile Composite Default CertPrs8(SUN)screen / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 1 4 Chapter 1: Language Fundamentals his chapter looks at the Java fundamentals that you need to pass the Java 1.4 Programmer exam.
    [Show full text]
  • Introduction to Java Programming — Comprehensive Version, 10H Ed
    59 Lecture Notes in Programming Foundations Elvis C. Foster Lecture 02: Introduction to Java This chapter contains: . Overview of Java . Compilation Process . Anatomy of a Java Program . Outputting Information on Screen . Primitive Data Types & Variables . Operations . Expressions . Object-Oriented Programming Conventions . Getting Input From Input Dialogs . Getting Input From the Console . The String Class . The Character Class . Formatted Output . Keeping Track of Date and Time . Java Keywords . Commonly Used Java Packages . Summary and Concluding Remarks . Review Questions . Recommended Readings Copyright © 2004 – 2016 by Elvis C. Foster All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, or otherwise, without prior written permission of the author. 60 Lecture 2: Introduction to Java E. C. Foster 2.1 Overview of Java Java is a purely object-oriented programming language (OOPL), originally developed by Sun Microsystems, and currently marketed by Oracle (after acquiring Sun Microsystems). The language, though relatively new, has been through several iterations of refinement. The currently available version is Java 8 Standard Edition (SE). Oracle markets various software packages including the Java language. The ones of immediate interest are: . Java Development Kit 8u25 . Java SE 8u25 . Java SE Run-time Environment 8u25 . Java Development Kit 8.0 with NetBeans 8.0.2 In addition, Oracle markets several other Java-based products. Each product line is marketed with a comprehensive set of documentation, which is accessible via the Oracle website. There are several third- party Java development kits that are available. One such product is Eclipse.
    [Show full text]
  • PDF for Printing
    Topic 16 The keyword list thus far: Complete list of Java keywords: Creating Correct Programs abstract default if private this boolean do implements protected throw "It is a profoundly erroneous truism, repeated by all the break double import public throws byte else instanceof return transient copybooks, and by eminent people when they are making case extends int short try speeches, that we should cultivate the habit of thinking about catch final interface static void char finally long strictfp volatile what we are doinggp. The precise o pposite is the case. class float native super while Civilization advances by extending the number of const for new switch operations which we can perform without thinking about continue goto package synchronized assert enum them. Operations of thought are like cavalry charges in a battle -they are strictly limited in number, they require fresh horses, and must only be made at decisive moments." -Alfred North Whitehead Based on slides for Building Java Programs by Reges/Stepp, found at httppyg://faculty.washington.edu/stepp /book/ CS305j Introduction to Odds and Ends 1 CS305j Introduction to Odds and Ends 2 Computing Computing The Random class Generating "Random" Java has a class named Random whose objects generate Numbers pseudo-random numbers. MthdMethod name DitiDescription nextInt() returns a random integer nextInt(max) returns a random integer in the range [0, max) in other words, from 0 up through one less than the max nextDouble() returns a random real number in the range [0.0, 1.0) –Example: Random rand = new Random(); int randomNumber = rand.nextInt(10); // randomNumber has a random value between 0 and 9 – Class Random is found in the java.util package.
    [Show full text]
  • Static Void Main(String[] Args) { System.Out.Println("Hello, World!"); } }
    Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, 2007. They may not be rehosted, sold, or modified without expressed permission from the authors. All rights reserved. 1 Chapter outline Lecture 1 Programs and programming languages Basic Java programs output with println statements syntax and errors Lecture 2 Structured algorithms with static methods Identifiers, keywords, and comments 2 Lecture 1 Basic Java programs with println statements suggested reading: 1.1 - 1.3 3 Computer programs program: A set of instructions that are to be carried out by a computer. program execution : The act of carrying out the instructions contained in a program. programming language : A systematic set of rules used to describe computations in a format that is editable by humans. This textbook teaches programming in a language named Java. 4 Languages A partial history of programming languages Some influential ones: FORTRAN science / engineering COBOL business data LISP logic and AI BASIC a simple language 5 Some modern languages procedural languages : programs are a series of commands Pascal (1970): designed for education C (1972): low-level operating systems and device drivers functional programming : functions map inputs to outputs Lisp (1958) / Scheme (1975), ML (1973), Haskell (1990) object-oriented languages : programs use interacting "objects" Smalltalk (1980): first major object-oriented language C++ (1985): "object-oriented" additions to C; successful in industrial programming (Windows is built in C++) Java (1995): Sun Microsystems' language designed for embedded systems, web applications, servers Runs on many platforms (Windows, Mac, Linux, cell phones...) The language taught in this textbook 6 A basic Java program public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } } code or source code : The sequence of instructions in a program.
    [Show full text]
  • Declarations and Access Control
    CertPrs8/Java 5 Cert. Study Guide/Sierra-Bates/225360-6/Chapter 1 Blind Folio 1 1 Declarations and Access Control CERTIFICATION OBJECTIVES l Declare Classes & Interfaces l Use Static Methods, JavaBeans Naming, & Var-Args l Develop Interfaces & Abstract Classes 3 Two-Minute Drill l Use Primitives, Arrays, Enums, & Q&A Self Test Legal Identifiers ch1-1123f.indd 1 11/28/05 12:24:13 AM CertPrs8/Java 5 Cert. StudyGuide/Sierra-Bates/225360-6/Chapter 1 2 Chapter 1: Declarations and Access Control e assume that because you're planning on becoming certified, you already know the basics of Java. If you're completely new to the language, this chapter—and the W rest of the book—will be confusing; so be sure you know at least the basics of the language before diving into this book. That said, we're starting with a brief, high-level refresher to put you back in the Java mood, in case you've been away for awhile. Java Refresher A Java program is mostly a collection of objects talking to other objects by invoking each other's methods. Every object is of a certain type, and that type is defined by a class or an interface. Most Java programs use a collection of objects of many different types. n Class A template that describes the kinds of state and behavior that objects of its type support. n Object At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object which is an instance of that class.
    [Show full text]
  • Structured Problem-Solving Using the Computer ITK
    Structured Problem-Solving Using the Computer IT 168 #6 Fall, September 5 2013 Announcements • Quiz#1 graded and returned • For today – Read Chapter 2.4 (Documentation and Style) of your text • For Tuesday – Read Chapter 3.1 • Program#1 will be out on Friday (schedule changed) • Question – Have you tried sample Java code in Chap 1 and 2? Quiz#2 • .. Any question? • .. Outline • Writing Pseudo Code – Review: LOOP #count • Chap 2.1: variables and expressions Outline of Chapter 2 • Variables and Expressions • The Class String • Keyboard and Screen I/O • Documentation and Style JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Variables and Expressions: Outline • Variables • Data Types • Java Identifiers • Assignment Statements • Simple Input • Simple Screen Output • Constants • Named Constants JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Variables and Expressions: Outline • Assignment Compatibilities • Type Casting • Arithmetic Operations • Parentheses and Precedence Rules • Specialized Assignment Operators • Case Study: Vending Machine Change • Increment and Decrement Operators JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Variables • Variables store data such as numbers and letters. Think of them as places to store data. They are implemented as memory locations. • The data stored by a variable is called its value. The value is stored in the memory location. • Its value can be changed. JAVA: An Introduction to Problem Solving & Programming, 6th Ed.
    [Show full text]
  • Introduction to Java
    DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45 SUBJECT CODE: 501 SUBJECT NAME: JAVA PROGRAMMING UNIT 1: INTRODUCTION TO JAVA Features of Java The primary objective of Java programming language creation was to make it portable, simple and secure programming language. Apart from this, there are also some excellent features which play an important role in the popularity of this language. The features of Java are also known as java buzzwords. A list of most important features of Java language is given below. www.dacc.edu.in PROF . SUPRIYA MANE DNYANSAGAR ARTS AND COMMERCE COLLEGE, BALEWADI,PUNE - 45 1. Simple 2. Object-Oriented 3. Portable 4. Platform independent 5. Secured 6. Robust 7. Architecture neutral 8. Interpreted 9. High Performance 10. Multithreaded 11. Distributed 12. Dynamic Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun, Java language is a simple programming language because: o Java syntax is based on C++ (so easier for programmers to learn it after C++). o Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc. o There is no need to remove unreferenced objects because there is an Automatic Garbage Collection in Java. Object-oriented Java is an object-oriented programming language. Everything in Java is an object. Object-oriented we organize our software as a combination of different types of objects that incorporates both data and behavior. Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules. Basic concepts of OOPs are: www.dacc.edu.in PROF .
    [Show full text]
  • Chapter 2 Primitive Types, Strongs, and Console
    Basic Computation Chapter 2 JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Objectives • Describe the Java data types used for simple data • Write Java statements to declare variables, define named constants • Write assignment statements, expressions containing variables and constants • Define strings of characters, perform simple string processing JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Objectives • Write Java statements that accomplish keyboard input, screen output • Adhere to stylistic guidelines and conventions • Write meaningful comments JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved 1 Outline • Variables and Expressions • The Class String • Keyboard and Screen I/O • Documentation and Style JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Variables and Expressions: Outline • Variables • Data Types • Java Identifiers • Assignment Statements • Simple Input • Simple Screen Output • Constants • Named Constants JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Variables and Expressions: Outline • Assignment Compatibilities • Type Casting • Arithmetic Operations • Parentheses and Precedence Rules • Specialized Assignment Operators • Case Study: Vending Machine Change • Increment and Decrement Operators JAVA: An Introduction to Problem Solving & Programming, 6th Ed. By Walter Savitch ISBN 0132162709 © 2012 Pearson Education, Inc., Upper Saddle River, NJ.
    [Show full text]
  • Chapter 2: Primitive Data Types and Operations
    Chapter 2: Primitive Data Types and Operations JAVA: An Introduction to Problem Solving & Programming, 7th Ed. By Walter Savitch 1 ISBN 0133862119 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Variables •Variables store data such as numbers and letters. • Think of them as places to store data. • They are implemented as memory locations. •The data stored by a variable is called its value. • The value is stored in the memory location. •Its value can be changed. JAVA: An Introduction to Problem Solving & Programming, 7th Ed. By Walter Savitch 2 ISBN 0133862119 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Java Identifiers •An identifier is a name, such as the name of a variable. •Identifiers may contain only • Letters • Digits (0 through 9) • The underscore character (_) • And the dollar sign symbol ($) which has a special meaning •The first character cannot be a digit. JAVA: An Introduction to Problem Solving & Programming, 7th Ed. By Walter Savitch 3 ISBN 0133862119 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Java Identifiers •Identifiers may not contain any spaces, dots (.), asterisks (*), or other characters: 7-11 oracle.com util.* (not allowed) •Identifiers can be arbitrarily long. •Since Java is case sensitive, stuff, Stuff, and STUFF are different identifiers. JAVA: An Introduction to Problem Solving & Programming, 7th Ed. By Walter Savitch 4 ISBN 0133862119 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved Keywords or Reserved Words •Words such as if are called keywords or reserved words and have special, predefined meanings. • Cannot be used as identifiers.
    [Show full text]
  • Introduction to Java
    Java Language Basics UNIT 3 JAVA LANGUAGE BASICS Structure Page Nos. 3.0 Introduction 37 3.1 Objectives 37 3.2 Introduction To Java 37 3.2.1 Basic Features 3.2.2 Java Virtual Machine Concepts 3.2.3 A Simple Java Program 3.3 Primitive Data Type And Variables 46 3.3.1 Java Keywords 3.3.2 Integer and Floating Point Data Type 3.3.3 Character and Boolean Types 3.3.4 Declaring and Initialization Variables 3.4 Java Operators 53 3.5 Summary 59 3.6 Solutions/Answers 60 3.0 INTRODUCTION Java is an island in Indonesia, or you can say Java is type of coffee, but Java is most popular as a programming language. In 1991 Java Programming Language stepped into the world and got dominant status. In this unit you will learn the advantages and strength of Java, and what actually makes Java powerful and popular. Broadly a Java program can be divided into two types, Application and Applets. The differences between the two are explained in this unit. The concept of Java virtual Machine makes this language platform independent. With this concept of Java virtual machine we will move towards the programming of Java language. You can learn the basic programming concept of Java and how you can compile and execute the Java Application and Applet programs. To improve your programming concepts, you can move towards the declaration and initiations of different data types and variables. Similar to C, Java also contains operators. Those are explained at the end of this unit.
    [Show full text]
  • Introduction to Java
    Chapter 1 Introduction to Java Chapter 1 – Introduction to Java Marks Allotted: 16 Lectures: 10 Semester Pattern: Exam: Winter 2008 Summer 2009 Marks: 16 24 Yearly Pattern (JPR-IF 1526): Exam: S’04 W’04 S’05 W’05 S’06 W’06 S’07 W’08 Marks: 16 16 20 16 16 20 12 12 Contents: 1.1 Fundamentals of Object Oriented Programming Object and Classes, Data abstraction and encapsulation, Inheritance, Polymorphism, Dynamic Binding 1.2 Java Features Compiled and Interpreted, Platform independent and portable, Object oriented Distributed, Multithreaded and interactive, High performance 1.3 Constant, Variables and Data Types Constant, Data Types, Scope of variable, Symbolic Constant, Type casting, Standard default values 1.4 Operator and Expression Arithmetic Operators, Relational Operators, Logical Operators, Assignment Operator Increment and Decrement Operator, Conditional Operator, Bit wise Operator, Special Operator 1.5 Decision making and Branching Decision making with if statement, Simple if statement, The if else statement, The else if ladder, The switch statement, The? : Operator 1.6 Decision making and Looping The While statement, The do statement, The for statement, Jumps in Loops, Labeled Loops Java Programming (9113) by T. B. Kute 1 Chapter 1 Introduction to Java Fundamentals of Object Oriented Programming Our computer programs consists of two elements i.e. code and data. A program is conceptually organized around the data. According to the way of flow of the data, there are two types of programming paradigms. The first way is called procedure oriented programming. In which everything is organized in functions by functions. Flow of execution of the program is taken through the linear steps.
    [Show full text]