Certified Core Java Developer VS-1036

Similar documents
Lecture 1: Overview of Java

Fundamentals of Programming. By Budditha Hettige

CSE 421 Course Overview and Introduction to Java

JVM interprets the Java bytecode, controls how it interacts with the operating system and manages memory.

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Chapter 4 Java Language Fundamentals

Life Without NetBeans

Introduction to Java

Getting Started with Eclipse/Java

Getting Started with Java. Atul Prakash

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

CHAPTER 1. Introduction to JAVA Programming

Before you start working with Java, you need to set up a Java development

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Software Installation for CS121

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

Javac and Eclipse tutorial

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

Lesson 04: Our First Java Program (W01D4

Programming with Java

Setting up your Computer

Chapter 1 Introduction to Java

CS 231 Data Structures and Algorithms, Fall 2016

Lecture 1: Introduction to Java

Running Java Programs

How to Install (then Test) the NetBeans Bundle

Introduction to Java. Nihar Ranjan Roy.

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Getting Started With Java

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Before you start with this tutorial, you need to know basic Java programming.

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Chapter 1 Introduction to Computers, Programs, and Java

Introduction to Java Programming

CS260 Intro to Java & Android 02.Java Technology

These two items are all you'll need to write your first application reading instructions in English.

Lesson 01 Introduction


Pace University. Fundamental Concepts of CS121 1

IT151: Introduction to Programming (java)

CHAPTER 1 Introduction to Computers and Java

JDB - QUICK GUIDE JDB - INTRODUCTION

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 1

1. Introduction. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

II. Compiling and launching from Command-Line, IDE A simple JAVA program

Mobile Computing LECTURE # 2

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Notes of the course - Advanced Programming. Barbara Russo

CSC116: Introduction to Computing - Java

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

CS 11 java track: lecture 1

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

13 th Windsor Regional Secondary School Computer Programming Competition

Getting Started (1.8.7) 9/2/2009

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

CSC116: Introduction to Computing - Java

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

This lecture will take you through simple and practical approach while learning Java Programming language.

NetBeans IDE Java Quick Start Tutorial

20 Most Important Java Programming Interview Questions. Powered by

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 12, 2011

By: Abhishek Khare (SVIM - INDORE M.P)

Object-Oriented Programming in Java

MODULE 1 JAVA PLATFORMS. Identifying Java Technology Product Groups

CS11 Java. Fall Lecture 1

Chapter 1 Introduction to Computers, Programs, and Java

Java Programming Language Mr.Rungrote Phonkam

CSC116: Introduction to Computing - Java

StackVsHeap SPL/2010 SPL/20

This section contains information you should review before using this book. Any updates to the information presented here will be posted at:

Chapter Goals. Contents INTRODUCTION

CompSci 125 Lecture 02

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Java Professional Certificate Day 1- Bridge Session

Selected Java Topics

Advanced Object-Oriented Programming Introduction to OOP and Java

EMC Documentum Composer

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 29, 2010

RTMS - Software Setup

Selected Questions from by Nageshwara Rao

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Java Bytecode (binary file)

Lecture 4: Introduction to Java and your Development Environment

JPA - INSTALLATION. Java version "1.7.0_60" Java TM SE Run Time Environment build b19

EMC Documentum Composer

Games Course, summer Introduction to Java. Frédéric Haziza

CHAPTER INTRODUCTION. Final Draft Oct. 15, Slides by Donald W. Smith TechNeTrain.com. Copyright 2013 by John Wiley & Sons. All rights reserved.

Chapter Goals. Contents. 1.1 Computer Programs

An Introduction to Software Engineering. David Greenstein Monta Vista High School

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

C++ Spring Break Packet 11 The Java Programming Language

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Introduction Basic elements of Java

Transcription:

VS-1036

1. LANGUAGE FUNDAMENTALS The Java language's programming paradigm is implementation and improvement of Object Oriented Programming (OOP) concepts. The Java language has its own rules, syntax, structure and programming paradigms. Today Java had expanded it scope to almost every digital field either it s a mobile device, or a television, or a washing machine, etc. Today java is used to deliver highly interactive and secure Desktop Applications, Web Based Content, Mobile Applications and Games, and Enterprise Software s. Java helps a programmer or an organization to develop or deploy exciting services and applications. Since Java is derivative of C++ or C Language, most of its features and syntax are similar in Java except that Java doesn t have concept of pointers. Some of them are variable declaration before they are use and the way both languages declare a variable, use of block codes, structure of loops and conditional statements etc. 1.1 About Java Compiler and JVM Java compiler is way different then C or C++ compiler. The C or C++ compiler compiles the complete code into machine code, which is dependent on OS. Thus a compiled code of C or C++ in Windows environment can t run on Linux/Unix/Solaris. Unlike C or C++, Java provide cross platform portability. Thus a code written and compiled in Windows environment can be run on Linux/Unix/Solaris/Mac OS environment without any extra efforts. But how this is possible? The answer to this question is very simple; it s because of Java Compiler. The Java compiler compiles the source code file (.java) into a Bytecode file which has an extension of.class or.jar. This.class or.jar file, i.e. the Bytecode file, is independent of the OS and it can only be understand by JVM (i.e. Java Virtual Machine). This makes java code portable. The JVM is platform dependent. So the JVM provide an environment to run the.class or.jar file, i.e. the bytecode runs on JVM. Fig 1.1 How Java Source code converts to Machine CODE 1.2 Java Runtime Environment (JRE) Oracle s (earlier known by Sun Microsystems s) Java execution environment is known as Java Runtime Environment (JRE). The JVM and Java APIs are bundled together to form Java Runtime Environment (JRE). The JRE also has a JIT Compiler. Just In Time (JIT) Compiler converts the bytecode into machine code that can be understood by Operating System. With the help of JIT Compiler, the execution of code becomes faster. www.vskills.in Page 7

1.3 Garbage Collection in Java Fig 1.2 Internal view of JRE Unlike C or C++ memory allocation and de-allocation process, Java (specifically JVM) automatically performs the allocation of memory from the memory heap and keeps track on the resources and when an object is no longer in use, it de-allocates the memory. This provides a better way of memory management and cleans memory automatically. Thus the over head of programmer to clean up memory reduces in Java. Whenever an object is instantiated, it is allocated memory from memory heap and a daemon thread known as Garbage Collector runs in background to keep track in the object. Before removing any object from memory the garbage collection runs finalize() method of object, so that it can perform any clean up/security process (like closing the database connection). When there is no more space available in Java Heap Memory, and a new object is instantiated, it throws an exception named as OutOfMemoryError. There is no manual way to perform garbage collection in Java. Thus as a programmer you can not clean up the heap memory. Although there are functions line System.gc() or Runtime.gc(), but they don t guarantee cleanup of memory. 1.4 Getting Started with Java Now let s write our first java. Before starting, check your system for following. Check List Java SE Development Kit 6 (JDK6) or above: In this book, we are going to use JDK version 6. You can use the current version of JDK i.e. 7. If you don t have JDK installed in your system, you can download it from www.oracle.com Text Editor: A simple text editor will work for us. We are going to use Notepad, MS Windows default text editor. We are now ready to write our first program. 1.4.1 Program 1: Hello World 1. Open up notepad and write following code. class Demo{ www.vskills.in Page 8

public static void main(string args[]){ System.out.println("Hello World"); } } 2. Now save this file as Demo.java. It must be noted that, the name of file must be similar to the class name having main() method. 1.4.2 Setting up Environment Variables To compile a java code, we first need to set environment variables so that our command line doest not throw errors like javac is not recognized as internal or external command. The process to set environment variables for different OS is different. Here we are going to cover the major OS. 1.4.2.1 WINDOWS XP/7 OS: Right clicks on My Computer and click on Properties from popped up menu. In System Property dialog box, switch to Advance tab. At the end you will find Environment Variables button, click on it a dialog box will appear. Click the New button under user variables. Now in this dialog box fill variable NAME as PATH and variable VALUE as C:\Program Files\Java\jdk1.6.0_31\bin; or the location of bin folder of java if you have custom installation. Fig 1.3 Windows Variable Environment Setting Menu 1.4.2.2 MAC OS: Download the JDK from Apple s App Center. Mount the.dmg disk and install the package by double clicking.pkg file. Now open up the terminal from Applications -> Utility -> Terminal and type the following command export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home. You need to logout the session and start again to make the changes. 1.4.2.3 LINUX OS: In Linux, java is installed to /usr/java by default. If you had a custom installations then change to that directory. Now go to /etc/profile.d directory and create a file name as java.sh. Now write the following content into it. #!/bin/bash JAVA_HOME=/usr/java/j2se JAVA_FONTS=/usr/share/fonts/truetype ANT_HOME=/usr/share/ant PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH export PATH JAVA_HOME JAVA_FONTS ANT_HOME export CLASSPATH=. After setting environment variables, go to command line and type following command java version. If it lists your java version then you are ready to go, otherwise check environment variables again. www.vskills.in Page 9

Fig 1.4 Output in Command Line after setting environment 1.4.3 Compiling and Executing Program Step by step instructions to compile the Java program. Open Command prompt and change to the directory in which you have saved.java file, here we have Demo.java file. Now to compile the source code use command javac Demo.java. It will generate a.class file. To run the code now type java Demo. And you will see the output. The output of above code will be 1.4.4 Explanation of Hello World Program Fig 1.5 Output of Hello World Program Class Declaration: The first line of code is basic way to declare a class. The definition of class resides between the opening and closing curly braces, i.e. {}. class <name> { } Main Block: Every Java program or application executions starts with main() method. The signature of the main() method is : public static void main(string args[]) { } The main() method in java accepts the string arguments as an array here named as args[] from the command line. These arguments can be used as input to our program and can be simple text, a condition or can be a file name that we want to use in our program (we ll see later). In case of no main() method defined in Java program or application we see an error as following: Exception in thread "main" java.lang.noclassdeffounderror: Demo.java. The System.out.println() line will send the output to the print stream which is command prompt in case we care executing it from command prompt. www.vskills.in Page 10

1.5 Access Modifier in Java Certified Core Java Developer The access modifiers are used to define the privilege of variable, methods and classes in Java. The access modifiers help in improving the Security in Java language. Java has three type of access modifier. Private Protected Public No access modifiers, or default access modifier 1.5.1 Private Modifier Whenever a class, a variable or a method is defined as private, it can not be accessed by any other class except itself. This means a private variable, or a method can be accessed by only the class they are defined. No other classes or sub-classes, either in same package or different package can access the private class data. 1.5.2 Protected Modifier A class, variable or method defined as protected can be accessed by the class itself, or by the other classes in same package, and by the sub-classes. No classes from other packages can access the data of the protected class or the protected variable or method. 1.5.3 Public Modifier A public class, variable or a method can be accessed from anywhere in java world. The public classes, variable or methods can be accessed by any class, sub-class, or any package. 1.5.4 No Access Modifier The default access modifier is also known as no access modifier. When no access modifier is used, the class, variables or method can be accessed in the same package. But a sub-class or other packages cannot access to those variables or methods. Visibility Access Modifiers Same Class Same package Sub-Class Other package Public Y Y Y Y Protected Y Y Y N Private Y N N N No Modifier Y Y N N Table 1: Visibility of Access Modifiers www.vskills.in Page 11

Self Assessment Questions Q1. What is this platform-independent code of Java called? (ans c) A. Source Code B. Virtual Code C. ByteCODE D. Machine CODE Q2. What is correct signature of main() method? (ans a, d) A. static public void main(string args[]) B. void main() C. public void main(string args[]) D. public static void main(string args[]) Q3. Which parameter does the main() method accepts? (ans d) A. Integer B. Long C. Boolean D. String Q4. JRE is composed of? (ans b) A. JVM B. Both a and c C. Java API D. None of the above Q5. Which modifier must be used to access a class within the same package only? (ans b) A. Public B. No access modifier C. Protected D. Private www.vskills.in Page 12