SlideShare a Scribd company logo
JAVA TUTORIAL
GENERAL
Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java
runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a
complete understanding of Java.
This lecture will take you through simple and practical approach while learning Java Programming language.
AUDIENCE
This lecture has been prepared for the beginners to help them understand the basic to advanced concepts
related to Java Programming language.
PREREQUISITIES
Before you start doing practice with various types of examples given in this reference, I'm making an
assumption that you are already aware about what is a computer program and what is a computer
programming language.
COMPILE/EXECUTE JAVA PROGRAMS
For most of the examples given in this tutorial you will find Try it option, so just make use of it and enjoy your
learning.
Try following example using Try it or Example option available at the top right corner of the below sample code
box:
public class MyFirstJavaProgram {
public static void main(String []args) {
System.out.println("Hello World");
}
}
RESOURCES
Java tutorials by Oracle:
http://www.oracle.com/technetwork/java/download-138590.html
Top free Java ebooks:
http://www.mkyong.com/featured/top-5-free-java-ebooks/
Java Examples:
http://www.java-examples.com/
JAVA – OVERVIEW
Java programming language was originally developed by Sun Microsystems which was initiated by James
Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).
As of December 2008, the latest release of the Java Standard Edition is 6 (J2SE). With the advancement of Java
and its widespread popularity, multiple configurations were built to suite various types of platforms. Ex: J2EE
for Enterprise Applications, J2ME for Mobile Applications.
Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME respectively. Java is
guaranteed to be Write Once, Run Anywhere.
Java is:
OBJECT ORIENTED
In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
PLATFORM INDEPENDENT
Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into
platform specific machine, rather into platform independent byte code. This byte code is distributed over the
web and interpreted by virtual Machine (JVM) on whichever platform it is being run.
SIMPLE
Java is designed to be easy to learn. If you understand the basic concept of OOP Java would be easy to master.
SECURE
With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are
based on public-key encryption.
ARCHITECTURAL-NEUTRAL
Java compiler generates an architecture-neutral object file format which makes the compiled code to be
executable on many processors, with the presence of Java runtime system.
PORTABLE
Being architectural-neutral and having no implementation dependent aspects of the specification makes Java
portable. Compiler in Java is written in ANSI C with a clean portability boundary which is a POSIX subset.
ROBUST
Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking
and runtime checking.
MULTITHREADED
With Java's multithreaded feature it is possible to write programs that can do many tasks simultaneously. This
design feature allows developers to construct smoothly running interactive applications.
INTERPRETED
Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The
development process is more rapid and analytical since the linking is an incremental and light weight process.
HIGH PERFORMANCE
With the use of Just-In-Time compilers, Java enables high performance.
DISTRIBUTED
Java is designed for the distributed environment of the internet.
DYNAMIC
Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment.
Java programs can carry extensive amount of run-time information that can be used to verify and resolve
accesses to objects on run-time.
HISTORY OF JAVA:
James Gosling initiated the Java language project in June 1991 for use in one of his many set-top box projects.
The language, initially called Oak after an oak tree that stood outside Gosling's office, also went by the name
Green and ended up later being renamed as Java, from a list of random words.
Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run Anywhere
(WORA), providing no-cost run-times on popular platforms.
On 13 November 2006, Sun released much of Java as free and open source software under the terms of the
GNU General Public License (GPL).
On 8 May 2007, Sun finished the process, making all of Java's core code free and open-source, aside from a
small portion of code to which Sun did not hold the copyright.
TOOLS YOU WILL NEED:
HARDWARE & SOFTWARE
For performing the examples discussed in this tutorial, you will need a Pentium 200-MHz computer with a
minimum of 64 MB of RAM (128 MB of RAM recommended).
Windows 95/98/2000/XP operating system.
DEVELOPMENT TOOLS – MINIMUM 
 Java JDK 5
 Microsoft Notepad or any other text editor
