Categories

Main
Database
Java
Microsoft.NET
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
ColdFusion
Crystal Reports
Delphi, C etc
JAVA
Microsoft.NET
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
XML & XSLT
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
Applications & Tools
Database Concepts & Design
EJB programming & troubleshooting
EJB design
General J2EE
XML & Web services
Web tier: servlets, JSP, Web frameworks
Performance and scalability
Industry news
TSS feedback
Mobicents Contributors
Mobicents Users
JSLEE Resource Adaptor Types
Planning JavaOne 2008
Sun Tech Days
Other Java conferences
Binary Web Services and XML
Metro and JAXB
GlassFish
GlassFish Plugins
Project jMaki
GlassFish WebTier
Mural
Java Development Tools
Java WS & XML Community News
JAXP
Java SE
6uN Early Access
Java Quick Starter
Java SE Snapshots: Project Feedback
JCK Forum
Feedback and Suggestions
JDK Distros
JDK Open Source
General JSR Discussion
JCP 2.6
JXTA Community Forum
ME Interest
ME Cool Apps
ME General Help
ME Feedback & Suggestions
ME Application Developer Interest
Blu-ray Disc Java
ME Developer Days
Squawk
Mobile Developer Alliance
OpenCable
LWUIT
JavaFX Script Language Discussion
OpenJFX General Discussion
Scene Graph
General Performance Discussion
Your Java Career
NetBeans 6.0
Servlets
JSP
JSF
Portals and Portlets
EJB and Other Java EE Technologies
Distributed Java
Object Relational Mapping
JDBC
Web Services
Swing / AWT / SWT / JFace
JNLP and Web Start
Java Micro Edition
Sockets and Internet Protocols
Threads and Synchronization
Performance
Applets
I/O and Streams
Other Java APIs
Game Development
Java in General (beginner)
Java in General (intermediate)
Java in General (advanced)
Programmer Certification (SCJP)
Developer Certification (SCJD)
Associate Certification (SCJA)
Web Component Certification (SCWCD)
EJB Certification (SCBCD)
Mobile Application Certification (SCMAD)
Architect Certification (SCEA)
Web Services Certification (SCDJWS)
XML Certification
Product and Other Certifications
Mock Exam Errata
Sun Certification Results
Authors' Corral
Book Reviews
Events
Bunkhouse Porch
Teachers' Lounge
Testing
OO, Patterns, UML and Refactoring
IDEs, Version Control and other tools
Ant, Maven and Other Build Tools
Linux / UNIX
Mac OS
HTML and JavaScript
XML and Related Technologies
Agile and Other Processes
General Computing
Security
Groovy
Scala
Other Languages
Struts
Application Frameworks
Other Open Source Projects
BEA/Weblogic
IBM/Websphere
Oracle/OAS
Apache/Tomcat
JBoss
Other Java Products and Servers
JavaRanch
Cattle Drive (java college)
Moderators Only
Trash Can
Jobs Offered
Jobs Wanted
Jobs Discussion
Meaningless Drivel
Programming Diversions
Blatant Advertising
Java Announcements
New To Java
Advanced Java
Java Applets
Networking
Threads and Synchronization
Java 2D
AWT / Swing
SWT / JFace
CLDC and MIDP
CDC and Personal Profile
Sun Java Wireless Toolkit
Enterprise JavaBeans
JavaServer Pages (JSP) and JSTL
Java Servlet
JavaServer Faces
Web Frameworks
Database
XML
Lucene
NetBeans
Eclipse
IntelliJ IDEA
JCreator
Other IDEs
Java Tutorials
Java Tips
Jobs Discussion
Jobs Offered
Jobs Wanted
Professional Certification
Forum Lobby
Java Blogs
Introductions
Reviews / Advertising
Suggestions & Feedback

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Java in General (intermediate)

Java in General (intermediate) Stuff that is past the beginners stage - but doesn't require a PHD in Java/Computer Science to talk about.

Initializer block problem ....'Illegal forward reference'


In initializer block ->{System.out.println("this.nsf1 : "+this.nsf1);nsf1=10;nsf1=sf1;//////////// int a=2*nsf1;int b=nsf1=20;System.out.println("this.nsf1 : "+this.nsf1);int c=this.nsf1;}int nsf1;static int sf1;this code works fine. Even though i have declared 'nsf1' later and used it before at 'nsf1=sf1;' & 'this.nsf1' . BUT THE PROBLEM ARISES WHEN I UNCOMMENT THE COMMENTED CODE -'int a=2*nsf1;' , IT GIVES AN COMPILE TIME ERROR 'Illegal forward reference int a=2*nsf1;'If i'm able to use/access the variable nsf1's value in this block then why does it gives this error of 'Illegal Forward Reference' .When i'm using it at the left hand, it works fine.why is it that when i use it at right hand here, it gives this error.... but again when i use it in line - 'int b=nsf1=20;' ... it works fine .. ??

   
   

 
   
      Paragraph 8.3.2.3 of the Java Language Specificationexplains this:"The declaration of a member needs to appear textually before it is usedonly if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:*The usage occursin an instance (respectively static) variable initializer of C orin an instance(respectively static)initializer of C."*The usage is not on the left hand side of an assignment."Move the declaration of the member variable nsf1 before the initializer:code:// Declaration of member variable BEFORE the initializer blockint nsf1;// Initializer block{// ...}[ October 14, 2006: Message edited by: Jesper Young ]--------------------Java Beginners FAQ - JavaRanch SCJP FAQThe Java Tutorial - Java SE 6.0 API documentation


Related Links

Java 1.5 spec
To HS: How attributes change design
Q 4 H.Schildt (4): how far can annotations go?
I don't see an advantage of Generics of Java 5 here!
Java 5 and backward compatibility
Reader question: Tiger's for loop
Java 2 v5.0 (Tiger) New Features by Herbert Schildt
Java Generics v1.5
WSAD question
Open Source Document Management
Book: Writing about a Beta API, Risky?
java.util.zip and a password-protected zip file
Has the Tiger been released?
how to write pseudocode ?? and examples ??
Herbert: Java 2 v5.0 vs. 1.5
Distributing apps as jar files