DEVELOPMENT TOOLS WE WILL USE
NETBEANS 7.4
For tutorials and for Excercises we will use NetBeans, version 7.4.
NetBeans is an advanced, full-featured programming environment. It supports not only JAVA, but also C, C++,
Assembler, Fortran, PHP and other programming languages.
LABORATORY ENVIRONMENT
In our laboratories like 404, you have JAVA environment preinstalled. Please, check your desktop, where you
find NetBeans icon.
REMOTE ACCESS
You also can yse remote access to JAVA envirnnment.
Run Start  Příslušenství (=Windows Accessories)  Připojení ke vzdálené ploše (=Remote Desktop Sytem)
and you will get login window. Please fill „RDS.FSID.CVUT.CZ“ and press „Pripojit“.
On the next window, select „Použít jiný účet“ (=select another account) and check „Zapamatovat pověření“ (=
remember login).
For login, write „AD“ followed by your login name and password, like in the following example:
Now, you should see standard desktop with NetBeans icon.
INSTALATION
Unfortunately, installation of NetBeans is not simple. It is quite a time-consumpting job.
If you are still willing to set up your environment for Java programming language, then this section guides you
on how to download and set up Java on your machine. Please follow the following steps to set up the
environment.
Java SE is freely available from this link. So you download a version based on your operating system.
Follow the instructions to download Java and run the .exe to install Java on your machine. Once you installed
Java on your machine, you would need to set environment variables to point to correct installation directories:
 Assuming you have installed Java in c:Program Filesjavajdk directory, right-click on 'My Computer'
and select 'Properties'.
 Click on the 'Environment variables' button under the 'Advanced' tab.
 Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the
path is currently set to 'C:WINDOWSSYSTEM32', then change your path to read
'C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin'.
Then load and run NetBeans installation profram from this link. Use „Java SE“ or „All“ version. Run instalation
.EXE file and follow instructions.
FIRST START OF NETBEANS
FIRST STEPS
When you first run NetBeans, you will see NetBeams introductory page like this:
Click File  New Project and select Java, Java Application:
REMARK
Do not try to select other options. These options are intended for advanced users only.
NEW JAVA APPLICATION
After clicking „Next“, new opens a window.
It is important to fill an unique and self-explanatory name for your new application.
Also, if necessary, you can change folders where uour project will be saved. Normally, it is in
C:UsersusernameDocumentsNetBeansProjects.
HELLO WORLD
PROGRAMMING ENVIRONMENT
Usually, in any programming langue, teachers show the first program on an example called „Hello World“. This
program does nothing more than it writes greeting on screen.
So, please, create an applicacion „Hello World“. After you create it, you can see your NetBeans screen divided
into three main parts:
1. In the first part, we can select our projects, files and libraries. For beginners, it is better not to change
anything in this part.
2. Second part is of much better use. Here we can check variables, their values, attributes of classes etc.
Now, you cannot understand it, but it will change soon.
3. The third part is of most importance for us. Into this part we will write our programs. Please make a
note that there exist some pre-defined texts. These texts form a standard skeleton of any java
program.
WRITE A PROGRAM
Please copy the following text
public class MyFirstJavaProgram {
public static void main(String []args) {
System.out.println("Hello World");
}
}
to the 3rd part of your NetBeans Screen, instead of line
// TODO code application logic here
You can use standard Ctrl+C and Ctrl+V shortcuts. Naturally, you cannot understand, what this text means.
However, you can write it properly „as is“ to test our java compiler and programming environment.
Your screen changes as follows:
You can see that in the left, red points with exclamation matks appiered. These red points mean that there is
an error in this line. (It is better to say that there is an error somewhere around this line, or exactly, that this is
the place where an error was detected).
In our code, we intentionally made some errors to show, what happened. After you delete all errorneous lines,
our code becomes clean:
RUN A PROGRAM
You can find a valid souce code here.
In the menu, you can either select greem arrow, or press Run  Run Project, or press F6. In either case, begins
a process of compiling and running of our program.
In the lower part of screen, new window appears. Green colour and „Build Successful“ show that compilation
was successful and our first program runs properly.
Just after line „run:“, i.e. before green „BUILD SUCCESSFUL“ you can see results of our program. As it was
expected, program wrote „Hello World“ to the output.
STEPPING A PROGRAM
NetBeans compiler helps us to find and remova all syntax errors efectively. But sometimes it happens that we
have in our program a semantic error, which is difficcult to find. In such case, it is useful to use breakpoints,
stepping and variable watching.
Let’s write a program similar to Hello World, but a bit more comlicated. The inner part of code will be as
follows:
public static void main(String[] args) {
System.out.println("Program begins");
int x = 123;
System.out.println("Value x=");
System.out.println(x);
x++;
System.out.println("Now, value x=");
System.out.println(x);
System.out.println("Program terminates");
}
As you can see, we have several lines like System.out.println( ); that, as we saw earlier, prints
something to the output. Also, we have a line int x = 123; This creates a variable whose name is x and
whose value is 123.
Now, let’s find what happens in line 21, where is command x++;
First of all, we will set a breakpoint to line 21. This means, that the program will run until it reaches line 21. Just
before executing line 21, it stops. We can set breakpoint by clicking on number 21 left to the program line, or
by right mouse Toggle Breakpoint, or by Ctrl+F8. In either case, a red square appears instead of line number:
Now, if we run the program (F6), it normally runs and terminates.
But if we instead use Debug  Debug Project (Ctrl+F5), it stops just on the beginning of line 21 (red oval). We
also can see that variable x has value 123 at this moment.
Now, we can continue running of program (F5), but this is of no use for debugging and troubleshooting. Much
better is to step the program, i.e. to go line-by-line. In debug menu we have several options:
 Step over – processes one line
 Step into – processes one line, but if this line is a procedure call, it steps on first line of the procedure
 Step out – runs until it leaves procedure
 Run to cursor – runs to cursor
In this situation, we use F8 = Step over. Program stops just before line 22. As you can see on debug window,
value of x changed to 124. In the other words, command x++; on line 21 increased value in x by 1.
From this point we can step again and again, or continue (F5) to finish the program. Resulting output follows:
REMARK
Though it is possible to use spaces in application names, it is better use names without spaces. As you can see
in „src“ directory of your NetBeans project, each space results in one deeper level of directory structure.

More Related Content

What's hot (15)

Java Programming
Java ProgrammingJava Programming
Java Programming
Prof. Dr. K. Adisesha
 
Java part1
Java part1Java part1
Java part1
Raghu nath
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
Vinit Vyas
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
Mikkel Flindt Heisterberg
 
Applet execution
Applet execution Applet execution
Applet execution
myrajendra
 
Applet
AppletApplet
Applet
optimisticharish
 
Jsp applet
Jsp appletJsp applet
Jsp applet
Sanoj Kumar
 
Netbeans gui tutorial
Netbeans gui tutorialNetbeans gui tutorial
Netbeans gui tutorial
stephan EL'wiin Shaarawy
 
Supplement J Eclipse
Supplement J EclipseSupplement J Eclipse
Supplement J Eclipse
nga
 
Netbeans IDE & Platform
Netbeans IDE & PlatformNetbeans IDE & Platform
Netbeans IDE & Platform
Aatul Palandurkar
 
Dr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin developmentDr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin development
Ulrich Krause
 
JAVA First Day
JAVA First DayJAVA First Day
JAVA First Day
Sher Singh Bardhan
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
Palak Sanghani
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
university of education,Lahore
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
poonguzhali1826
 

Similar to Java interview question (20)

JAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARIJAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARI
SivaSankari36
 
Programming in java ppt
Programming in java  pptProgramming in java  ppt
Programming in java ppt
MrsRLakshmiIT
 
JAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java developmentJAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java development
wannabekrishna0
 
Java
JavaJava
Java
Harry Potter
 
Java
JavaJava
Java
James Wong
 
Java
JavaJava
Java
Tony Nguyen
 
Java
JavaJava
Java
Fraboni Ec
 
Java
JavaJava
Java
Luis Goldster
 
Java
JavaJava
Java
Young Alista
 
Learn java in one day and learn it well 2016 jamie chan
Learn java in one day and learn it well 2016   jamie chanLearn java in one day and learn it well 2016   jamie chan
Learn java in one day and learn it well 2016 jamie chan
anand_study
 
what is java.pdf
what is java.pdfwhat is java.pdf
what is java.pdf
XanGwaps
 
JAVA CORE
JAVA COREJAVA CORE
JAVA CORE
Ankit Chauhan
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorial
jackschitze
 
Java - At a glance
Java - At a glanceJava - At a glance
Java - At a glance
Nitish Baranwal
 
Java Programming Tutorials Basic to Advanced 1
Java Programming Tutorials Basic to Advanced 1Java Programming Tutorials Basic to Advanced 1
Java Programming Tutorials Basic to Advanced 1
JALALUDHEENVK1
 
Java Programming : introduction
Java Programming : introductionJava Programming : introduction
Java Programming : introduction
Kongu Engineering College, Perundurai, Erode
 
Java technology is widely used currently. Let's start learning of java from b...
Java technology is widely used currently. Let's start learning of java from b...Java technology is widely used currently. Let's start learning of java from b...
Java technology is widely used currently. Let's start learning of java from b...
aliblackcat76
 
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptxVMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
michellebacayplacide
 
Java programming language basics
Java programming language basicsJava programming language basics
Java programming language basics
dharmendra kumar dhakar
 
Object Oriented Programming Part 1 of Unit 1
Object Oriented Programming Part 1 of Unit 1Object Oriented Programming Part 1 of Unit 1
Object Oriented Programming Part 1 of Unit 1
VigneshkumarPonnusam1
 
JAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARIJAVA BOOK BY SIVASANKARI
JAVA BOOK BY SIVASANKARI
SivaSankari36
 
Programming in java ppt
Programming in java  pptProgramming in java  ppt
Programming in java ppt
MrsRLakshmiIT
 
JAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java developmentJAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java development
wannabekrishna0
 
Learn java in one day and learn it well 2016 jamie chan
Learn java in one day and learn it well 2016   jamie chanLearn java in one day and learn it well 2016   jamie chan
Learn java in one day and learn it well 2016 jamie chan
anand_study
 
what is java.pdf
what is java.pdfwhat is java.pdf
what is java.pdf
XanGwaps
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorial
jackschitze
 
Java Programming Tutorials Basic to Advanced 1
Java Programming Tutorials Basic to Advanced 1Java Programming Tutorials Basic to Advanced 1
Java Programming Tutorials Basic to Advanced 1
JALALUDHEENVK1
 
Java technology is widely used currently. Let's start learning of java from b...
Java technology is widely used currently. Let's start learning of java from b...Java technology is widely used currently. Let's start learning of java from b...
Java technology is widely used currently. Let's start learning of java from b...
aliblackcat76
 
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptxVMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
VMC___JAVA-THIRD QUARTER-SHS TWELVE.pptx
michellebacayplacide
 
Object Oriented Programming Part 1 of Unit 1
Object Oriented Programming Part 1 of Unit 1Object Oriented Programming Part 1 of Unit 1
Object Oriented Programming Part 1 of Unit 1
VigneshkumarPonnusam1
 
Ad

Recently uploaded (20)

How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Ad

Java interview question

  • 1. JAVA TUTORIAL GENERAL Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding of Java. This lecture will take you through simple and practical approach while learning Java Programming language. AUDIENCE This lecture has been prepared for the beginners to help them understand the basic to advanced concepts related to Java Programming language. PREREQUISITIES Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program and what is a computer programming language. COMPILE/EXECUTE JAVA PROGRAMS For most of the examples given in this tutorial you will find Try it option, so just make use of it and enjoy your learning. Try following example using Try it or Example option available at the top right corner of the below sample code box: public class MyFirstJavaProgram { public static void main(String []args) { System.out.println("Hello World"); } } RESOURCES Java tutorials by Oracle: http://www.oracle.com/technetwork/java/download-138590.html Top free Java ebooks: http://www.mkyong.com/featured/top-5-free-java-ebooks/ Java Examples:
  • 2. http://www.java-examples.com/ JAVA – OVERVIEW Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]). As of December 2008, the latest release of the Java Standard Edition is 6 (J2SE). With the advancement of Java and its widespread popularity, multiple configurations were built to suite various types of platforms. Ex: J2EE for Enterprise Applications, J2ME for Mobile Applications. Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere. Java is: OBJECT ORIENTED In Java, everything is an Object. Java can be easily extended since it is based on the Object model. PLATFORM INDEPENDENT Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run. SIMPLE Java is designed to be easy to learn. If you understand the basic concept of OOP Java would be easy to master. SECURE With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption. ARCHITECTURAL-NEUTRAL Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence of Java runtime system. PORTABLE Being architectural-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary which is a POSIX subset. ROBUST Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking. MULTITHREADED With Java's multithreaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.
  • 3. INTERPRETED Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light weight process. HIGH PERFORMANCE With the use of Just-In-Time compilers, Java enables high performance. DISTRIBUTED Java is designed for the distributed environment of the internet. DYNAMIC Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time. HISTORY OF JAVA: James Gosling initiated the Java language project in June 1991 for use in one of his many set-top box projects. The language, initially called Oak after an oak tree that stood outside Gosling's office, also went by the name Green and ended up later being renamed as Java, from a list of random words. Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms. On 13 November 2006, Sun released much of Java as free and open source software under the terms of the GNU General Public License (GPL). On 8 May 2007, Sun finished the process, making all of Java's core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright. TOOLS YOU WILL NEED: HARDWARE & SOFTWARE For performing the examples discussed in this tutorial, you will need a Pentium 200-MHz computer with a minimum of 64 MB of RAM (128 MB of RAM recommended). Windows 95/98/2000/XP operating system. DEVELOPMENT TOOLS – MINIMUM   Java JDK 5  Microsoft Notepad or any other text editor DEVELOPMENT TOOLS WE WILL USE NETBEANS 7.4
  • 4. For tutorials and for Excercises we will use NetBeans, version 7.4. NetBeans is an advanced, full-featured programming environment. It supports not only JAVA, but also C, C++, Assembler, Fortran, PHP and other programming languages. LABORATORY ENVIRONMENT In our laboratories like 404, you have JAVA environment preinstalled. Please, check your desktop, where you find NetBeans icon. REMOTE ACCESS You also can yse remote access to JAVA envirnnment. Run Start  Příslušenství (=Windows Accessories)  Připojení ke vzdálené ploše (=Remote Desktop Sytem) and you will get login window. Please fill „RDS.FSID.CVUT.CZ“ and press „Pripojit“. On the next window, select „Použít jiný účet“ (=select another account) and check „Zapamatovat pověření“ (= remember login).
  • 5. For login, write „AD“ followed by your login name and password, like in the following example: Now, you should see standard desktop with NetBeans icon. INSTALATION Unfortunately, installation of NetBeans is not simple. It is quite a time-consumpting job. If you are still willing to set up your environment for Java programming language, then this section guides you on how to download and set up Java on your machine. Please follow the following steps to set up the environment. Java SE is freely available from this link. So you download a version based on your operating system. Follow the instructions to download Java and run the .exe to install Java on your machine. Once you installed Java on your machine, you would need to set environment variables to point to correct installation directories:  Assuming you have installed Java in c:Program Filesjavajdk directory, right-click on 'My Computer' and select 'Properties'.  Click on the 'Environment variables' button under the 'Advanced' tab.  Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:WINDOWSSYSTEM32', then change your path to read 'C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin'. Then load and run NetBeans installation profram from this link. Use „Java SE“ or „All“ version. Run instalation .EXE file and follow instructions. FIRST START OF NETBEANS
  • 6. FIRST STEPS When you first run NetBeans, you will see NetBeams introductory page like this: Click File  New Project and select Java, Java Application: REMARK
  • 7. Do not try to select other options. These options are intended for advanced users only. NEW JAVA APPLICATION After clicking „Next“, new opens a window. It is important to fill an unique and self-explanatory name for your new application. Also, if necessary, you can change folders where uour project will be saved. Normally, it is in C:UsersusernameDocumentsNetBeansProjects. HELLO WORLD PROGRAMMING ENVIRONMENT Usually, in any programming langue, teachers show the first program on an example called „Hello World“. This program does nothing more than it writes greeting on screen. So, please, create an applicacion „Hello World“. After you create it, you can see your NetBeans screen divided into three main parts: 1. In the first part, we can select our projects, files and libraries. For beginners, it is better not to change anything in this part. 2. Second part is of much better use. Here we can check variables, their values, attributes of classes etc. Now, you cannot understand it, but it will change soon. 3. The third part is of most importance for us. Into this part we will write our programs. Please make a note that there exist some pre-defined texts. These texts form a standard skeleton of any java program.
  • 8. WRITE A PROGRAM Please copy the following text public class MyFirstJavaProgram { public static void main(String []args) { System.out.println("Hello World"); } } to the 3rd part of your NetBeans Screen, instead of line // TODO code application logic here You can use standard Ctrl+C and Ctrl+V shortcuts. Naturally, you cannot understand, what this text means. However, you can write it properly „as is“ to test our java compiler and programming environment. Your screen changes as follows:
  • 9. You can see that in the left, red points with exclamation matks appiered. These red points mean that there is an error in this line. (It is better to say that there is an error somewhere around this line, or exactly, that this is the place where an error was detected). In our code, we intentionally made some errors to show, what happened. After you delete all errorneous lines, our code becomes clean: RUN A PROGRAM You can find a valid souce code here. In the menu, you can either select greem arrow, or press Run  Run Project, or press F6. In either case, begins a process of compiling and running of our program.
  • 10. In the lower part of screen, new window appears. Green colour and „Build Successful“ show that compilation was successful and our first program runs properly. Just after line „run:“, i.e. before green „BUILD SUCCESSFUL“ you can see results of our program. As it was expected, program wrote „Hello World“ to the output. STEPPING A PROGRAM NetBeans compiler helps us to find and remova all syntax errors efectively. But sometimes it happens that we have in our program a semantic error, which is difficcult to find. In such case, it is useful to use breakpoints, stepping and variable watching. Let’s write a program similar to Hello World, but a bit more comlicated. The inner part of code will be as follows:
  • 11. public static void main(String[] args) { System.out.println("Program begins"); int x = 123; System.out.println("Value x="); System.out.println(x); x++; System.out.println("Now, value x="); System.out.println(x); System.out.println("Program terminates"); } As you can see, we have several lines like System.out.println( ); that, as we saw earlier, prints something to the output. Also, we have a line int x = 123; This creates a variable whose name is x and whose value is 123. Now, let’s find what happens in line 21, where is command x++; First of all, we will set a breakpoint to line 21. This means, that the program will run until it reaches line 21. Just before executing line 21, it stops. We can set breakpoint by clicking on number 21 left to the program line, or by right mouse Toggle Breakpoint, or by Ctrl+F8. In either case, a red square appears instead of line number: Now, if we run the program (F6), it normally runs and terminates. But if we instead use Debug  Debug Project (Ctrl+F5), it stops just on the beginning of line 21 (red oval). We also can see that variable x has value 123 at this moment.
  • 12. Now, we can continue running of program (F5), but this is of no use for debugging and troubleshooting. Much better is to step the program, i.e. to go line-by-line. In debug menu we have several options:  Step over – processes one line  Step into – processes one line, but if this line is a procedure call, it steps on first line of the procedure  Step out – runs until it leaves procedure  Run to cursor – runs to cursor In this situation, we use F8 = Step over. Program stops just before line 22. As you can see on debug window, value of x changed to 124. In the other words, command x++; on line 21 increased value in x by 1. From this point we can step again and again, or continue (F5) to finish the program. Resulting output follows:
  • 13. REMARK Though it is possible to use spaces in application names, it is better use names without spaces. As you can see in „src“ directory of your NetBeans project, each space results in one deeper level of directory structure.